cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r476335 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne: ObjectId.java exp/parser/SimpleNode.java
Date Fri, 17 Nov 2006 21:53:01 GMT
Author: aadamchik
Date: Fri Nov 17 13:53:01 2006
New Revision: 476335

URL: http://svn.apache.org/viewvc?view=rev&rev=476335
Log:
CAY-707 SelectQuery automatic cache key build mechanism produces wrong results when DO's are
used in qualifier
(fixed)

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectId.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectId.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectId.java?view=diff&rev=476335&r1=476334&r2=476335
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectId.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/ObjectId.java
Fri Nov 17 13:53:01 2006
@@ -20,10 +20,12 @@
 package org.apache.cayenne;
 
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.cayenne.util.IDUtil;
@@ -330,7 +332,8 @@
     }
 
     /**
-     * A standard toString method used for debugging.
+     * A standard toString method used for debugging. It is guaranteed to produce the same
+     * string if two ObjectIds are equal.
      */
     public String toString() {
 
@@ -349,12 +352,19 @@
                     singleValue);
         }
         else if (objectIdKeys != null) {
-            Iterator it = objectIdKeys.entrySet().iterator();
+
+            
+            // ensure consistent order of the keys, so that toString could be used as a
+            // unique key, just like id itself
+            
+            List keys = new ArrayList(objectIdKeys.entrySet());
+            Collections.sort(keys);
+            Iterator it = keys.iterator();
             while (it.hasNext()) {
-                Map.Entry entry = (Map.Entry) it.next();
+                Object key = it.next();
                 buffer.append(", ");
-                buffer.append(String.valueOf(entry.getKey())).append("=").append(
-                        entry.getValue());
+                buffer.append(String.valueOf(key)).append("=").append(
+                        objectIdKeys.get(key));
             }
         }
 

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java?view=diff&rev=476335&r1=476334&r2=476335
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/exp/parser/SimpleNode.java
Fri Nov 17 13:53:01 2006
@@ -19,25 +19,28 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.exp.parser;
 
 import java.io.PrintWriter;
 
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.Persistent;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionException;
 import org.apache.cayenne.util.Util;
 
 /**
- * Superclass of AST* expressions that implements Node interface defined
- * by JavaCC framework.
- * 
- * <p>Some parts of the parser are based on OGNL parser,
- * copyright (c) 2002, Drew Davidson and Luke Blanshard.</p>
+ * Superclass of AST* expressions that implements Node interface defined by JavaCC
+ * framework.
+ * <p>
+ * Some parts of the parser are based on OGNL parser, copyright (c) 2002, Drew Davidson
+ * and Luke Blanshard.
+ * </p>
  * 
  * @since 1.1
  */
 public abstract class SimpleNode extends Expression implements Node {
+
     protected Node parent;
     protected Node[] children;
     protected int id;
@@ -51,6 +54,16 @@
         if (quote) {
             pw.print('\"');
         }
+
+        // encode only ObjectId for Persistent, ensure that the order of keys is
+        // predictable....
+        if (scalar instanceof Persistent) {
+            ObjectId id = ((Persistent) scalar).getObjectId();
+            if(id != null) {
+                scalar = id;
+            }
+        }
+
         encodeAsEscapedString(pw, String.valueOf(scalar));
         if (quote) {
             pw.print('\"');
@@ -58,8 +71,8 @@
     }
 
     /**
-     * Utility method that prints a string to the provided PrintWriter,
-     * escaping special characters.
+     * Utility method that prints a string to the provided PrintWriter, escaping special
+     * characters.
      */
     protected static void encodeAsEscapedString(PrintWriter pw, String source) {
         int len = source.length();
@@ -67,31 +80,31 @@
             char c = source.charAt(i);
 
             switch (c) {
-                case '\n' :
+                case '\n':
                     pw.print("\\n");
                     continue;
-                case '\r' :
+                case '\r':
                     pw.print("\\r");
                     continue;
-                case '\t' :
+                case '\t':
                     pw.print("\\t");
                     continue;
-                case '\b' :
+                case '\b':
                     pw.print("\\b");
                     continue;
-                case '\f' :
+                case '\f':
                     pw.print("\\f");
                     continue;
-                case '\\' :
+                case '\\':
                     pw.print("\\\\");
                     continue;
-                case '\'' :
+                case '\'':
                     pw.print("\\'");
                     continue;
-                case '\"' :
+                case '\"':
                     pw.print("\\\"");
                     continue;
-                default :
+                default:
                     pw.print(c);
             }
         }
@@ -114,9 +127,9 @@
         return ExpressionParserTreeConstants.jjtNodeName[id];
     }
 
-    /** 
-     * Flattens the tree under this node by eliminating any children that are 
-     * of the same class as this node and copying their children to this node. 
+    /**
+     * Flattens the tree under this node by eliminating any children that are of the same
+     * class as this node and copying their children to this node.
      */
     protected void flattenTree() {
         boolean shouldFlatten = false;
@@ -187,9 +200,8 @@
     }
 
     protected Node wrapChild(Object child) {
-        return (child instanceof Node || child == null)
-            ? (Node) child
-            : new ASTScalar(child);
+        return (child instanceof Node || child == null) ? (Node) child : new ASTScalar(
+                child);
     }
 
     protected Object unwrapChild(Node child) {
@@ -256,7 +268,7 @@
     protected Object evaluateChild(int index, Object o) throws Exception {
         return ((SimpleNode) jjtGetChild(index)).evaluate(o);
     }
-    
+
     public Expression notExp() {
         return new ASTNot(this);
     }
@@ -269,9 +281,9 @@
         catch (Throwable th) {
             String string = this.toString();
             throw new ExpressionException(
-                "Error evaluating expression '" + string + "'",
-                string,
-                Util.unwindException(th));
+                    "Error evaluating expression '" + string + "'",
+                    string,
+                    Util.unwindException(th));
         }
     }
 }



Mime
View raw message