Return-Path: Delivered-To: apmail-incubator-cayenne-commits-archive@locus.apache.org Received: (qmail 73119 invoked from network); 2 Sep 2006 19:10:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 Sep 2006 19:10:02 -0000 Received: (qmail 26343 invoked by uid 500); 2 Sep 2006 19:10:02 -0000 Delivered-To: apmail-incubator-cayenne-commits-archive@incubator.apache.org Received: (qmail 26321 invoked by uid 500); 2 Sep 2006 19:10:01 -0000 Mailing-List: contact cayenne-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cayenne-dev@incubator.apache.org Delivered-To: mailing list cayenne-commits@incubator.apache.org Received: (qmail 26312 invoked by uid 99); 2 Sep 2006 19:10:01 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 02 Sep 2006 12:10:01 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 02 Sep 2006 12:10:01 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 0422B1A981A; Sat, 2 Sep 2006 12:09:41 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: cayenne-commits@incubator.apache.org From: aadamchik@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060902190941.0422B1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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); + } } } }