cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r439612 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/access/types/ByteOrCharArrayFactory.java test/java/org/apache/cayenne/access/MiscTypesTst.java
Date Sat, 02 Sep 2006 15:48:43 GMT
Author: aadamchik
Date: Sat Sep  2 08:48:43 2006
New Revision: 439612

URL: http://svn.apache.org/viewvc?rev=439612&view=rev
Log:
CAY-650 - finished

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

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=439612&r1=439611&r2=439612&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 08:48:43 2006
@@ -70,7 +70,18 @@
                 return new CharArrayType(stringType);
             }
             else if (Byte.class.isAssignableFrom(elementType)) {
-                return map.getRegisteredType(byte[].class);
+                // note - 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);
             }
         }
 
@@ -156,7 +167,7 @@
                 buffer[i] = bytes[i] != null ? bytes[i].byteValue() : 0;
             }
 
-            return buffer.toString();
+            return buffer;
         }
 
         Object toJavaObject(Object object) {

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=439612&r1=439611&r2=439612&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 08:48:43 2006
@@ -53,6 +53,26 @@
         context.commitChanges();
     }
 
+    public void testByteArray() {
+        DataContext context = createDataContext();
+
+        ArraysEntity test = (ArraysEntity) context.newObject(ArraysEntity.class);
+
+        byte[] a = new byte[] {
+                1, 2, 3
+        };
+        test.setByteArray(a);
+        context.commitChanges();
+
+        SelectQuery q = new SelectQuery(ArraysEntity.class);
+        ArraysEntity testRead = (ArraysEntity) context.performQuery(q).get(0);
+        assertNotNull(testRead.getByteArray());
+        assertArraysEqual(a, testRead.getByteArray());
+
+        test.setByteArray(null);
+        context.commitChanges();
+    }
+
     public void testCharArray() {
         DataContext context = createDataContext();
 
@@ -90,6 +110,26 @@
         assertArraysEqual(a, testRead.getCharWrapperArray());
 
         test.setCharWrapperArray(null);
+        context.commitChanges();
+    }
+
+    public void testByteWrapperArray() {
+        DataContext context = createDataContext();
+
+        ArraysEntity test = (ArraysEntity) context.newObject(ArraysEntity.class);
+
+        Byte[] a = new Byte[] {
+                new Byte((byte) 1), new Byte((byte) 2), new Byte((byte) 3)
+        };
+        test.setByteWrapperArray(a);
+        context.commitChanges();
+
+        SelectQuery q = new SelectQuery(ArraysEntity.class);
+        ArraysEntity testRead = (ArraysEntity) context.performQuery(q).get(0);
+        assertNotNull(testRead.getByteWrapperArray());
+        assertArraysEqual(a, testRead.getByteWrapperArray());
+
+        test.setByteWrapperArray(null);
         context.commitChanges();
     }
 



Mime
View raw message