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-2506 Java class generated for Embeddable object is not serializable
Date Mon, 29 Apr 2019 12:00:49 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 974ddcc  CAY-2506 Java class generated for Embeddable object is not serializable
974ddcc is described below

commit 974ddcc9ce9d71193b4222c112d732777b512578
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Mon Apr 29 14:59:31 2019 +0300

    CAY-2506 Java class generated for Embeddable object is not serializable
---
 RELEASE-NOTES.txt                                  |   1 +
 .../cayenne/tools/CayenneGeneratorTaskTest.java    |  14 +--
 .../templates/v4_1/embeddable-singleclass.vm       |   3 +-
 .../templates/v4_1/embeddable-superclass.vm        |   3 +-
 .../cayenne/access/EmbeddingSerializeIT.java       | 131 +++++++++++++++++++++
 .../testdo/embeddable/auto/_Embeddable1.java       |  24 ++--
 .../tools/CayenneGeneratorIntegrationTest.java     |   6 +-
 7 files changed, 159 insertions(+), 23 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 37c7f91..20f4d61 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -18,6 +18,7 @@ CAY-2570 Use MySQL adapter for latest versions of MariaDB
 
 Bug Fixes:
 
+CAY-2506 Java class generated for Embeddable object is not serializable
 CAY-2550 Modeler: ObjAttribute inspector modifies wrong columns in attribute table
 CAY-2559 Modeler: Warning dialog shows wrong information after changing target entity in
dbRelationship
 CAY-2561 Modeler: cgen type combobox doesn't set templates
diff --git a/cayenne-ant/src/test/java/org/apache/cayenne/tools/CayenneGeneratorTaskTest.java
b/cayenne-ant/src/test/java/org/apache/cayenne/tools/CayenneGeneratorTaskTest.java
index 1879cfd..53efb50 100644
--- a/cayenne-ant/src/test/java/org/apache/cayenne/tools/CayenneGeneratorTaskTest.java
+++ b/cayenne-ant/src/test/java/org/apache/cayenne/tools/CayenneGeneratorTaskTest.java
@@ -19,6 +19,12 @@
 
 package org.apache.cayenne.tools;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.util.regex.Pattern;
+
 import org.apache.cayenne.test.file.FileUtil;
 import org.apache.cayenne.test.resource.ResourceUtil;
 import org.apache.tools.ant.Location;
