cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r928404 - in /cayenne/main/branches/STABLE-3.0: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/
Date Sun, 28 Mar 2010 14:20:41 GMT
Author: aadamchik
Date: Sun Mar 28 14:20:41 2010
New Revision: 928404

URL: http://svn.apache.org/viewvc?rev=928404&view=rev
Log:
CAY-1111 Expression.toEJBQL() support for single-column PK Persistent objects

Modified:
    cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTScalar.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionTest.java

Modified: cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=928404&r1=928403&r2=928404&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt Sun Mar
28 14:20:41 2010
@@ -14,6 +14,7 @@ Date: 
 
 Bug Fixes Since 3.0RC2:
 
+CAY-1111 Expression.toEJBQL() support for single-column PK Persistent objects
 CAY-1378 Error unsetting to-many DataObject property
 	(this also reverts CAY-1009)
 CAY-1379 Error resolving fault, no matching row exists in the database

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTScalar.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTScalar.java?rev=928404&r1=928403&r2=928404&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTScalar.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTScalar.java
Sun Mar 28 14:20:41 2010
@@ -21,6 +21,8 @@ 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;
 
 /**
@@ -29,6 +31,7 @@ import org.apache.cayenne.exp.Expression
  * @since 1.1
  */
 public class ASTScalar extends SimpleNode {
+
     protected Object value;
 
     /**
@@ -66,13 +69,27 @@ public class ASTScalar extends SimpleNod
     public void encodeAsString(PrintWriter pw) {
         SimpleNode.encodeScalarAsString(pw, value, '\"');
     }
-    
+
     /**
      * @since 3.0
      */
     @Override
     public void encodeAsEJBQL(PrintWriter pw, String rootId) {
-        SimpleNode.encodeScalarAsString(pw, value, '\'');
+
+        // TODO: see CAY-1111
+        // Persistent processing is a hack for a rather special case of a single column PK
+        // object.. full implementation pending...
+        Object scalar = value;
+        if (scalar instanceof Persistent) {
+
+            Persistent persistent = (Persistent) scalar;
+            ObjectId id = persistent.getObjectId();
+            if (!id.isTemporary() && id.getIdSnapshot().size() == 1) {
+                scalar = id.getIdSnapshot().values().iterator().next();
+            }
+        }
+
+        SimpleNode.encodeScalarAsString(pw, scalar, '\'');
     }
 
     public void setValue(Object value) {
@@ -85,7 +102,8 @@ public class ASTScalar extends SimpleNod
 
     @Override
     protected String getExpressionOperator(int index) {
-        throw new UnsupportedOperationException(
-            "No operator for '" + ExpressionParserTreeConstants.jjtNodeName[id] + "'");
+        throw new UnsupportedOperationException("No operator for '"
+                + ExpressionParserTreeConstants.jjtNodeName[id]
+                + "'");
     }
 }

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionTest.java?rev=928404&r1=928403&r2=928404&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionTest.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionTest.java
Sun Mar 28 14:20:41 2010
@@ -23,6 +23,9 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Collections;
 
+import org.apache.art.Artist;
+import org.apache.cayenne.ObjectId;
+
 import junit.framework.TestCase;
 
 /**
@@ -104,4 +107,22 @@ public class ExpressionTest extends Test
 
         assertEquals("x.artistName in ('a', 'b', 'c')", ejbql);
     }
+    
+    public void testEncodeAsEJBQL_PersistentParamater() {
+        
+        Artist a = new Artist();
+        ObjectId aId = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 1);
+        a.setObjectId(aId);
+
+        Expression e = ExpressionFactory.matchExp("artist", a);
+
+        StringWriter buffer = new StringWriter();
+        PrintWriter pw = new PrintWriter(buffer);
+        e.encodeAsEJBQL(pw, "x");
+        pw.close();
+        buffer.flush();
+        String ejbql = buffer.toString();
+
+        assertEquals("x.artist = 1", ejbql);
+    }
 }



Mime
View raw message