cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1292242 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: exp/parser/ASTDbPath.java exp/parser/ASTObjPath.java query/Ordering.java
Date Wed, 22 Feb 2012 11:24:19 GMT
Author: aadamchik
Date: Wed Feb 22 11:24:18 2012
New Revision: 1292242

URL: http://svn.apache.org/viewvc?rev=1292242&view=rev
Log:
CAY-1667 Expression parser performance optimization

manual parsing of ordering

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTDbPath.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTObjPath.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Ordering.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTDbPath.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTDbPath.java?rev=1292242&r1=1292241&r2=1292242&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTDbPath.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTDbPath.java
Wed Feb 22 11:24:18 2012
@@ -33,6 +33,8 @@ import org.apache.cayenne.map.Entity;
  * @since 1.1
  */
 public class ASTDbPath extends ASTPath {
+    
+    public static final String DB_PREFIX = "db:";
 
     ASTDbPath(int id) {
         super(id);
@@ -91,7 +93,7 @@ public class ASTDbPath extends ASTPath {
 
     @Override
     public void encodeAsString(PrintWriter pw) {
-        pw.print("db:");
+        pw.print(DB_PREFIX);
         pw.print(path);
     }
     
@@ -101,7 +103,7 @@ public class ASTDbPath extends ASTPath {
     @Override
     public void encodeAsEJBQL(PrintWriter pw, String rootId) {
         // warning: non-standard EJBQL...
-        pw.print("db:");
+        pw.print(DB_PREFIX);
         pw.print(rootId);
         pw.print('.');
         pw.print(path);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTObjPath.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTObjPath.java?rev=1292242&r1=1292241&r2=1292242&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTObjPath.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTObjPath.java
Wed Feb 22 11:24:18 2012
@@ -33,6 +33,8 @@ import org.apache.commons.logging.LogFac
 public class ASTObjPath extends ASTPath {
     private static final Log logObj = LogFactory.getLog(ASTObjPath.class);
 
+    public static final String OBJ_PREFIX = "obj:";
+    
     /**
      * Constructor used by expression parser. Do not invoke directly.
      */

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Ordering.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Ordering.java?rev=1292242&r1=1292241&r2=1292242&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Ordering.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/Ordering.java
Wed Feb 22 11:24:18 2012
@@ -28,6 +28,8 @@ import java.util.List;
 
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionException;
+import org.apache.cayenne.exp.parser.ASTDbPath;
+import org.apache.cayenne.exp.parser.ASTObjPath;
 import org.apache.cayenne.util.ConversionUtil;
 import org.apache.cayenne.util.Util;
 import org.apache.cayenne.util.XMLEncoder;
@@ -233,8 +235,22 @@ public class Ordering implements Compara
             return null;
         }
 
-        // compile on demand
+        // compile on demand .. since orderings can only be paths, avoid the overhead of
+        // Expression.fromString, and parse them manually
         if (sortSpec == null) {
+
+            if (sortSpecString.startsWith(ASTDbPath.DB_PREFIX)) {
+                sortSpec = new ASTDbPath(sortSpecString.substring(ASTDbPath.DB_PREFIX
+                        .length()));
+            }
+            else if (sortSpecString.startsWith(ASTObjPath.OBJ_PREFIX)) {
+                sortSpec = new ASTObjPath(sortSpecString.substring(ASTObjPath.OBJ_PREFIX
+                        .length()));
+            }
+            else {
+                sortSpec = new ASTObjPath(sortSpecString);
+            }
+
             sortSpec = Expression.fromString(sortSpecString);
         }
 



Mime
View raw message