db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r374869 - in /db/torque: runtime/trunk/src/java/org/apache/torque/util/BasePeer.java runtime/trunk/src/java/org/apache/torque/util/LimitHelper.java test/trunk/test-project/src/java/org/apache/torque/DataTest.java
Date Sat, 04 Feb 2006 14:21:59 GMT
Author: tfischer
Date: Sat Feb  4 06:21:47 2006
New Revision: 374869

URL: http://svn.apache.org/viewcvs?rev=374869&view=rev
Log:
Changed behaviour for a limit of zero: (criteria.setLimit(0))
- If the db supports native limit, a limit of zero returns zero datasets.
- if the db does not support native limit, a limit of zero causes a TorqueException (thanks
to village :-()
Former behaviour was: A limit of zero returns all datasets.

Added a test case for the behaviour
Added a test case checking case insensitive order by

Modified:
    db/torque/runtime/trunk/src/java/org/apache/torque/util/BasePeer.java
    db/torque/runtime/trunk/src/java/org/apache/torque/util/LimitHelper.java
    db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java

Modified: db/torque/runtime/trunk/src/java/org/apache/torque/util/BasePeer.java
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/src/java/org/apache/torque/util/BasePeer.java?rev=374869&r1=374868&r2=374869&view=diff
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/util/BasePeer.java (original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/util/BasePeer.java Sat Feb  4 06:21:47
2006
@@ -998,7 +998,7 @@
         List results = null;
         try
         {
-            if (numberOfResults <= 0)
+            if (numberOfResults < 0)
             {
                 results = new ArrayList();
                 qds.fetchRecords();

Modified: db/torque/runtime/trunk/src/java/org/apache/torque/util/LimitHelper.java
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/src/java/org/apache/torque/util/LimitHelper.java?rev=374869&r1=374868&r2=374869&view=diff
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/util/LimitHelper.java (original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/util/LimitHelper.java Sat Feb  4 06:21:47
2006
@@ -48,7 +48,7 @@
 
         DB db = Torque.getDB(criteria.getDbName());
 
-        if (offset > 0 || limit > 0)
+        if (offset > 0 || limit >= 0)
         {
             // If we hit a database type, that is able to do native
             // limiting, we must set the criteria values to -1 and 0

Modified: db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java?rev=374869&r1=374868&r2=374869&view=diff
==============================================================================
--- db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java (original)
+++ db/torque/test/trunk/test-project/src/java/org/apache/torque/DataTest.java Sat Feb  4
06:21:47 2006
@@ -68,6 +68,7 @@
 import org.apache.torque.util.CountHelper;
 import org.apache.torque.util.Criteria;
 
+import com.workingdogs.village.DataSetException;
 import com.workingdogs.village.Record;
 
 /**
@@ -213,6 +214,23 @@
             assertTrue("Incorrect title: " + title,
                     titleMap.containsKey(title));
         }
+        crit.clear();
+        crit.setLimit(0);
+        try
+        {
+        	books = BookPeer.doSelect(crit);
+            assertTrue("List should have 0 books, not " + books.size(),
+            		books.size() == 0);
+        }
+        catch (TorqueException e)
+        {
+        	if (!Torque.getDB(Torque.getDefaultDB()).supportsNativeLimit())
+        	{
+                log.error("testLimitOffset(): "
+                		+ "A limit of 0 is not supported for Databases "
+        				+ "without native limit support");
+        	}
+        }
     }
 
     /**
@@ -907,6 +925,7 @@
     {
         cleanBookstore();
 
+        // check ignore case in selects
         Author author = new Author();
         author.setName("AuTHor");
         author.save();
@@ -915,10 +934,41 @@
         criteria.add(AuthorPeer.NAME, author.getName().toLowerCase());
         criteria.setIgnoreCase(true);
         List result = AuthorPeer.doSelect(criteria);
-        if (result.size() != 1)
-        {
-            fail("Size of result is not 1, but " + result.size());
-        }
+        assertTrue("Size of result is not 1, but " + result.size(), 
+        		result.size() == 1);
+        
+        // check ignore case in order by
+        cleanBookstore();
+        author = new Author();
+        author.setName("a");
+        author.save();
+        author = new Author();
+        author.setName("B");
+        author.save();
+        criteria.clear();
+        criteria.setIgnoreCase(true);
+        criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
+        result = AuthorPeer.doSelect(criteria);
+        assertTrue("Size of result is not 2, but " + result.size(), 
+        		result.size() == 2);
+        author = (Author) result.get(0);
+        assertEquals("First", author.getName(), "a");
+        
+        cleanBookstore();
+        author = new Author();
+        author.setName("A");
+        author.save();
+        author = new Author();
+        author.setName("b");
+        author.save();
+        criteria.clear();
+        criteria.setIgnoreCase(true);
+        criteria.addAscendingOrderByColumn(AuthorPeer.NAME);
+        result = AuthorPeer.doSelect(criteria);
+        assertTrue("Size of result is not 2, but " + result.size(), 
+        		result.size() == 2);
+        author = (Author) result.get(0);
+        assertEquals("First", author.getName(), "A");
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message