cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r788664 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/exp/ExpressionFactory.java test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
Date Fri, 26 Jun 2009 11:46:20 GMT
Author: andrey
Date: Fri Jun 26 11:46:19 2009
New Revision: 788664

URL: http://svn.apache.org/viewvc?rev=788664&view=rev
Log:
CAY-1241 Add method to ExpressionFactory to match against the primary key of an object or
list of objects (renaming)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java?rev=788664&r1=788663&r2=788664&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
Fri Jun 26 11:46:19 2009
@@ -25,7 +25,6 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.exp.parser.ASTAdd;
 import org.apache.cayenne.exp.parser.ASTAnd;
@@ -683,39 +682,27 @@
      * <code>ObjectId</code>'s <code>IdSnapshot</code> for the argument
      * <code>object</code>.
      */
-    public static Expression matchObjectExp(Persistent object) {
-        ObjectId obid = object.getObjectId();
-        Map<String, ?> map = obid.getIdSnapshot();
-
-        List<Expression> pairs = new ArrayList<Expression>(map.size());
-
-        for (Map.Entry<String, ?> entry : map.entrySet()) {
-            Expression exp = expressionOfType(Expression.EQUAL_TO);
-            exp.setOperand(0, new ASTDbPath(entry.getKey()));
-            exp.setOperand(1, wrapPathOperand(entry.getValue()));
-            pairs.add(exp);
-        }
-
-        return joinExp(Expression.AND, pairs);
+    public static Expression matchExp(Persistent object) {
+        return matchAllDbExp(object.getObjectId().getIdSnapshot(), Expression.EQUAL_TO);
     }
 
     /**
      * Creates an expression that matches any of the objects contained in the list
      * <code>objects</code>
      */
-    public static Expression matchObjectsExp(List<? extends Persistent> objects) {
+    public static Expression matchAnyExp(List<? extends Persistent> objects) {
         if (objects == null || objects.size() == 0) {
             return expFalse();
         }
         
-        return matchObjectsExp(objects.toArray(new Persistent[objects.size()]));
+        return matchAnyExp(objects.toArray(new Persistent[objects.size()]));
     } 
     
     /**
      * Creates an expression that matches any of the objects contained in the
      * <code>objects</code> array
      */
-    public static Expression matchObjectsExp(Persistent... objects) {
+    public static Expression matchAnyExp(Persistent... objects) {
         if (objects == null || objects.length == 0) {
             return expFalse();
         }
@@ -723,7 +710,7 @@
         List<Expression> pairs = new ArrayList<Expression>(objects.length);
 
         for (Persistent object : objects) {
-            pairs.add(matchObjectExp(object));
+            pairs.add(matchExp(object));
         }
 
         return joinExp(Expression.OR, pairs);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java?rev=788664&r1=788663&r2=788664&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
Fri Jun 26 11:46:19 2009
@@ -262,12 +262,12 @@
         
         SelectQuery query = new SelectQuery(Artist.class);
         
-        query.setQualifier(ExpressionFactory.matchObjectExp(a2));
+        query.setQualifier(ExpressionFactory.matchExp(a2));
         Object res = DataObjectUtils.objectForQuery(dc, query);//exception if >1 result
         assertSame(res, a2);
         assertTrue(query.getQualifier().match(res));
         
-        query.setQualifier(ExpressionFactory.matchObjectsExp(a1, a3));
+        query.setQualifier(ExpressionFactory.matchAnyExp(a1, a3));
         query.addOrdering("artistName", true);
         List<Persistent> list = dc.performQuery(query);
         assertEquals(list.size(), 2);
@@ -277,6 +277,6 @@
         assertTrue(query.getQualifier().match(a3));
         
         assertEquals(query.getQualifier(), 
-                ExpressionFactory.matchObjectsExp(Arrays.asList(a1, a3)));
+                ExpressionFactory.matchAnyExp(Arrays.asList(a1, a3)));
     }
 }



Mime
View raw message