db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject svn commit: r382489 - in /db/ojb/branches/OJB_1_0_RELEASE/src: java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java test/org/apache/ojb/broker/QueryTest.java
Date Thu, 02 Mar 2006 20:00:00 GMT
Author: brj
Date: Thu Mar  2 11:59:58 2006
New Revision: 382489

URL: http://svn.apache.org/viewcvs?rev=382489&view=rev
Log:
if attribute is a column-name prefix it with the alias

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java?rev=382489&r1=382488&r2=382489&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
Thu Mar  2 11:59:58 2006
@@ -283,10 +283,10 @@
         TableAlias tableAlias = anAttrInfo.getTableAlias();
         String colName = anAttrInfo.getAttribute();
 
-        // no translation required, use attribute name
+        // no translation required, use alias.attribute
         if (!translate)
         {
-            buf.append(colName);
+            appendColumn(tableAlias, colName, buf);   
             return;
         }
 
@@ -302,7 +302,7 @@
 
         if (fld == null)
         {
-            buf.append(colName);
+            appendColumn(colName, buf);   
             return;
         }
 

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java?rev=382489&r1=382488&r2=382489&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/QueryTest.java Thu Mar
 2 11:59:58 2006
@@ -348,7 +348,6 @@
      */
     public void testSubQuery3()
     {
-
         ReportQueryByCriteria subQuery;
         Criteria subCrit = new Criteria();
         Criteria crit = new Criteria();
@@ -568,7 +567,6 @@
      */
     public void testInCriteria()
     {
-
         Criteria crit = new Criteria();
         Collection ids = new Vector();
         ids.add(new Integer(1));
@@ -2227,6 +2225,68 @@
         Mammal mammal = (Mammal) broker.getObjectByQuery(queryMammal);
         assertNotNull(reptile);
         assertNotNull(mammal);
+    }
+
+    /**
+     * test ColumnEqualTo Criteria
+     */
+    public void testColumnEqualCriteria()
+    {
+        Criteria crit = new Criteria();
+        crit.addColumnEqualTo("FIRSTNAME", "tom");
+        Query q = QueryFactory.newQuery(Person.class, crit);
+
+        Collection results = broker.getCollectionByQuery(q);
+        assertNotNull(results);
+        assertTrue(results.size() > 0);
+    }
+
+    /**
+     * test Column Null Criteria
+     */
+    public void testColumnNullCriteria()
+    {
+        String name = "testColumnNullCriteria_" + System.currentTimeMillis();
+        Person p = new Person();
+        p.setLastname(name);
+        broker.beginTransaction();
+        broker.store(p);
+        broker.commitTransaction();
+
+        Criteria crit = new Criteria();
+        crit.addColumnIsNull("FIRSTNAME");
+        Criteria crit2 = new Criteria();
+        crit2.addLike("lastname", name);
+        crit.addAndCriteria(crit2);
+        
+        Query q = QueryFactory.newQuery(Person.class, crit);
+
+        Collection results = broker.getCollectionByQuery(q);
+        assertNotNull(results);
+        assertEquals(1, results.size());
+    }
+
+    /**
+     * test Column In Criteria
+     */
+    public void testColumnInCriteria()
+    {
+        Criteria crit = new Criteria();
+        Collection ids = new Vector();
+        ids.add(new Integer(1));
+        ids.add(new Integer(3));
+        ids.add(new Integer(5));
+
+        crit.addColumnIn("ID", ids);
+        Query q = QueryFactory.newQuery(Person.class, crit);
+
+        Collection results = broker.getCollectionByQuery(q);
+        assertNotNull(results);
+        assertTrue(results.size() == 3);
+
+        // compare with count
+        int count = broker.getCount(q);
+        assertEquals(results.size(), count);
     }
 
 }



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


Mime
View raw message