cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skolbac...@apache.org
Subject cayenne git commit: -add warn information for SerializableTypeFactory; -provide array type test; -fix registration type for arrays;
Date Tue, 26 May 2015 11:08:25 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 0aad4a810 -> 1de0edfe7


-add warn information for SerializableTypeFactory;
-provide array type test;
-fix registration type for arrays;


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/1de0edfe
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/1de0edfe
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/1de0edfe

Branch: refs/heads/master
Commit: 1de0edfe75b71d76992adca96e5c21a1b73f055f
Parents: 0aad4a8
Author: Savva Kolbachev <s.kolbachev@gmail.com>
Authored: Tue May 26 14:05:06 2015 +0300
Committer: Savva Kolbachev <s.kolbachev@gmail.com>
Committed: Tue May 26 14:05:06 2015 +0300

----------------------------------------------------------------------
 .../cayenne/access/types/ExtendedTypeMap.java   | 16 +-----
 .../access/types/SerializableTypeFactory.java   | 14 +++--
 .../org/apache/cayenne/dba/TypesMapping.java    |  6 +-
 .../cayenne/access/DataContextArrayTypeIT.java  | 58 ++++++++++++++++++++
 .../testdo/array_type/ArrayTestEntity.java      |  9 +++
 .../array_type/auto/_ArrayTestEntity.java       | 27 +++++++++
 .../cayenne/unit/di/server/CayenneProjects.java |  1 +
 .../cayenne/unit/di/server/SchemaBuilder.java   |  2 +-
 .../src/test/resources/array-type.map.xml       | 18 ++++++
 .../src/test/resources/cayenne-array-type.xml   |  4 ++
 10 files changed, 134 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/1de0edfe/cayenne-server/src/main/java/org/apache/cayenne/access/types/ExtendedTypeMap.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/types/ExtendedTypeMap.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/types/ExtendedTypeMap.java
index cb46ef1..48534a5 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/types/ExtendedTypeMap.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/types/ExtendedTypeMap.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.access.types;
 
