cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r439636 - /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
Date Sat, 02 Sep 2006 19:09:40 GMT
Author: aadamchik
Date: Sat Sep  2 12:09:39 2006
New Revision: 439636

URL: http://svn.apache.org/viewvc?rev=439636&view=rev
Log:
refactoring - switching extendedtype to ExtendedTypeDecorator superclass

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java?rev=439636&r1=439635&r2=439636&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/access/types/SerializableTypeFactory.java
Sat Sep  2 12:09:39 2006
@@ -23,12 +23,8 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
-import java.sql.CallableStatement;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.validation.ValidationResult;
+import org.apache.cayenne.CayenneRuntimeException;
 
 /**
  * ExtendedTypeFactory for handling serializable objects. Returned ExtendedType is simply
@@ -73,64 +69,20 @@
     /**
      * A serialization wrapper on top of byte[] ExtendedType
      */
-    final class SerializableType implements ExtendedType {
+    final class SerializableType extends ExtendedTypeDecorator {
 
         private Class javaClass;
-        private ExtendedType bytesType;
 
         SerializableType(Class javaClass, ExtendedType bytesType) {
+            super(bytesType);
             this.javaClass = javaClass;
-            this.bytesType = bytesType;
         }
 
         public String getClassName() {
             return javaClass.getName();
         }
 
-        public Object materializeObject(CallableStatement rs, int index, int type)
-                throws Exception {
-
-            byte[] bytes = (byte[]) bytesType.materializeObject(rs, index, type);
-            return readBytes(bytes);
-        }
-
-        public Object materializeObject(ResultSet rs, int index, int type)
-                throws Exception {
-            byte[] bytes = (byte[]) bytesType.materializeObject(rs, index, type);
-            return readBytes(bytes);
-        }
-
-        public void setJdbcObject(
-                PreparedStatement statement,
-                Object value,
-                int pos,
-                int type,
-                int precision) throws Exception {
-
-            if (value == null) {
-                statement.setNull(pos, type);
-            }
-            else {
-                byte[] bytes = writeBytes((Serializable) value);
-                bytesType.setJdbcObject(statement, bytes, pos, type, precision);
-            }
-        }
-
-        public boolean validateProperty(
-                Object source,
-                String property,
-                Object value,
-                DbAttribute dbAttribute,
-                ValidationResult validationResult) {
-            return true;
-        }
-
-        private Object readBytes(byte[] bytes) throws Exception {
-            return bytes != null && bytes.length > 0 ? new ObjectInputStream(
-                    new ByteArrayInputStream(bytes)).readObject() : null;
-        }
-
-        private byte[] writeBytes(Serializable object) throws Exception {
+        Object fromJavaObject(Object object) {
             ByteArrayOutputStream bytes = new ByteArrayOutputStream() {
 
                 // avoid unneeded array copy...
@@ -139,11 +91,27 @@
                 }
             };
 
-            ObjectOutputStream out = new ObjectOutputStream(bytes);
-            out.writeObject(object);
-            out.close();
+            try {
+                ObjectOutputStream out = new ObjectOutputStream(bytes);
+                out.writeObject(object);
+                out.close();
+            }
+            catch (Exception e) {
+                throw new CayenneRuntimeException("Error serializing object", e);
+            }
 
             return bytes.toByteArray();
+        }
+
+        Object toJavaObject(Object object) {
+            byte[] bytes = (byte[]) object;
+            try {
+                return bytes != null && bytes.length > 0 ? new ObjectInputStream(
+                        new ByteArrayInputStream(bytes)).readObject() : null;
+            }
+            catch (Exception e) {
+                throw new CayenneRuntimeException("Error deserializing object", e);
+            }
         }
     }
 }



Mime
View raw message