cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] branch master updated: CAY-2506 Java class generated for Embeddable object is not serializable
Date Mon, 29 Apr 2019 08:49:37 GMT
This is an automated email from the ASF dual-hosted git repository.

abulatski 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 980ba14  CAY-2506 Java class generated for Embeddable object is not serializable
     new 78ecba1  Merge PR #381
980ba14 is described below

commit 980ba14d6c6c0cfdad0d8fff5a9458933b1d59d2
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Mon Apr 29 11:43:48 2019 +0300

    CAY-2506 Java class generated for Embeddable object is not serializable
---
 RELEASE-NOTES.txt                                  |   1 +
 .../templates/v4_1/embeddable-singleclass.vm       |   3 +-
 .../templates/v4_1/embeddable-superclass.vm        |   3 +-
 .../cayenne/access/EmbeddingSerializeIT.java       | 131 +++++++++++++++++++++
 .../testdo/embeddable/auto/_Embeddable1.java       |   4 +-
 5 files changed, 139 insertions(+), 3 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index b53d7c6..311b8ea 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -37,6 +37,7 @@ CAY-2570 Use MySQL adapter for latest versions of MariaDB
 Bug Fixes:
 
 CAY-2332 Property API: unable to use eq() and in() methods for toMany relationships
+CAY-2506 Java class generated for Embeddable object is not serializable
 CAY-2509 Result of resolving lazily faulted relationships can be out-of-date
 CAY-2530 Modeler: DB Import and Class Generation from Project is performed for removed datamaps
 CAY-2531 Modeler: Importing same schema after Import Revert clears all entities in datamap
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 3e003bf..96a6f47 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")}##
@@ -44,7 +45,7 @@ $importUtils.addType(${attr.Type})##
 ${importUtils.generate()}
 
 ##  extends ${baseClassName} - always Object, so skip it
-public abstract class ${subClassName} {
+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 0e8c4ce..2af7266 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")}##
@@ -50,7 +51,7 @@ ${importUtils.generate()}
  * If you need to make any customizations, please use subclass. 
  */
 ## extends ${baseClassName} - always Object, so skip it
-public abstract class ${superClassName} {
+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..05d7a44
--- /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());
+    }
+}
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 8e280f4..905765c 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;
 
 /** 
@@ -8,7 +10,7 @@ import org.apache.cayenne.Persistent;
  * since it may be overwritten next time code is regenerated. 
  * If you need to make any customizations, please use subclass. 
  */
-public abstract class _Embeddable1 {
+public abstract class _Embeddable1 implements Serializable {
 
     // special properties injected by Cayenne
     private Persistent owner;


Mime
View raw message