This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new fc8cc0c  Normalize extractor prefix to db path
fc8cc0c is described below

commit fc8cc0c7bc0896beb8efa275cb2e11bfb5e07523
Author: Nikita Timofeev <[email protected]>
AuthorDate: Mon Feb 25 13:02:17 2019 +0300

    Normalize extractor prefix to db path
---
 .../select/CustomColumnSetExtractor.java           | 37 +++++++++++++++-------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractor.java
 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractor.java
index ed2c06f..7a9675d 100644
--- 
a/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractor.java
+++ 
b/cayenne-server/src/main/java/org/apache/cayenne/access/translator/select/CustomColumnSetExtractor.java
@@ -26,7 +26,7 @@ import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.access.sqlbuilder.sqltree.Node;
 import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.parser.ASTPath;
+import org.apache.cayenne.exp.parser.ASTDbPath;
 import org.apache.cayenne.exp.property.BaseProperty;
 import org.apache.cayenne.map.JoinType;
 import org.apache.cayenne.map.ObjEntity;
@@ -108,26 +108,39 @@ class CustomColumnSetExtractor implements ColumnExtractor 
{
         }
     }
 
+    /**
+     * Extracts prefix for this extractor from property.
+     * This will be just a db path for this property, if any exists.
+     */
     private String calculatePrefix(String prefix, BaseProperty<?> property) {
-        Expression propertyExpression = property.getExpression();
-        int expressionType = propertyExpression.getType();
-
-        if(expressionType == Expression.FULL_OBJECT && 
propertyExpression.getOperandCount() > 0) {
-            Object op = propertyExpression.getOperand(0);
-            if(op instanceof ASTPath) {
-                prefix = ((ASTPath) op).getPath();
+        Expression exp = property.getExpression();
+        int expressionType = exp.getType();
+        if(expressionType == Expression.FULL_OBJECT && exp.getOperandCount() > 
0) {
+            Object op = exp.getOperand(0);
+            if(op instanceof Expression) {
+                exp = (Expression)op;
             }
-        } else if(expressionType == Expression.DB_PATH || expressionType == 
Expression.OBJ_PATH) {
-            prefix = ((ASTPath) propertyExpression).getPath();
+        }
+        return dbPathOrDefault(exp, prefix);
+    }
+
+    private String dbPathOrDefault(Expression pathExp, String defaultPrefix) {
+        // normalize to db path first
+        if(pathExp.getType() == Expression.OBJ_PATH) {
+            pathExp = 
context.getMetadata().getObjEntity().translateToDbPath(pathExp);
+        }
+
+        if(pathExp.getType() != Expression.DB_PATH) {
+            return defaultPrefix;
         }
 
-        return prefix;
+        return ((ASTDbPath)pathExp).getPath();
     }
 
     private void ensureJoin(String prefix) {
         // ensure all joins for given property
         if(!Util.isEmptyString(prefix)) {
-            PathTranslationResult result = 
context.getPathTranslator().translatePath(context.getMetadata().getObjEntity(), 
prefix);
+            PathTranslationResult result = 
context.getPathTranslator().translatePath(context.getMetadata().getDbEntity(), 
prefix);
             result.getDbRelationship().ifPresent(relationship
                     -> 
context.getTableTree().addJoinTable(result.getFinalPath(), relationship, 
JoinType.LEFT_OUTER));
         }

Reply via email to