+import org.apache.cayenne.util.Util;
+
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -27,8 +29,6 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 
-import org.apache.cayenne.util.Util;
-
 /**
  * Stores ExtendedTypes, implementing an algorithm to determine the right type for a given
  * Java class. See {@link #getRegisteredType(String)} documentation for lookup algorithm
@@ -197,17 +197,7 @@ public class ExtendedTypeMap {
      * instance.
      */
     public ExtendedType getRegisteredType(Class<?> javaClass) {
-        String name = null;
-
-        if (javaClass.isArray()) {
-            // only support single dimensional arrays now
-            name = javaClass.getComponentType().getName() + "[]";
-        }
-        else {
-            name = javaClass.getName();
-        }
-
-        return getRegisteredType(name);
+        return getRegisteredType(javaClass.getCanonicalName());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1de0edfe/cayenne-server/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
index 5836f03..4b9ea07 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
@@ -18,14 +18,16 @@
  ****************************************************************/
 package org.apache.cayenne.access.types;
 
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 
-import org.apache.cayenne.CayenneRuntimeException;
-
 /**
  * ExtendedTypeFactory for handling serializable objects. Returned ExtendedType is simply
  * an object serialization wrapper on top of byte[] ExtendedType.
@@ -34,6 +36,8 @@ import org.apache.cayenne.CayenneRuntimeException;
  */
 class SerializableTypeFactory implements ExtendedTypeFactory {
 
+    private static final Log logger = LogFactory.getLog(SerializableTypeFactory.class);
+
     private ExtendedTypeMap map;
 
     SerializableTypeFactory(ExtendedTypeMap map) {
@@ -41,8 +45,10 @@ class SerializableTypeFactory implements ExtendedTypeFactory {
     }
 
     public ExtendedType getType(Class<?> objectClass) {
+        logger.warn("Haven't found suitable ExtendedType for class '" + objectClass.getCanonicalName()
+ "'. Most likely you need to define custom ExtendedType.");
 
         if (Serializable.class.isAssignableFrom(objectClass)) {
+            logger.warn("SerializableType will be used for type conversion.");
 
             // using a binary stream delegate instead of byte[] may actually speed up
             // things in some dbs, but at least byte[] type works consistently across
@@ -55,7 +61,7 @@ class SerializableTypeFactory implements ExtendedTypeFactory {
             if (bytesType instanceof SerializableType) {
                 throw new IllegalStateException(
                         "Can't create Serializable ExtendedType for "
-                                + objectClass.getName()
+                                + objectClass.getCanonicalName()
                                 + ": no ExtendedType exists for byte[]");
             }
 
@@ -79,7 +85,7 @@ class SerializableTypeFactory implements ExtendedTypeFactory {
 
         @Override
         public String getClassName() {
-            return javaClass.getName();
+            return javaClass.getCanonicalName();
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1de0edfe/cayenne-server/src/main/java/org/apache/cayenne/dba/TypesMapping.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/dba/TypesMapping.java b/cayenne-server/src/main/java/org/apache/cayenne/dba/TypesMapping.java
index df0d5c8..cfc5cda 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/dba/TypesMapping.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/dba/TypesMapping.java
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.dba;
 
+import org.apache.cayenne.util.Util;
+
 import java.io.Serializable;
 import java.math.BigInteger;
 import java.sql.DatabaseMetaData;
@@ -31,8 +33,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cayenne.util.Util;
-
 import static java.sql.Types.*;
 
 /**
@@ -120,7 +120,7 @@ public class TypesMapping {
     private static final Map<String, Integer> JAVA_SQL_ENUM = new HashMap<String,
Integer>();
 
     static {
-        SQL_STRING_TYPE.put(SQL_ARRAY, ARRAY);
+//        SQL_STRING_TYPE.put(SQL_ARRAY, ARRAY);
         SQL_STRING_TYPE.put(SQL_BIGINT, BIGINT);
         SQL_STRING_TYPE.put(SQL_BINARY, BINARY);
         SQL_STRING_TYPE.put(SQL_BIT, BIT);

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1de0edfe/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextArrayTypeIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextArrayTypeIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextArrayTypeIT.java
new file mode 100644
index 0000000..67db2a2
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextArrayTypeIT.java
@@ -0,0 +1,58 @@
+/*****************************************************************
+ *   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 org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.testdo.array_type.ArrayTestEntity;
+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.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNotNull;
+
+
+@UseServerRuntime(CayenneProjects.ARRAY_TYPE_PROJECT)
+public class DataContextArrayTypeIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    @Test
+    public void testDoubleArray() {
+        ArrayTestEntity arrayTest = context.newObject(ArrayTestEntity.class);
+        Double[] doubleArray = {1.0, 2.0, 3.0};
+
+        arrayTest.setDoubleArray(doubleArray);
+        context.commitChanges();
+
+        List<ArrayTestEntity> res = context.performQuery(new SelectQuery(ArrayTestEntity.class));
+        ArrayTestEntity arrayRes = res.get(0);
+
+        assertNotNull(arrayRes);
+        assertNotNull(arrayRes.getDoubleArray());
+        assertArrayEquals(doubleArray, arrayRes.getDoubleArray());
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1de0edfe/cayenne-server/src/test/java/org/apache/cayenne/testdo/array_type/ArrayTestEntity.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/array_type/ArrayTestEntity.java
b/cayenne-server/src/test/java/org/apache/cayenne/testdo/array_type/ArrayTestEntity.java
new file mode 100644
index 0000000..64fa867
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/array_type/ArrayTestEntity.java
@@ -0,0 +1,9 @@
+package org.apache.cayenne.testdo.array_type;
+
+import org.apache.cayenne.testdo.array_type.auto._ArrayTestEntity;
+
+public class ArrayTestEntity extends _ArrayTestEntity {
+
+    private static final long serialVersionUID = 1L; 
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1de0edfe/cayenne-server/src/test/java/org/apache/cayenne/testdo/array_type/auto/_ArrayTestEntity.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/testdo/array_type/auto/_ArrayTestEntity.java
b/cayenne-server/src/test/java/org/apache/cayenne/testdo/array_type/auto/_ArrayTestEntity.java
new file mode 100644
index 0000000..4e55dd7
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/testdo/array_type/auto/_ArrayTestEntity.java
@@ -0,0 +1,27 @@
+package org.apache.cayenne.testdo.array_type.auto;
+
+import org.apache.cayenne.CayenneDataObject;
+import org.apache.cayenne.exp.Property;
+
+/**
+ * Class _ArrayTestEntity was generated by Cayenne.
+ * It is probably a good idea to avoid changing this class manually,
+ * since it may be overwritten next time code is regenerated.
+ * If you need to make any customizations, please use subclass.
+ */
+public abstract class _ArrayTestEntity extends CayenneDataObject {
+
+    private static final long serialVersionUID = 1L; 
+
+    public static final String ID_PK_COLUMN = "ID";
+
+    public static final Property<Double[]> DOUBLE_ARRAY = new Property<Double[]>("doubleArray");
+
+    public void setDoubleArray(Double[] doubleArray) {
+        writeProperty("doubleArray", doubleArray);
+    }
+    public Double[] getDoubleArray() {
+        return (Double[])readProperty("doubleArray");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1de0edfe/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/CayenneProjects.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/CayenneProjects.java
b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/CayenneProjects.java
index f731191..2d92da8 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/CayenneProjects.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/CayenneProjects.java
@@ -26,6 +26,7 @@ public class CayenneProjects {
     // can define their own on the fly (TODO: how would that work with the
     // global schema
     // setup?)
+    public static final String ARRAY_TYPE_PROJECT = "cayenne-array-type.xml";
     public static final String BINARY_PK_PROJECT = "cayenne-binary-pk.xml";
     public static final String COMPOUND_PROJECT = "cayenne-compound.xml";
     public static final String DATE_TIME_PROJECT = "cayenne-date-time.xml";

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1de0edfe/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
index 0bb751b..f397168 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
@@ -78,7 +78,7 @@ public class SchemaBuilder {
             "map-to-many.map.xml", "toone.map.xml", "meaningful-pk.map.xml", "table-primitives.map.xml",
             "generic.map.xml", "map-db1.map.xml", "map-db2.map.xml", "embeddable.map.xml",
"qualified.map.xml",
             "quoted-identifiers.map.xml", "inheritance-single-table1.map.xml", "inheritance-vertical.map.xml",
-            "oneway-rels.map.xml", "unsupported-distinct-types.map.xml" };
+            "oneway-rels.map.xml", "unsupported-distinct-types.map.xml", "array-type.map.xml"
};
 
     // hardcoded dependent entities that should be excluded
     // if LOBs are not supported

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1de0edfe/cayenne-server/src/test/resources/array-type.map.xml
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/resources/array-type.map.xml b/cayenne-server/src/test/resources/array-type.map.xml
new file mode 100644
index 0000000..957a1ec
--- /dev/null
+++ b/cayenne-server/src/test/resources/array-type.map.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/7/modelMap"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://cayenne.apache.org/schema/7/modelMap http://cayenne.apache.org/schema/7/modelMap.xsd"
+          project-version="7">
+    <property name="defaultPackage" value="org.apache.cayenne.testdo.array_type"/>
+    <property name="defaultSuperclass" value="org.apache.cayenne.CayenneDataObject"/>
+    <property name="clientSupported" value="true"/>
+    <property name="defaultClientPackage" value="test.client"/>
+    <property name="defaultClientSuperclass" value="org.apache.cayenne.PersistentObject"/>
+    <db-entity name="ARRAY_TEST">
+        <db-attribute name="DOUBLE_ARRAY" type="VARBINARY" length="2048"/>
+        <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+    </db-entity>
+    <obj-entity name="ArrayTestEntity" className="org.apache.cayenne.testdo.array_type.ArrayTestEntity"
dbEntityName="ARRAY_TEST">
+        <obj-attribute name="doubleArray" type="java.lang.Double[]" db-attribute-path="DOUBLE_ARRAY"/>
+    </obj-entity>
+</data-map>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cayenne/blob/1de0edfe/cayenne-server/src/test/resources/cayenne-array-type.xml
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/resources/cayenne-array-type.xml b/cayenne-server/src/test/resources/cayenne-array-type.xml
new file mode 100644
index 0000000..c224355
--- /dev/null
+++ b/cayenne-server/src/test/resources/cayenne-array-type.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domain project-version="7">
+    <map name="array-type"/>
+</domain>
\ No newline at end of file


Mime
View raw message