db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1408955 - in /db/torque/torque4/trunk/torque-runtime/src: main/java/org/apache/torque/criteria/Criterion.java test/java/org/apache/torque/criteria/CriterionTest.java
Date Tue, 13 Nov 2012 20:57:27 GMT
Author: tfischer
Date: Tue Nov 13 20:57:26 2012
New Revision: 1408955

URL: http://svn.apache.org/viewvc?rev=1408955&view=rev
Log:
TORQUE-243 Also use copies of Criterions in Criterion's copy constructor

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

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java?rev=1408955&r1=1408954&r2=1408955&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java
Tue Nov 13 20:57:26 2012
@@ -24,6 +24,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.commons.collections.ListUtils;
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.torque.Column;
@@ -195,7 +196,14 @@ public class Criterion implements Serial
         this.preparedStatementReplacements
                 = toCopy.preparedStatementReplacements;
         this.ignoreCase = toCopy.ignoreCase;
-        this.parts = toCopy.parts;
+        if (toCopy.parts != null)
+        {
+            this.parts = new ArrayList<Criterion>(toCopy.parts.size());
+            for (Criterion part : toCopy.parts)
+            {
+                this.parts.add(new Criterion(part));
+            }
+        }
         this.conjunction = toCopy.conjunction;
     }
 

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriterionTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriterionTest.java?rev=1408955&r1=1408954&r2=1408955&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriterionTest.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriterionTest.java
Tue Nov 13 20:57:26 2012
@@ -132,4 +132,67 @@ public class CriterionTest extends BaseT
         assertNotSame(criterion.getParts().get(1), oredCriterion);
         assertNotSame(criterion.getParts().get(2), oredCriterion);
     }
+
+    /**
+     * Tests that a criterion is copied when being added as top level criterion
+     * using where (also tests and).
+     * checks TORQUE-243.
+     */
+    public void testCopyConstructorSimpleCriterion()
+    {
+        Criterion criterion = new Criterion(stringColumnMap, "abc");
+        Criterion copied = new Criterion(criterion);
+        assertEquals(criterion.getLValue(), copied.getLValue());
+        assertEquals(criterion.getComparison(), copied.getComparison());
+        assertEquals(criterion.getRValue(), copied.getRValue());
+        assertNull(copied.getSql());
+        assertNull(copied.getPreparedStatementReplacements());
+        assertFalse(copied.isIgnoreCase());
+        assertNull(copied.getParts());
+        assertNull(copied.getConjunction());
+    }
+
+    /**
+     * Tests that a criterion is copied when being added as top level criterion
+     * using where (also tests and).
+     * checks TORQUE-243.
+     */
+    public void testCopyConstructorCompositeCriterion()
+    {
+        Criterion criterion = new Criterion(stringColumnMap, "abc");
+        criterion.or(new Criterion(stringColumnMap, "def"));
+        criterion.setIgnoreCase(true);
+        Criterion copied = new Criterion(criterion);
+        assertNull(criterion.getLValue());
+        assertNull(criterion.getComparison());
+        assertNull(criterion.getRValue());
+        assertNull(copied.getSql());
+        assertNull(copied.getPreparedStatementReplacements());
+        assertTrue(copied.isIgnoreCase());
+        assertEquals(criterion.getParts(), copied.getParts());
+        assertNotSame(criterion.getParts().get(0), copied.getParts().get(0));
+        assertNotSame(criterion.getParts().get(1), copied.getParts().get(1));
+        assertEquals(criterion.getConjunction(), copied.getConjunction());
+    }
+
+    /**
+     * Tests that a criterion is copied when being added as top level criterion
+     * using where (also tests and).
+     * checks TORQUE-243.
+     */
+    public void testCopyConstructorSqlCriterion()
+    {
+        Criterion criterion = new Criterion(null, null, null, "select 1", new Object[] {1});
+        Criterion copied = new Criterion(criterion);
+        assertNull(criterion.getLValue());
+        assertNull(criterion.getComparison());
+        assertNull(criterion.getRValue());
+        assertEquals(criterion.getSql(), copied.getSql());
+        assertEquals(
+                criterion.getPreparedStatementReplacements(),
+                copied.getPreparedStatementReplacements());
+        assertFalse(copied.isIgnoreCase());
+        assertNull(copied.getParts());
+        assertNull(copied.getConjunction());
+    }
 }



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