[jboss-cvs] jboss-seam/src/main/org/jboss/seam/framework ...
Gavin King
gavin.king at jboss.com
Thu Oct 5 22:58:25 EDT 2006
User: gavin
Date: 06/10/05 22:58:25
Modified: src/main/org/jboss/seam/framework Query.java
Log:
support for last page navigation
Revision Changes Path
1.5 +52 -0 jboss-seam/src/main/org/jboss/seam/framework/Query.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Query.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/framework/Query.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- Query.java 5 Oct 2006 19:43:59 -0000 1.4
+++ Query.java 6 Oct 2006 02:58:24 -0000 1.5
@@ -52,6 +52,16 @@
return singleResult;
}
+ public Long getResultCount()
+ {
+ if (singleResult==null)
+ {
+ javax.persistence.Query query = createCountQuery();
+ singleResult = query==null ? null : query.getSingleResult();
+ }
+ return (Long) singleResult;
+ }
+
public DataModel getDataModel()
{
if (dataModel==null)
@@ -61,6 +71,31 @@
return dataModel;
}
+ private javax.persistence.Query createCountQuery()
+ {
+ prepareEjbql();
+
+ getEntityManager().joinTransaction();
+
+ int loc = ejbql.indexOf("from");
+ String countEjbql = "select count(*) " + ejbql.substring(loc);
+
+ javax.persistence.Query query = getEntityManager().createQuery(countEjbql);
+ for (int i=0; i<queryParameters.size(); i++)
+ {
+ Object parameterValue = queryParameters.get(i).getValue();
+ if (parameterValue==null)
+ {
+ return null;
+ }
+ else
+ {
+ query.setParameter( i, parameterValue );
+ }
+ }
+ return query;
+ }
+
private javax.persistence.Query createQuery()
{
prepareEjbql();
@@ -96,6 +131,12 @@
dataModel = null;
}
+ public void last()
+ {
+ firstResult = (int) getLastFirstResult();
+ dataModel = null;
+ }
+
public void next()
{
firstResult = getNextFirstResult();
@@ -108,6 +149,17 @@
dataModel = null;
}
+ public void first()
+ {
+ firstResult = 0;
+ dataModel = null;
+ }
+
+ public long getLastFirstResult()
+ {
+ return ( getResultCount() / maxResults ) * maxResults;
+ }
+
public int getNextFirstResult()
{
//TODO: check to see if there are more results
More information about the jboss-cvs-commits
mailing list