db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1408442 - in /db/torque/torque4/trunk/torque-runtime/src: main/java/org/apache/torque/criteria/Criteria.java test/java/org/apache/torque/criteria/CriteriaTest.java
Date Mon, 12 Nov 2012 20:28:05 GMT
Author: tfischer
Date: Mon Nov 12 20:28:04 2012
New Revision: 1408442

URL: http://svn.apache.org/viewvc?rev=1408442&view=rev
Log:
TORQUE-243: copy Criterions passed into a Criteria

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java?rev=1408442&r1=1408441&r2=1408442&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java
Mon Nov 12 20:28:04 2012
@@ -987,11 +987,11 @@ public class Criteria
     {
         if (topLevelCriterion == null)
         {
-            topLevelCriterion = criterion;
+            topLevelCriterion = new Criterion(criterion);
         }
         else
         {
-            topLevelCriterion.and(criterion);
+            topLevelCriterion.and(new Criterion(criterion));
         }
         return this;
     }
@@ -1316,11 +1316,11 @@ public class Criteria
     {
         if (topLevelCriterion == null)
         {
-            topLevelCriterion = criterion;
+            topLevelCriterion = new Criterion(criterion);
         }
         else
         {
-            topLevelCriterion.or(criterion);
+            topLevelCriterion.or(new Criterion(criterion));
         }
         return this;
     }

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java?rev=1408442&r1=1408441&r2=1408442&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java
Mon Nov 12 20:28:04 2012
@@ -251,6 +251,96 @@ public class CriteriaTest extends BaseTe
     }
 
     /**
+     * Tests that a criterion is copied when being added as top level criterion
+     * using where (also tests and).
+     * checks TORQUE-243.
+     */
+    public void testCriteriaTopLevelCriterionGetsCopiedWhere()
+    {
+        Criterion criterion = new Criterion(stringColumnMap, "abc");
+        Criteria criteria = new Criteria().where(criterion);
+        assertNotSame(criterion, criteria.getTopLevelCriterion());
+    }
+
+    /**
+     * Tests that a criterion is copied when being added as top level criterion
+     * using where (also tests and).
+     * checks TORQUE-243.
+     */
+    public void testCriteriaTopLevelCriterionGetsCopiedOr()
+    {
+        Criterion criterion = new Criterion(stringColumnMap, "abc");
+        Criteria criteria = new Criteria().or(criterion);
+        assertNotSame(criterion, criteria.getTopLevelCriterion());
+    }
+
+    /**
+     * Tests that a criterion is copied when being added as top level criterion
+     * using where (also tests and).
+     * checks TORQUE-243.
+     */
+    public void testCriteriaCriterionGetsCopiedWhere()
+    {
+        Criteria criteria = new Criteria().where(stringColumnMap, "def");
+        Criterion criterion = new Criterion(stringColumnMap, "abc");
+        criteria.where(criterion);
+        assertNotSame(
+                criterion,
+                criteria.getTopLevelCriterion().getParts().get(0));
+        assertNotSame(
+                criterion,
+                criteria.getTopLevelCriterion().getParts().get(1));
+    }
+
+    /**
+     * Tests that a criterion is copied when being added as top level criterion
+     * using where (also tests and).
+     * checks TORQUE-243.
+     */
+    public void testCriteriaCriterionGetsCopiedOr()
+    {
+        Criteria criteria = new Criteria().where(stringColumnMap, "def");
+        Criterion criterion = new Criterion(stringColumnMap, "abc");
+        criteria.or(criterion);
+        assertNotSame(
+                criterion,
+                criteria.getTopLevelCriterion().getParts().get(0));
+        assertNotSame(
+                criterion,
+                criteria.getTopLevelCriterion().getParts().get(1));
+    }
+
+    /**
+     * Tests that a criterion does not get changed if it is added as
+     * root criterion to a criteria which is afterwards changed.
+     * checks TORQUE-243.
+     */
+    public void testCriterionDoesNotGetChangedByCriteriaOr()
+    {
+        Criterion criterion = new Criterion(stringColumnMap, "abc");
+        Criteria criteria = new Criteria().where(criterion);
+        criteria.or(stringColumnMap, "def");
+        assertFalse(criterion.isComposite());
+        assertEquals(stringColumnMap, criterion.getLValue());
+        assertEquals("abc", criterion.getRValue());
+    }
+
+    /**
+     * Tests that a criterion does not get changed if it is added as
+     * root criterion to a criteria which is afterwards changed.
+     * checks TORQUE-243.
+     */
+    public void testCriterionDoesNotGetChangedByCriteriaAnd()
+    {
+        Criterion criterion = new Criterion(stringColumnMap, "abc");
+        Criteria criteria = new Criteria().where(criterion);
+        criteria.and(stringColumnMap, "def");
+        assertFalse(criterion.isComposite());
+        assertEquals(stringColumnMap, criterion.getLValue());
+        assertEquals("abc", criterion.getRValue());
+    }
+
+    /**
      * Test that nesting Criterions works for equals comparison.
      */
     public void testNestedCriterionComparisonEqual() throws TorqueException



---------------------------------------------------------------------
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