@@ -26,12 +32,6 @@ import org.apache.tools.ant.Project;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
-import java.util.regex.Pattern;
-
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -270,7 +270,7 @@ public class CayenneGeneratorTaskTest {
 
 		File _e = new File(mapDir, convertPath("org/apache/cayenne/testdo/embeddable/auto/_Embeddable1.java"));
 		assertTrue(_e.exists());
-		assertContents(_e, "_Embeddable1", "org.apache.cayenne.testdo.embeddable.auto", "Object");
+		assertContents(_e, "_Embeddable1", "org.apache.cayenne.testdo.embeddable.auto", "Serializable");
 	}
 
 	private String convertPath(String unixPath) {
diff --git a/cayenne-cgen/src/main/resources/templates/v4_1/embeddable-singleclass.vm b/cayenne-cgen/src/main/resources/templates/v4_1/embeddable-singleclass.vm
index a30dcec..c505fff 100644
--- a/cayenne-cgen/src/main/resources/templates/v4_1/embeddable-singleclass.vm
+++ b/cayenne-cgen/src/main/resources/templates/v4_1/embeddable-singleclass.vm
@@ -35,6 +35,7 @@
 ##
 ##
 ${importUtils.setPackage($subPackageName)}##
+${importUtils.addType("java.io.Serializable")}##
 ${importUtils.addReservedType("${subPackageName}.${subClassName}")}##
 ${importUtils.addType("${basePackageName}.${baseClassName}")}##
 ${importUtils.addType("org.apache.cayenne.Persistent")}##
@@ -46,7 +47,7 @@ $importUtils.addType(${attr.Type})##
 #end
 ${importUtils.generate()}
 
-public abstract class ${subClassName} extends ${baseClassName} {
+public abstract class ${subClassName} implements Serializable {
 
 ## Create property names
 #if( $createPropertyNames )
diff --git a/cayenne-cgen/src/main/resources/templates/v4_1/embeddable-superclass.vm b/cayenne-cgen/src/main/resources/templates/v4_1/embeddable-superclass.vm
index 95e39dc..225b9c0 100644
--- a/cayenne-cgen/src/main/resources/templates/v4_1/embeddable-superclass.vm
+++ b/cayenne-cgen/src/main/resources/templates/v4_1/embeddable-superclass.vm
@@ -35,6 +35,7 @@
 ##
 ##
 ${importUtils.setPackage($superPackageName)}##
+${importUtils.addType("java.io.Serializable")}##
 ${importUtils.addReservedType("${superPackageName}.${superClassName}")}##
 ${importUtils.addType("${basePackageName}.${baseClassName}")}##
 ${importUtils.addType("org.apache.cayenne.Persistent")}##
@@ -52,7 +53,7 @@ ${importUtils.generate()}
  * since it may be overwritten next time code is regenerated. 
  * If you need to make any customizations, please use subclass. 
  */
-public abstract class ${superClassName} extends ${baseClassName} {
+public abstract class ${superClassName} implements Serializable {
 
 ## Create property names
 #if( $createPropertyNames )
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingSerializeIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingSerializeIT.java
new file mode 100644
index 0000000..222f8ea
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/EmbeddingSerializeIT.java
@@ -0,0 +1,131 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.access;
+
+import java.util.List;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.ObjectSelect;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.testdo.embeddable.EmbedEntity1;
+import org.apache.cayenne.testdo.embeddable.Embeddable1;
+import org.apache.cayenne.unit.di.server.CayenneProjects;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.apache.cayenne.util.Util;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@UseServerRuntime(CayenneProjects.EMBEDDABLE_PROJECT)
+public class EmbeddingSerializeIT extends ServerCase {
+
+    @Inject
+    protected ObjectContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    protected TableHelper tEmbedEntity1;
+
+    @Before
+    public void setUp() throws Exception {
+        tEmbedEntity1 = new TableHelper(dbHelper, "EMBED_ENTITY1");
+        tEmbedEntity1.setColumns("ID", "NAME", "EMBEDDED10", "EMBEDDED20", "EMBEDDED30",
"EMBEDDED40");
+    }
+
+    protected void createSelectDataSet() throws Exception {
+        tEmbedEntity1.delete().execute();
+        tEmbedEntity1.insert(1, "n1", "e1", "e2", "e3", "e4");
+    }
+
+    @Test
+    public void testSerializationEntityWithEmbeddableCommited() throws Exception {
+        createSelectDataSet();
+
+        ObjectSelect<EmbedEntity1> query = ObjectSelect.query(EmbedEntity1.class);
+        List<EmbedEntity1> results = query.select(context);
+        assertEquals(1, results.size());
+
+        EmbedEntity1 o1 = results.get(0);
+        assertNotNull(o1);
+
+        EmbedEntity1 o2 = Util.cloneViaSerialization(o1);
+        assertNotNull(o2);
+
+        assertEquals(o1.getPersistenceState(), PersistenceState.COMMITTED);
+        assertEquals(o2.getPersistenceState(), PersistenceState.HOLLOW);
+
+        assertEquals("e1", o1.getEmbedded1().getEmbedded10());
+        assertEquals("e3", o1.getEmbedded2().getEmbedded10());
+
+        assertNull(o2.getEmbedded1());
+        assertNull(o2.getEmbedded2());
+    }
+
+    @Test
+    public void testSerializationEntityWithEmbeddableModified() throws Exception {
+        createSelectDataSet();
+
+        ObjectSelect<EmbedEntity1> query = ObjectSelect.query(EmbedEntity1.class);
+        List<EmbedEntity1> results = query.select(context);
+        assertEquals(1, results.size());
+
+        EmbedEntity1 o1 = results.get(0);
+        assertNotNull(o1);
+        o1.setPersistenceState(PersistenceState.MODIFIED);
+
+        EmbedEntity1 o2 = Util.cloneViaSerialization(o1);
+        assertNotNull(o2);
+
+        assertEquals(o1.getPersistenceState(), PersistenceState.MODIFIED);
+        assertEquals(o2.getPersistenceState(), PersistenceState.MODIFIED);
+
+        assertEquals("e1", o1.getEmbedded1().getEmbedded10());
+        assertEquals("e1", o2.getEmbedded1().getEmbedded10());
+
+        assertEquals("e3", o1.getEmbedded2().getEmbedded10());
+        assertEquals("e3", o2.getEmbedded2().getEmbedded10());
+    }
+
+    @Test
+    public void testSerializationEmbeddable() throws Exception {
+        createSelectDataSet();
+
+        ObjectSelect<EmbedEntity1> query = ObjectSelect.query(EmbedEntity1.class);
+        List<EmbedEntity1> results = query.select(context);
+        assertEquals(1, results.size());
+
+        EmbedEntity1 o1 = results.get(0);
+        assertNotNull(o1);
+
+        Embeddable1 e1 = o1.getEmbedded1();
+
+        Embeddable1 e2 = Util.cloneViaSerialization(e1);
+
+        assertEquals(e1.getEmbedded10(), e2.getEmbedded10());
+    }
+}
\ No newline at end of file
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_Embeddable1.java
b/cayenne-server/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_Embeddable1.java
index 1084e08..aa1f2b2 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_Embeddable1.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/embeddable/auto/_Embeddable1.java
@@ -1,5 +1,7 @@
 package org.apache.cayenne.testdo.embeddable.auto;
 
+import java.io.Serializable;
+
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.exp.Property;
 
@@ -9,18 +11,18 @@ import org.apache.cayenne.exp.Property;
  * since it may be overwritten next time code is regenerated. 
  * If you need to make any customizations, please use subclass. 
  */
-public abstract class _Embeddable1 extends Object {
+public abstract class _Embeddable1 implements Serializable {
 
-    public static final Property<String> EMBEDDED10 = Property.create("embedded10",
String.class);
     public static final Property<String> EMBEDDED20 = Property.create("embedded20",
String.class);
+    public static final Property<String> EMBEDDED10 = Property.create("embedded10",
String.class);
 
     // special properties injected by Cayenne
     private Persistent owner;
     private String embeddedProperty;
     
     // declared properties
-    protected String embedded10;
     protected String embedded20;
+    protected String embedded10;
 
     // lifecycle methods
     protected void propertyWillChange(String property, Object oldValue, Object newValue)
{
@@ -34,14 +36,6 @@ public abstract class _Embeddable1 extends Object {
     }
 
     // declared getters and setters
-    public void setEmbedded10(String embedded10) {
-        propertyWillChange("embedded10", this.embedded10, embedded10);
-        this.embedded10 = embedded10;
-    }
-    public String getEmbedded10() {
-        return embedded10;
-    }
-
     public void setEmbedded20(String embedded20) {
         propertyWillChange("embedded20", this.embedded20, embedded20);
         this.embedded20 = embedded20;
@@ -50,4 +44,12 @@ public abstract class _Embeddable1 extends Object {
         return embedded20;
     }
 
+    public void setEmbedded10(String embedded10) {
+        propertyWillChange("embedded10", this.embedded10, embedded10);
+        this.embedded10 = embedded10;
+    }
+    public String getEmbedded10() {
+        return embedded10;
+    }
+
 }
diff --git a/maven-plugins/cayenne-tools-itest/src/test/java/org/apache/cayenne/tools/CayenneGeneratorIntegrationTest.java
b/maven-plugins/cayenne-tools-itest/src/test/java/org/apache/cayenne/tools/CayenneGeneratorIntegrationTest.java
index 2142389..839a4e5 100644
--- a/maven-plugins/cayenne-tools-itest/src/test/java/org/apache/cayenne/tools/CayenneGeneratorIntegrationTest.java
+++ b/maven-plugins/cayenne-tools-itest/src/test/java/org/apache/cayenne/tools/CayenneGeneratorIntegrationTest.java
@@ -18,14 +18,14 @@
  ****************************************************************/
 package org.apache.cayenne.tools;
 
-import org.junit.Test;
-
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStreamReader;
 import java.util.regex.Pattern;
 
+import org.junit.Test;
+
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -127,7 +127,7 @@ public class CayenneGeneratorIntegrationTest {
         assertContents("org/apache/cayenne/testdo/embeddable/Embeddable1.java", "Embeddable1",
                 "org.apache.cayenne.testdo.embeddable", "_Embeddable1");
         assertContents("org/apache/cayenne/testdo/embeddable/auto/_Embeddable1.java", "_Embeddable1",
-                "org.apache.cayenne.testdo.embeddable.auto", "Object");
+                "org.apache.cayenne.testdo.embeddable.auto", "Serializable");
     }
 
     private String convertPath(String unixPath) {


Mime
View raw message