[jboss-cvs] JBossAS SVN: r63030 - branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 14 06:59:01 EDT 2007
Author: alex.loubyansky at jboss.com
Date: 2007-05-14 06:59:01 -0400 (Mon, 14 May 2007)
New Revision: 63030
Modified:
branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/AbstractQueryCommand.java
branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DynamicQueryCommand.java
branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JBossQLQueryCommand.java
Log:
JBAS-4408
Modified: branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/AbstractQueryCommand.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/AbstractQueryCommand.java 2007-05-14 10:56:08 UTC (rev 63029)
+++ branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/AbstractQueryCommand.java 2007-05-14 10:59:01 UTC (rev 63030)
@@ -72,6 +72,10 @@
private CollectionFactory collectionFactory;
private CollectionStrategy collectionStrategy;
private ResultReader resultReader;
+ private int offsetParam;
+ private int offsetValue;
+ private int limitParam;
+ private int limitValue;
// Protected
@@ -125,7 +129,9 @@
public Collection fetchCollection(Schema schema, GenericEntityObjectFactory factory, Object[] args)
throws FinderException
{
- return fetchCollection(entity, sql, params, collectionStrategy, schema, factory, args, log);
+ int offset = toInt(args, offsetParam, offsetValue);
+ int limit = toInt(args, limitParam, limitValue);
+ return fetchCollection(entity, sql, params, offset, limit, collectionStrategy, schema, factory, args, log);
}
public Object fetchOne(Schema schema, GenericEntityObjectFactory factory, Object[] args) throws FinderException
@@ -134,8 +140,38 @@
return executeFetchOne(args, factory);
}
+ public void setOffsetValue(int offsetValue)
+ {
+ this.offsetValue = offsetValue;
+ }
+
+ public void setLimitValue(int limitValue)
+ {
+ this.limitValue = limitValue;
+ }
+
+ public void setOffsetParam(int offsetParam)
+ {
+ this.offsetParam = offsetParam;
+ }
+
+ public void setLimitParam(int limitParam)
+ {
+ this.limitParam = limitParam;
+ }
+
// Protected
+ protected static int toInt(Object[] params, int paramNumber, int defaultValue)
+ {
+ if(paramNumber == 0)
+ {
+ return defaultValue;
+ }
+ Integer arg = (Integer) params[paramNumber - 1];
+ return arg.intValue();
+ }
+
protected Object executeFetchOne(Object[] args, GenericEntityObjectFactory factory) throws FinderException
{
return fetchOne(entity, sql, params, resultReader, args, factory, log);
@@ -144,6 +180,8 @@
static Collection fetchCollection(JDBCEntityBridge2 entity,
String sql,
QueryParameter[] params,
+ int offset,
+ int limit,
CollectionStrategy collectionStrategy,
Schema schema,
GenericEntityObjectFactory factory,
@@ -153,6 +191,7 @@
{
schema.flush();
+ int count = offset;
Collection result;
Connection con = null;
@@ -198,6 +237,14 @@
}
rs = ps.executeQuery();
+
+ // skip 'offset' results
+ while(count > 0 && rs.next())
+ {
+ count--;
+ }
+
+ count = limit;
}
catch(Exception e)
{
@@ -211,7 +258,7 @@
throw fe;
}
- result = collectionStrategy.readResultSet(con, ps, rs, factory);
+ result = collectionStrategy.readResultSet(con, ps, rs, limit, count, factory);
return result;
}
@@ -393,7 +440,7 @@
interface CollectionStrategy
{
- Collection readResultSet(Connection con, PreparedStatement ps, ResultSet rs, GenericEntityObjectFactory factory)
+ Collection readResultSet(Connection con, PreparedStatement ps, ResultSet rs, int limit, int count, GenericEntityObjectFactory factory)
throws FinderException;
}
@@ -415,18 +462,19 @@
public Collection readResultSet(Connection con,
PreparedStatement ps,
ResultSet rs,
+ int limit, int count,
GenericEntityObjectFactory factory)
throws FinderException
{
Collection result;
try
{
- if(rs.next())
+ if((limit == 0 || count-- > 0) && rs.next())
{
result = collectionFactory.newCollection();
Object instance = resultReader.readRow(rs, factory);
result.add(instance);
- while(rs.next())
+ while((limit == 0 || count-- > 0) && rs.next())
{
instance = resultReader.readRow(rs, factory);
result.add(instance);
Modified: branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DynamicQueryCommand.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DynamicQueryCommand.java 2007-05-14 10:56:08 UTC (rev 63029)
+++ branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/DynamicQueryCommand.java 2007-05-14 10:59:01 UTC (rev 63030)
@@ -99,6 +99,11 @@
String sql = compiler.getSQL();
+ int offsetParam = compiler.getOffsetParam();
+ int offsetValue = compiler.getOffsetValue();
+ int limitParam = compiler.getLimitParam();
+ int limitValue = compiler.getLimitValue();
+
AbstractQueryCommand.ResultReader resultReader;
if(!compiler.isSelectEntity())
{
@@ -118,6 +123,7 @@
return AbstractQueryCommand.fetchCollection(
entity, sql, toArray(compiler.getInputParameters()),
+ AbstractQueryCommand.toInt(args, offsetParam, offsetValue), AbstractQueryCommand.toInt(args, limitParam, limitValue),
new AbstractQueryCommand.EagerCollectionStrategy(collectionFactory, resultReader, log),
schema, factory, (Object[])args[1], log);
}
Modified: branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JBossQLQueryCommand.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JBossQLQueryCommand.java 2007-05-14 10:56:08 UTC (rev 63029)
+++ branches/Branch_4_2/server/src/main/org/jboss/ejb/plugins/cmp/jdbc2/JBossQLQueryCommand.java 2007-05-14 10:59:01 UTC (rev 63030)
@@ -64,6 +64,10 @@
setParameters(compiler.getInputParameters());
setResultType(metadata.getMethod().getReturnType());
+ setOffsetParam(compiler.getOffsetParam());
+ setOffsetValue(compiler.getOffsetValue());
+ setLimitParam(compiler.getLimitParam());
+ setLimitValue(compiler.getLimitValue());
if(!compiler.isSelectEntity())
{
More information about the jboss-cvs-commits
mailing list