db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1411555 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java torque-test/src/test/java/org/apache/torque/generated/peer/SelectTest.java
Date Tue, 20 Nov 2012 06:00:35 GMT
Author: tfischer
Date: Tue Nov 20 06:00:34 2012
New Revision: 1411555

URL: http://svn.apache.org/viewvc?rev=1411555&view=rev
Log:
TORQUE-247 Fix Select using a SimpleKey

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectTest.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java?rev=1411555&r1=1411554&r2=1411555&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java
Tue Nov 20 06:00:34 2012
@@ -23,6 +23,7 @@ import org.apache.torque.TorqueException
 import org.apache.torque.adapter.Adapter;
 import org.apache.torque.criteria.PreparedStatementPart;
 import org.apache.torque.criteria.SqlEnum;
+import org.apache.torque.om.ObjectKey;
 import org.apache.torque.sql.WhereClauseExpression;
 
 /**
@@ -65,7 +66,8 @@ public class NullValueBuilder extends Ab
             return result;
         }
 
-        // now we know from isApplicable() that rValue is null
+        // now we know from isApplicable() that rValue is null or is
+        // an ObjectKey containing null
         if (whereClausePart.getOperator().equals(SqlEnum.EQUAL))
         {
             result = getObjectOrColumnPsPartBuilder().buildPs(
@@ -105,7 +107,10 @@ public class NullValueBuilder extends Ab
         {
             return true;
         }
-        if (whereClauseExpression.getRValue() != null)
+        Object rValue = whereClauseExpression.getRValue();
+        if (rValue != null
+                && (!(rValue instanceof ObjectKey)
+                        || ((ObjectKey) rValue).getValue() != null))
         {
             return false;
         }

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectTest.java?rev=1411555&r1=1411554&r2=1411555&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectTest.java
(original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SelectTest.java
Tue Nov 20 06:00:34 2012
@@ -26,6 +26,7 @@ import org.apache.torque.BaseDatabaseTes
 import org.apache.torque.TooManyRowsException;
 import org.apache.torque.Torque;
 import org.apache.torque.criteria.Criteria;
+import org.apache.torque.om.SimpleKey;
 import org.apache.torque.om.mapper.CompositeMapper;
 import org.apache.torque.test.dbobject.Author;
 import org.apache.torque.test.dbobject.Book;
@@ -347,4 +348,35 @@ public class SelectTest extends BaseData
         assertEquals(1, authors.size());
         assertEquals(null, authors.get(0));
     }
+
+    /**
+     * Tests a select for a SimpleKeyValue.
+     *
+     * @throws Exception if the test fails.
+     */
+    public void testSelectSimpleKey() throws Exception
+    {
+        Book bookToSelect = authorList.get(0).getBooks().get(0);
+        Criteria criteria = new Criteria()
+                .where(BookPeer.BOOK_ID, bookToSelect.getPrimaryKey());
+
+        List<Book> books = BookPeer.doSelect(criteria);
+        assertEquals(1, books.size());
+        assertEquals(bookToSelect.getBookId(), books.get(0).getBookId());
+    }
+
+    /**
+     * Tests a select for a SimpleKeyValue with a null value.
+     *
+     * @throws Exception if the test fails.
+     */
+    public void testSelectSimpleKeyNullValue() throws Exception
+    {
+        SimpleKey keyToSelect = SimpleKey.keyFor((Integer) null);
+        Criteria criteria = new Criteria()
+                .where(BookPeer.ISBN, keyToSelect);
+
+        List<Book> books = BookPeer.doSelect(criteria);
+        assertEquals(10, books.size());
+    }
 }



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