cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r439637 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/access/types/ test/java/org/apache/art/ test/java/org/apache/art/auto/ test/java/org/apache/cayenne/access/ test/resources/
Date Sat, 02 Sep 2006 19:11:47 GMT
Author: aadamchik
Date: Sat Sep  2 12:11:47 2006
New Revision: 439637

URL: http://svn.apache.org/viewvc?rev=439637&view=rev
Log:
CAY-650 - adding support for java.lang.Character

Added:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/CharacterEntity.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_CharacterEntity.java
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ByteOrCharArrayFactory.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/MiscTypesTst.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/resources/testmap.map.xml

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ByteOrCharArrayFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ByteOrCharArrayFactory.java?rev=439637&r1=439636&r2=439637&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ByteOrCharArrayFactory.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/ByteOrCharArrayFactory.java
Sat Sep  2 12:11:47 2006
@@ -19,8 +19,8 @@
 package org.apache.cayenne.access.types;
 
 /**
- * A factory that dynamically creates ExtendedTypes for Character[], Byte[] and char[]
- * based on adapter configured types for String and byte[].
+ * A factory that dynamically creates ExtendedTypes for Character, Character[], Byte[] and
+ * char[] based on adapter configured types for String and byte[].
  * 
  * @since 3.0
  * @author Andrus Adamchik
@@ -40,52 +40,60 @@
             Class elementType = objectClass.getComponentType();
 
             if (Character.class.isAssignableFrom(elementType)) {
-                // note - can't use "getRegisteredType" as it causes infinite recursion
+                // can't use "getRegisteredType" as it causes infinite recursion
                 ExtendedType stringType = map
                         .getExplictlyRegisteredType("java.lang.String");
 
-                // not sure if this type of recursion can occur, still worth checking
-                if (stringType instanceof CharacterArrayType) {
-                    throw new IllegalStateException(
-                            "Can't create CharacterArrayType for "
-                                    + objectClass.getName()
-                                    + ": no ExtendedType exists for String");
-                }
-
                 return new CharacterArrayType(stringType);
             }
             else if (Character.TYPE.isAssignableFrom(elementType)) {
 
-                // note - can't use "getRegisteredType" as it causes infinite recursion
+                // can't use "getRegisteredType" as it causes infinite recursion
                 ExtendedType stringType = map
                         .getExplictlyRegisteredType("java.lang.String");
 
-                // not sure if this type of recursion can occur, still worth checking
-                if (stringType instanceof CharArrayType) {
-                    throw new IllegalStateException("Can't create CharArrayType for "
-                            + objectClass.getName()
-                            + ": no ExtendedType exists for String");
-                }
-
                 return new CharArrayType(stringType);
             }
             else if (Byte.class.isAssignableFrom(elementType)) {
-                // note - can't use "getRegisteredType" as it causes infinite recursion
+                // can't use "getRegisteredType" as it causes infinite recursion
                 ExtendedType bytesType = map.getExplictlyRegisteredType("byte[]");
-
-                // not sure if this type of recursion can occur, still worth checking
-                if (bytesType instanceof ByteWrapperArrayType) {
-                    throw new IllegalStateException(
-                            "Can't create ByteWrapperArrayType for "
-                                    + objectClass.getName()
-                                    + ": no ExtendedType exists for byte[]");
-                }
-
                 return new ByteWrapperArrayType(bytesType);
             }
         }
+        else if (Character.class.isAssignableFrom(objectClass)) {
+
+            // can't use "getRegisteredType" as it causes infinite recursion
+            ExtendedType stringType = map.getExplictlyRegisteredType("java.lang.String");
+            return new CharacterType(stringType);
+        }
 
         return null;
+    }
+
+    final class CharacterType extends ExtendedTypeDecorator {
+
+        CharacterType(ExtendedType stringType) {
+            super(stringType);
+        }
+
+        public String getClassName() {
+            return "java.lang.Character";
+        }
+
+        Object fromJavaObject(Object object) {
+            return object != null
+                    ? String.valueOf(((Character) object).charValue())
+                    : null;
+        }
+
+        Object toJavaObject(Object object) {
+            if (object == null) {
+                return null;
+            }
+
+            String string = object.toString();
+            return (string.length() > 0) ? new Character(string.charAt(0)) : null;
+        }
     }
 
     final class CharArrayType extends ExtendedTypeDecorator {

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/CharacterEntity.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/CharacterEntity.java?rev=439637&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/CharacterEntity.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/CharacterEntity.java
Sat Sep  2 12:11:47 2006
@@ -0,0 +1,10 @@
+package org.apache.art;
+
+import org.apache.art.auto._CharacterEntity;
+
+public class CharacterEntity extends _CharacterEntity {
+
+}
+
+
+

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_CharacterEntity.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_CharacterEntity.java?rev=439637&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_CharacterEntity.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/art/auto/_CharacterEntity.java
Sat Sep  2 12:11:47 2006
@@ -0,0 +1,22 @@
+package org.apache.art.auto;
+
+/** Class _CharacterEntity 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 class _CharacterEntity extends org.apache.cayenne.CayenneDataObject {
+
+    public static final String CHARACTER_FIELD_PROPERTY = "characterField";
+
+    public static final String ID_PK_COLUMN = "ID";
+
+    public void setCharacterField(Character characterField) {
+        writeProperty("characterField", characterField);
+    }
+    public Character getCharacterField() {
+        return (Character)readProperty("characterField");
+    }
+    
+    
+}

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/MiscTypesTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/MiscTypesTst.java?rev=439637&r1=439636&r2=439637&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/MiscTypesTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/access/MiscTypesTst.java
Sat Sep  2 12:11:47 2006
@@ -21,6 +21,7 @@
 import java.lang.reflect.Array;
 
 import org.apache.art.ArraysEntity;
+import org.apache.art.CharacterEntity;
 import org.apache.art.SerializableEntity;
 import org.apache.cayenne.MockSerializable;
 import org.apache.cayenne.query.SelectQuery;
@@ -110,6 +111,23 @@
         assertArraysEqual(a, testRead.getCharWrapperArray());
 
         test.setCharWrapperArray(null);
+        context.commitChanges();
+    }
+    
+    public void testCharacter() {
+        DataContext context = createDataContext();
+
+        CharacterEntity test = (CharacterEntity) context.newObject(CharacterEntity.class);
+
+        test.setCharacterField(new Character('c'));
+        context.commitChanges();
+
+        SelectQuery q = new SelectQuery(CharacterEntity.class);
+        CharacterEntity testRead = (CharacterEntity) context.performQuery(q).get(0);
+        assertNotNull(testRead.getCharacterField());
+        assertEquals(new Character('c'), testRead.getCharacterField());
+
+        test.setCharacterField(null);
         context.commitChanges();
     }
 

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/resources/testmap.map.xml
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/resources/testmap.map.xml?rev=439637&r1=439636&r2=439637&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/resources/testmap.map.xml (original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/resources/testmap.map.xml Sat
Sep  2 12:11:47 2006
@@ -70,6 +70,10 @@
 		<db-attribute name="CALENDAR_FIELD" type="TIMESTAMP"/>
 		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
 	</db-entity>
+	<db-entity name="CHARACTER_ENTITY">
+		<db-attribute name="CHARACTER_FIELD" type="CHAR" length="1"/>
+		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+	</db-entity>
 	<db-entity name="CHAR_FK_TEST">
 		<db-attribute name="FK_COL" type="CHAR" length="10"/>
 		<db-attribute name="NAME" type="VARCHAR" length="100"/>
@@ -260,6 +264,9 @@
 	<obj-entity name="CharPkTestEntity" className="org.apache.art.CharPkTestEntity" dbEntityName="CHAR_PK_TEST">
 		<obj-attribute name="otherCol" type="java.lang.String" db-attribute-path="OTHER_COL"/>
 		<obj-attribute name="pkCol" type="java.lang.String" db-attribute-path="PK_COL"/>
+	</obj-entity>
+	<obj-entity name="CharacterEntity" className="org.apache.art.CharacterEntity" dbEntityName="CHARACTER_ENTITY">
+		<obj-attribute name="characterField" type="java.lang.Character" db-attribute-path="CHARACTER_FIELD"/>
 	</obj-entity>
 	<obj-entity name="ClobTestEntity" className="org.apache.art.ClobTestEntity" dbEntityName="CLOB_TEST">
 		<obj-attribute name="clobCol" type="java.lang.String" db-attribute-path="CLOB_COL"/>



Mime
View raw message