You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/11/01 04:40:05 UTC

svn commit: r469771 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/exp/ExpressionFactory.java test/java/org/apache/cayenne/exp/ExpressionFactoryTst.java

Author: aadamchik
Date: Tue Oct 31 19:40:04 2006
New Revision: 469771

URL: http://svn.apache.org/viewvc?view=rev&rev=469771
Log:
CAY-651: Add convenience method to create missing DB_PATH expressions where there is a corresponding OBJ_PATH expression
(added missing methods)

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTst.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java?view=diff&rev=469771&r1=469770&r2=469771
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java Tue Oct 31 19:40:04 2006
@@ -17,7 +17,6 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.exp;
 
 import java.util.ArrayList;
@@ -208,7 +207,7 @@
         Iterator it = map.entrySet().iterator();
         while (it.hasNext()) {
             Map.Entry entry = (Map.Entry) it.next();
-            
+
             Expression exp = expressionOfType(pairType);
             exp.setOperand(0, new ASTDbPath(entry.getKey()));
             exp.setOperand(1, wrapPathOperand(entry.getValue()));
@@ -282,20 +281,6 @@
     }
 
     /**
-     * A convenience shortcut for building IN DB expression.
-     */
-    public static Expression inDbExp(String pathSpec, Object[] values) {
-        return new ASTIn(new ASTDbPath(pathSpec), new ASTList(values));
-    }
-
-    /**
-     * A convenience shortcut for building IN DB expression.
-     */
-    public static Expression inDbExp(String pathSpec, Collection values) {
-        return new ASTIn(new ASTDbPath(pathSpec), new ASTList(values));
-    }
-
-    /**
      * A convenience method to create an OBJ_PATH "equal to" expression.
      */
     public static Expression matchExp(String pathSpec, Object value) {
@@ -315,6 +300,15 @@
     public static Expression lessExp(String pathSpec, Object value) {
         return new ASTLess(new ASTObjPath(pathSpec), value);
     }
+    
+    /**
+     * A convenience method to create an DB_PATH "less than" expression.
+     * 
+     * @since 3.0
+     */
+    public static Expression lessDbExp(String pathSpec, Object value) {
+        return new ASTLess(new ASTDbPath(pathSpec), value);
+    }
 
     /**
      * A convenience method to create an OBJ_PATH "less than or equal to" expression.
@@ -322,6 +316,15 @@
     public static Expression lessOrEqualExp(String pathSpec, Object value) {
         return new ASTLessOrEqual(new ASTObjPath(pathSpec), value);
     }
+    
+    /**
+     * A convenience method to create an DB_PATH "less than or equal to" expression.
+     * 
+     * @since 3.0
+     */
+    public static Expression lessOrEqualDbExp(String pathSpec, Object value) {
+        return new ASTLessOrEqual(new ASTDbPath(pathSpec), value);
+    }
 
     /**
      * A convenience method to create an OBJ_PATH "greater than" expression.
@@ -329,6 +332,15 @@
     public static Expression greaterExp(String pathSpec, Object value) {
         return new ASTGreater(new ASTObjPath(pathSpec), value);
     }
+    
+    /**
+     * A convenience method to create an DB_PATH "greater than" expression.
+     * 
+     * @since 3.0
+     */
+    public static Expression greaterDbExp(String pathSpec, Object value) {
+        return new ASTGreater(new ASTDbPath(pathSpec), value);
+    }
 
     /**
      * A convenience method to create an OBJ_PATH "greater than or equal to" expression.
@@ -336,6 +348,15 @@
     public static Expression greaterOrEqualExp(String pathSpec, Object value) {
         return new ASTGreaterOrEqual(new ASTObjPath(pathSpec), value);
     }
+    
+    /**
+     * A convenience method to create an DB_PATH "greater than or equal to" expression.
+     * 
+     * @since 3.0
+     */
+    public static Expression greaterOrEqualDbExp(String pathSpec, Object value) {
+        return new ASTGreaterOrEqual(new ASTDbPath(pathSpec), value);
+    }
 
     /**
      * A convenience shortcut for building IN expression.
@@ -345,6 +366,13 @@
     }
 
     /**
+     * A convenience shortcut for building IN DB expression.
+     */
+    public static Expression inDbExp(String pathSpec, Object[] values) {
+        return new ASTIn(new ASTDbPath(pathSpec), new ASTList(values));
+    }
+
+    /**
      * A convenience shortcut for building IN expression.
      */
     public static Expression inExp(String pathSpec, Collection values) {
@@ -352,11 +380,28 @@
     }
 
     /**
+     * A convenience shortcut for building IN DB expression.
+     */
+    public static Expression inDbExp(String pathSpec, Collection values) {
+        return new ASTIn(new ASTDbPath(pathSpec), new ASTList(values));
+    }
+
+    /**
      * A convenience shortcut for building NOT_IN expression.
      */
     public static Expression notInExp(String pathSpec, Collection values) {
         return new ASTNotIn(new ASTObjPath(pathSpec), new ASTList(values));
     }
+    
+    /**
+     * A convenience shortcut for building NOT_IN expression.
+     * 
+     * @since 3.0
+     */
+    public static Expression notInDbExp(String pathSpec, Collection values) {
+        return new ASTNotIn(new ASTDbPath(pathSpec), new ASTList(values));
+    }
+
 
     /**
      * A convenience shortcut for building NOT_IN expression.
@@ -366,6 +411,15 @@
     public static Expression notInExp(String pathSpec, Object[] values) {
         return new ASTNotIn(new ASTObjPath(pathSpec), new ASTList(values));
     }
+    
+    /**
+     * A convenience shortcut for building NOT_IN expression.
+     * 
+     * @since 3.0
+     */
+    public static Expression notInDbExp(String pathSpec, Object[] values) {
+        return new ASTNotIn(new ASTDbPath(pathSpec), new ASTList(values));
+    }
 
     /**
      * A convenience shortcut for building BETWEEN expressions.
@@ -373,6 +427,15 @@
     public static Expression betweenExp(String pathSpec, Object value1, Object value2) {
         return new ASTBetween(new ASTObjPath(pathSpec), value1, value2);
     }
+    
+    /**
+     * A convenience shortcut for building BETWEEN expressions.
+     * 
+     * @since 3.0
+     */
+    public static Expression betweenDbExp(String pathSpec, Object value1, Object value2) {
+        return new ASTBetween(new ASTDbPath(pathSpec), value1, value2);
+    }
 
     /**
      * A convenience shortcut for building NOT_BETWEEN expressions.
@@ -380,6 +443,15 @@
     public static Expression notBetweenExp(String pathSpec, Object value1, Object value2) {
         return new ASTNotBetween(new ASTObjPath(pathSpec), value1, value2);
     }
+    
+    /**
+     * A convenience shortcut for building NOT_BETWEEN expressions.
+     * 
+     * @since 3.0
+     */
+    public static Expression notBetweenDbExp(String pathSpec, Object value1, Object value2) {
+        return new ASTNotBetween(new ASTDbPath(pathSpec), value1, value2);
+    }
 
     /**
      * A convenience shortcut for building LIKE expression.
@@ -387,6 +459,15 @@
     public static Expression likeExp(String pathSpec, Object value) {
         return new ASTLike(new ASTObjPath(pathSpec), value);
     }
+    
+    /**
+     * A convenience shortcut for building LIKE DB_PATH expression.
+     * 
+     * @since 3.0
+     */
+    public static Expression likeDbExp(String pathSpec, Object value) {
+        return new ASTLike(new ASTDbPath(pathSpec), value);
+    }
 
     /**
      * A convenience shortcut for building NOT_LIKE expression.
@@ -394,6 +475,15 @@
     public static Expression notLikeExp(String pathSpec, Object value) {
         return new ASTNotLike(new ASTObjPath(pathSpec), value);
     }
+    
+    /**
+     * A convenience shortcut for building NOT_LIKE expression.
+     * 
+     * @since 3.0
+     */
+    public static Expression notLikeDbExp(String pathSpec, Object value) {
+        return new ASTNotLike(new ASTDbPath(pathSpec), value);
+    }
 
     /**
      * A convenience shortcut for building LIKE_IGNORE_CASE expression.
@@ -401,12 +491,30 @@
     public static Expression likeIgnoreCaseExp(String pathSpec, Object value) {
         return new ASTLikeIgnoreCase(new ASTObjPath(pathSpec), value);
     }
+    
+    /**
+     * A convenience shortcut for building LIKE_IGNORE_CASE expression.
+     * 
+     * @since 3.0
+     */
+    public static Expression likeIgnoreCaseDbExp(String pathSpec, Object value) {
+        return new ASTLikeIgnoreCase(new ASTDbPath(pathSpec), value);
+    }
 
     /**
      * A convenience shortcut for building NOT_LIKE_IGNORE_CASE expression.
      */
     public static Expression notLikeIgnoreCaseExp(String pathSpec, Object value) {
         return new ASTNotLikeIgnoreCase(new ASTObjPath(pathSpec), value);
+    }
+    
+    /**
+     * A convenience shortcut for building NOT_LIKE_IGNORE_CASE expression.
+     * 
+     * @since 3.0
+     */
+    public static Expression notLikeIgnoreCaseDbExp(String pathSpec, Object value) {
+        return new ASTNotLikeIgnoreCase(new ASTDbPath(pathSpec), value);
     }
 
     /**

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTst.java?view=diff&rev=469771&r1=469770&r2=469771
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTst.java (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTst.java Tue Oct 31 19:40:04 2006
@@ -22,9 +22,10 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.cayenne.unit.CayenneTestCase;
+import junit.framework.TestCase;
+
+public class ExpressionFactoryTst extends TestCase {
 
-public class ExpressionFactoryTst extends CayenneTestCase {
     // non-existent type
     private static final int badType = -50;
 
@@ -34,7 +35,7 @@
             fail();
         }
         catch (ExpressionException ex) {
-            // exception expected   
+            // exception expected
         }
     }
 
@@ -43,6 +44,19 @@
         Object v2 = new Object();
         Expression exp = ExpressionFactory.betweenExp("abc", v1, v2);
         assertEquals(Expression.BETWEEN, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.OBJ_PATH, path.getType());
+    }
+
+    public void testBetweenDbExp() throws Exception {
+        Object v1 = new Object();
+        Object v2 = new Object();
+        Expression exp = ExpressionFactory.betweenDbExp("abc", v1, v2);
+        assertEquals(Expression.BETWEEN, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.DB_PATH, path.getType());
     }
 
     public void testNotBetweenExp() throws Exception {
@@ -50,6 +64,19 @@
         Object v2 = new Object();
         Expression exp = ExpressionFactory.notBetweenExp("abc", v1, v2);
         assertEquals(Expression.NOT_BETWEEN, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.OBJ_PATH, path.getType());
+    }
+    
+    public void testNotBetweenDbExp() throws Exception {
+        Object v1 = new Object();
+        Object v2 = new Object();
+        Expression exp = ExpressionFactory.notBetweenDbExp("abc", v1, v2);
+        assertEquals(Expression.NOT_BETWEEN, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.DB_PATH, path.getType());
     }
 
     public void testGreaterExp() throws Exception {
@@ -58,26 +85,67 @@
         assertEquals(Expression.GREATER_THAN, exp.getType());
     }
 
+    public void testGreaterDbExp() throws Exception {
+        Object v = new Object();
+        Expression exp = ExpressionFactory.greaterDbExp("abc", v);
+        assertEquals(Expression.GREATER_THAN, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.DB_PATH, path.getType());
+    }
+
     public void testGreaterOrEqualExp() throws Exception {
         Object v = new Object();
         Expression exp = ExpressionFactory.greaterOrEqualExp("abc", v);
         assertEquals(Expression.GREATER_THAN_EQUAL_TO, exp.getType());
     }
 
+    public void testGreaterOrEqualDbExp() throws Exception {
+        Object v = new Object();
+        Expression exp = ExpressionFactory.greaterOrEqualDbExp("abc", v);
+        assertEquals(Expression.GREATER_THAN_EQUAL_TO, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.DB_PATH, path.getType());
+    }
+
     public void testLessExp() throws Exception {
         Object v = new Object();
         Expression exp = ExpressionFactory.lessExp("abc", v);
         assertEquals(Expression.LESS_THAN, exp.getType());
     }
 
+    public void testLessDbExp() throws Exception {
+        Object v = new Object();
+        Expression exp = ExpressionFactory.lessDbExp("abc", v);
+        assertEquals(Expression.LESS_THAN, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.DB_PATH, path.getType());
+    }
+
     public void testLessOrEqualExp() throws Exception {
         Object v = new Object();
         Expression exp = ExpressionFactory.lessOrEqualExp("abc", v);
         assertEquals(Expression.LESS_THAN_EQUAL_TO, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.OBJ_PATH, path.getType());
+    }
+
+    public void testLessOrEqualDbExp() throws Exception {
+        Object v = new Object();
+        Expression exp = ExpressionFactory.lessOrEqualDbExp("abc", v);
+        assertEquals(Expression.LESS_THAN_EQUAL_TO, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.DB_PATH, path.getType());
     }
 
     public void testInExp1() throws Exception {
-        Object[] v = new Object[] { "a", "b" };
+        Object[] v = new Object[] {
+                "a", "b"
+        };
         Expression exp = ExpressionFactory.inExp("abc", v);
         assertEquals(Expression.IN, exp.getType());
     }
@@ -92,12 +160,36 @@
         String v = "abc";
         Expression exp = ExpressionFactory.likeExp("abc", v);
         assertEquals(Expression.LIKE, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.OBJ_PATH, path.getType());
+    }
+
+    public void testLikeDbExp() throws Exception {
+        String v = "abc";
+        Expression exp = ExpressionFactory.likeDbExp("abc", v);
+        assertEquals(Expression.LIKE, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.DB_PATH, path.getType());
     }
 
     public void testLikeIgnoreCaseExp() throws Exception {
         String v = "abc";
         Expression exp = ExpressionFactory.likeIgnoreCaseExp("abc", v);
         assertEquals(Expression.LIKE_IGNORE_CASE, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.OBJ_PATH, path.getType());
+    }
+
+    public void testLikeIgnoreCaseDbExp() throws Exception {
+        String v = "abc";
+        Expression exp = ExpressionFactory.likeIgnoreCaseDbExp("abc", v);
+        assertEquals(Expression.LIKE_IGNORE_CASE, exp.getType());
+
+        Expression path = (Expression) exp.getOperand(0);
+        assertEquals(Expression.DB_PATH, path.getType());
     }
 
     public void testNotLikeIgnoreCaseExp() throws Exception {