openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r627645 - in /openjpa/trunk/openjpa-slice/src: main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java test/java/org/apache/openjpa/slice/TestQuery.java
Date Thu, 14 Feb 2008 03:27:35 GMT
Author: ppoddar
Date: Wed Feb 13 19:27:26 2008
New Revision: 627645

URL: http://svn.apache.org/viewvc?rev=627645&view=rev
Log:
OPENJPA-551 Support Range Query

Modified:
    openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
    openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java

Modified: openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java?rev=627645&r1=627644&r2=627645&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
(original)
+++ openjpa/trunk/openjpa-slice/src/main/java/org/apache/openjpa/slice/jdbc/DistributedStoreQuery.java
Wed Feb 13 19:27:26 2008
@@ -34,6 +34,7 @@
 import org.apache.openjpa.kernel.StoreQuery;
 import org.apache.openjpa.kernel.exps.ExpressionParser;
 import org.apache.openjpa.lib.rop.MergedResultObjectProvider;
+import org.apache.openjpa.lib.rop.RangeResultObjectProvider;
 import org.apache.openjpa.lib.rop.ResultObjectProvider;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.util.StoreException;
@@ -135,16 +136,23 @@
         	boolean[] ascending = getAscending(q);
         	boolean isAscending = ascending.length > 0;
         	boolean isUnique    = q.getContext().isUnique();
+        	boolean hasRange    = q.getContext().getEndRange() != Long.MAX_VALUE;
+        	ResultObjectProvider result = null;
         	if (isUnique) {
-        	    return new UniqueResultObjectProvider(tmp, q, 
+        	    result = new UniqueResultObjectProvider(tmp, q, 
         	            getQueryExpressions());
-        	}
-        	if (isAscending) {
-        	    return new OrderingMergedResultObjectProvider(tmp, ascending, 
+        	} else if (isAscending) {
+        	    result = new OrderingMergedResultObjectProvider(tmp, ascending, 
                   (Executor[])executors.toArray(new Executor[executors.size()]),
                   q, params);
+        	} else {
+        	    result = new MergedResultObjectProvider(tmp);
         	}
-        	return new MergedResultObjectProvider(tmp);
+        	if (hasRange)
+        	    result = new RangeResultObjectProvider(result, 
+        	            q.getContext().getStartRange(), 
+        	            q.getContext().getEndRange());
+        	return result;
         }
         
         public Number executeDelete(StoreQuery q, Object[] params) {

Modified: openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java?rev=627645&r1=627644&r2=627645&view=diff
==============================================================================
--- openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java (original)
+++ openjpa/trunk/openjpa-slice/src/test/java/org/apache/openjpa/slice/TestQuery.java Wed
Feb 13 19:27:26 2008
@@ -31,7 +31,7 @@
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
         long id = System.currentTimeMillis();
-        for (int i=0;i<0;i++) {
+        for (int i=0;i<10;i++) {
             PObject pc = new PObject(id++);
             pc.setValue(i);
             em.persist(pc);
@@ -65,6 +65,24 @@
         for (Object r:result)
             System.err.println(r);
     }
+    
+    public void testSetMaxResult() {
+        EntityManager em = emf.createEntityManager();
+        int limit = 3;
+        em.getTransaction().begin();
+        List result = em.createQuery("SELECT p.value,p FROM PObject p ORDER BY p.value ASC")
+            .setMaxResults(limit).getResultList();
+        int i = 0;
+        for (Object row:result) {
+            Object[] line = (Object[])row;
+            int value = ((Integer)line[0]).intValue();
+            PObject pc = (PObject)line[1];
+            System.err.println(++i + "." + SlicePersistence.getSlice(pc) + ":" + pc.getId()
+ "," + pc.getValue());
+        }
+        em.getTransaction().rollback();
+        assertEquals(limit, result.size());
+    }
+    
     protected String getPersistenceUnitName() {
         return "ordering";
     }



Mime
View raw message