You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2019/10/23 08:29:12 UTC

[cayenne] branch master updated: CAY-2635 Lambda expressions break ROP serialization

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 3e57de7  CAY-2635 Lambda expressions break ROP serialization
3e57de7 is described below

commit 3e57de7da4548d0a4a31970162a6d6d73ce72de0
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Wed Oct 23 11:29:03 2019 +0300

    CAY-2635 Lambda expressions break ROP serialization
---
 RELEASE-NOTES.txt                                       |  1 +
 .../rop/protostuff/ProtostuffROPSerializationTest.java  | 13 +++++++++++++
 .../org/apache/cayenne/exp/property/BaseProperty.java   | 17 ++++++++++++++---
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 3c254e1..372090a 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -104,6 +104,7 @@ CAY-2628 dbimport: unable to add several relationships to existing entity
 CAY-2631 Can no longer use "byte[]" as root of scalar SQLSelect
 CAY-2632 Modeler: issue saving cgen path for maven project
 CAY-2633 Modeler: attribute sorting logic in cgen can corrupt model
+CAY-2635 Lambda expressions break ROP serialization
 
 ----------------------------------
 Release: 4.1.B1
diff --git a/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationTest.java b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationTest.java
index fb2441d..c64c8be 100644
--- a/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationTest.java
+++ b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.rop.protostuff;
 
+import org.apache.cayenne.query.ColumnSelect;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.rop.ROPSerializationService;
 import org.apache.cayenne.rop.protostuff.persistent.ClientMtTable1;
 import org.apache.cayenne.rop.protostuff.persistent.ClientMtTable2;
@@ -110,6 +112,17 @@ public class ProtostuffROPSerializationTest extends ProtostuffProperties {
         assertCorrectness(clientTable2);
     }
 
+    @Test
+    public void testColumnQuerySerialization() throws Exception {
+        ColumnSelect<String> select = ObjectSelect.columnQuery(ClientMtTable1.class, ClientMtTable1.GLOBAL_ATTRIBUTE);
+
+        byte[] data = serverService.serialize(select);
+        @SuppressWarnings("unchecked")
+        ColumnSelect<Integer> clone = (ColumnSelect<Integer>) serverService.deserialize(data, ColumnSelect.class);
+
+        assertEquals(ClientMtTable1.GLOBAL_ATTRIBUTE.getExpression(), clone.getColumns().iterator().next().getExpression());
+    }
+
     private void assertCorrectness(ClientMtTable2 table2) {
         ClientMtTable1 table1 = table2.getTable1();
         assertEquals(GLOBAL_ATTRIBUTE2, table2.getGlobalAttribute());
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/exp/property/BaseProperty.java b/cayenne-server/src/main/java/org/apache/cayenne/exp/property/BaseProperty.java
index 34141f8..af46649 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/exp/property/BaseProperty.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/exp/property/BaseProperty.java
@@ -68,13 +68,24 @@ public class BaseProperty<E> implements Property<E> {
      *
      * @see PropertyFactory#createBase(String, Expression, Class)
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({"unchecked", "Convert2Lambda", "Anonymous2MethodRef"})
     protected BaseProperty(String name, Expression expression, Class<? super E> type) {
         this.name = name;
+        // can't use lambda here, see CAY-2635
         if(expression == null) {
-            this.expressionSupplier = () -> ExpressionFactory.pathExp(name);
+            this.expressionSupplier = new Supplier<Expression>() {
+                @Override
+                public Expression get() {
+                    return ExpressionFactory.pathExp(name);
+                }
+            };
         } else {
-            this.expressionSupplier = expression::deepCopy;
+            this.expressionSupplier = new Supplier<Expression>() {
+                @Override
+                public Expression get() {
+                    return expression.deepCopy();
+                }
+            };
         }
         this.type = (Class<E>)type;
     }