cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] branch STABLE-4.1 updated: CAY-2565 Can't use new generated PK properties with dot() operator
Date Tue, 06 Aug 2019 12:09:56 GMT
This is an automated email from the ASF dual-hosted git repository.

abulatski pushed a commit to branch STABLE-4.1
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/STABLE-4.1 by this push:
     new dc0b650  CAY-2565 Can't use new generated PK properties with dot() operator
dc0b650 is described below

commit dc0b6507bb9a29d7f5d0939d1806b404f28d1929
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Tue Aug 6 15:05:33 2019 +0300

    CAY-2565 Can't use new generated PK properties with dot() operator
---
 RELEASE-NOTES.txt                                  |  1 +
 .../main/java/org/apache/cayenne/exp/Property.java | 19 ++++++-------------
 .../java/org/apache/cayenne/exp/PropertyTest.java  | 22 ++++++++++++++++------
 3 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 92f7dad..b483e72 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -20,6 +20,7 @@ Bug Fixes:
 
 CAY-2417 Modeler: wrong title in attribute context menu
 CAY-2553 Wrong disjoint prefetch query qualifier
+CAY-2565 Can't use new generated PK properties with dot() operator
 CAY-2573 DI field injection is triggered when creating sql Driver
 CAY-2580 Cgen: Can't use custom templates for client mode
 CAY-2582 Double insert of manyToMany relationship mapped to Set
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java b/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java
index 449934c..10c7e66 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/exp/Property.java
@@ -94,12 +94,7 @@ public class Property<E> {
      */
     protected Property(final String name, final Class<? super E> type) {
         this.name = name;
-        expressionProvider = new ExpressionProvider() {
-            @Override
-            public Expression get() {
-                return ExpressionFactory.pathExp(name);
-            }
-        };
+        expressionProvider = () -> ExpressionFactory.pathExp(name);
         this.type = type;
     }
 
@@ -114,12 +109,7 @@ public class Property<E> {
      */
     protected Property(final String name, final Expression expression, final Class<? super
E> type) {
         this.name = name;
-        expressionProvider = new ExpressionProvider() {
-            @Override
-            public Expression get() {
-                return expression.deepCopy();
-            }
-        };
+        expressionProvider = () -> expression.deepCopy();
         this.type = type;
     }
 
@@ -200,6 +190,9 @@ public class Property<E> {
      * @return a newly created Property object.
      */
     public <T> Property<T> dot(Property<T> property) {
+        if(property.getExpression().getType() != getExpression().getType()) {
+            throw new CayenneRuntimeException("Can't process path with not the same segment's
types.");
+        }
         return create(getName() + "." + property.getName(), property.getType());
     }
 
@@ -643,7 +636,7 @@ public class Property<E> {
     public Property<Long> count() {
         return create(FunctionExpressionFactory.countExp(getExpression()), Long.class);
     }
-    
+
     /**
      * @see FunctionExpressionFactory#countDistinctExp(Expression)
      * @since 4.1
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/PropertyTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/PropertyTest.java
index 3630384..c8eeffa 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/PropertyTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/PropertyTest.java
@@ -18,14 +18,10 @@
  ****************************************************************/
 package org.apache.cayenne.exp;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.exp.parser.ASTAbs;
 import org.apache.cayenne.exp.parser.ASTAvg;
 import org.apache.cayenne.exp.parser.ASTConcat;
@@ -48,6 +44,11 @@ import org.apache.cayenne.exp.parser.PatternMatchNode;
 import org.apache.cayenne.reflect.TstJavaBean;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
 public class PropertyTest {
 
     @Test
@@ -348,7 +349,7 @@ public class PropertyTest {
         assertTrue(newProp.getExpression() instanceof ASTCount);
         assertEquals(p.getExpression(), newProp.getExpression().getOperand(0));
     }
-    
+
     @Test
     public void testCountDistinct() {
         Property<String> p = Property.create("test", String.class);
@@ -489,4 +490,13 @@ public class PropertyTest {
         assertEquals(3, newProp.getExpression().getOperand(2)); // getOperand unwrapping
ASTScalar
         assertEquals(p2.getExpression(), newProp.getExpression().getOperand(3));
     }
+
+    @Test(expected = CayenneRuntimeException.class)
+    public void testMixDbAndObjPath() {
+        Property<Integer> dbPathProperty = Property
+                .create(ExpressionFactory.dbPathExp("db_path"), Integer.class);
+        Property<String> objPathProperty = Property
+                .create(ExpressionFactory.pathExp("obj_path"), String.class);
+        objPathProperty.dot(dbPathProperty);
+    }
 }


Mime
View raw message