You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/06/16 08:46:13 UTC
svn commit: r414754 - in
/incubator/cayenne/main/trunk/cayenne/cayenne-java/src:
cayenne/java/org/objectstyle/cayenne/remote/hessian/
cayenne/java/org/objectstyle/cayenne/remote/hessian/service/
tests/java/org/objectstyle/cayenne/
Author: aadamchik
Date: Thu Jun 15 23:46:13 2006
New Revision: 414754
URL: http://svn.apache.org/viewvc?rev=414754&view=rev
Log:
DataRow Hessian serialization bug. (I can't log in to Jira due to Apache network problems; I will enter the bug once this is resolved)
Added:
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/DataRowDeserializer.java
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/service/ServerDataRowSerializer.java
Modified:
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/ClientSerializerFactory.java
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/service/ServerSerializerFactory.java
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/DataRowTst.java
Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/ClientSerializerFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/ClientSerializerFactory.java?rev=414754&r1=414753&r2=414754&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/ClientSerializerFactory.java (original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/ClientSerializerFactory.java Thu Jun 15 23:46:13 2006
@@ -58,6 +58,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.objectstyle.cayenne.DataRow;
import org.objectstyle.cayenne.util.PersistentObjectList;
import com.caucho.hessian.io.AbstractSerializerFactory;
@@ -75,6 +76,7 @@
class ClientSerializerFactory extends AbstractSerializerFactory {
private Map deserializers;
+ private Deserializer dataRowDeserializer;
public Serializer getSerializer(Class cl) throws HessianProtocolException {
return null;
@@ -101,7 +103,13 @@
deserializers.put(cl, deserializer);
}
}
-
+ }
+ else if(DataRow.class.isAssignableFrom(cl)) {
+ if(dataRowDeserializer == null) {
+ dataRowDeserializer = new DataRowDeserializer();
+ }
+
+ return dataRowDeserializer;
}
return deserializer;
Added: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/DataRowDeserializer.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/DataRowDeserializer.java?rev=414754&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/DataRowDeserializer.java (added)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/DataRowDeserializer.java Thu Jun 15 23:46:13 2006
@@ -0,0 +1,116 @@
+/* ====================================================================
+ *
+ * The ObjectStyle Group Software License, version 1.1
+ * ObjectStyle Group - http://objectstyle.org/
+ *
+ * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
+ * of the software. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any,
+ * must include the following acknowlegement:
+ * "This product includes software developed by independent contributors
+ * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
+ * or promote products derived from this software without prior written
+ * permission. For written permission, email
+ * "andrus at objectstyle dot org".
+ *
+ * 5. Products derived from this software may not be called "ObjectStyle"
+ * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
+ * names without prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals and hosted on ObjectStyle Group web site. For more
+ * information on the ObjectStyle Group, please see
+ * <http://objectstyle.org/>.
+ */
+package org.objectstyle.cayenne.remote.hessian;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+
+import org.objectstyle.cayenne.CayenneRuntimeException;
+import org.objectstyle.cayenne.DataRow;
+
+import com.caucho.hessian.io.AbstractHessianInput;
+import com.caucho.hessian.io.AbstractMapDeserializer;
+
+/**
+ * Client side deserilaizer of DataRows.
+ *
+ * @author Andrus Adamchik
+ * @since 1.2
+ */
+class DataRowDeserializer extends AbstractMapDeserializer {
+
+ protected Field versionField;
+
+ DataRowDeserializer() {
+ try {
+ versionField = DataRow.class.getDeclaredField("version");
+ }
+ catch (Exception e) {
+ throw new CayenneRuntimeException(
+ "Error building deserializer for DataRow",
+ e);
+ }
+
+ versionField.setAccessible(true);
+ }
+
+ public Class getType() {
+ return DataRow.class;
+ }
+
+ public Object readMap(AbstractHessianInput in) throws IOException {
+
+ int size = in.readInt();
+ DataRow row = new DataRow(size);
+ try {
+ versionField.set(row, new Long(in.readLong()));
+ }
+ catch (Exception e) {
+ throw new IOException("Error reading 'version' field");
+ }
+
+ row.setReplacesVersion(in.readLong());
+ in.addRef(row);
+
+ while (!in.isEnd()) {
+ row.put(in.readObject(), in.readObject());
+ }
+
+ in.readEnd();
+
+ return row;
+ }
+}
Added: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/service/ServerDataRowSerializer.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/service/ServerDataRowSerializer.java?rev=414754&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/service/ServerDataRowSerializer.java (added)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/service/ServerDataRowSerializer.java Thu Jun 15 23:46:13 2006
@@ -0,0 +1,97 @@
+/* ====================================================================
+ *
+ * The ObjectStyle Group Software License, version 1.1
+ * ObjectStyle Group - http://objectstyle.org/
+ *
+ * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
+ * of the software. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any,
+ * must include the following acknowlegement:
+ * "This product includes software developed by independent contributors
+ * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
+ * or promote products derived from this software without prior written
+ * permission. For written permission, email
+ * "andrus at objectstyle dot org".
+ *
+ * 5. Products derived from this software may not be called "ObjectStyle"
+ * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
+ * names without prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals and hosted on ObjectStyle Group web site. For more
+ * information on the ObjectStyle Group, please see
+ * <http://objectstyle.org/>.
+ */
+package org.objectstyle.cayenne.remote.hessian.service;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.objectstyle.cayenne.DataRow;
+
+import com.caucho.hessian.io.AbstractHessianOutput;
+import com.caucho.hessian.io.AbstractSerializer;
+
+/**
+ * A server-side DataRow Hessian serializer.
+ *
+ * @author Andrus Adamchik
+ */
+class ServerDataRowSerializer extends AbstractSerializer {
+
+ public void writeObject(Object object, AbstractHessianOutput out) throws IOException {
+ if (out.addRef(object)) {
+ return;
+ }
+
+ DataRow row = (DataRow) object;
+
+ out.writeMapBegin(DataRow.class.getName());
+
+ out.writeInt(row.size());
+ out.writeLong(row.getVersion());
+ out.writeLong(row.getReplacesVersion());
+
+ Iterator it = row.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry entry = (Map.Entry) it.next();
+ out.writeObject(entry.getKey());
+ out.writeObject(entry.getValue());
+ }
+
+ out.writeMapEnd();
+ }
+
+}
Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/service/ServerSerializerFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/service/ServerSerializerFactory.java?rev=414754&r1=414753&r2=414754&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/service/ServerSerializerFactory.java (original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/remote/hessian/service/ServerSerializerFactory.java Thu Jun 15 23:46:13 2006
@@ -58,6 +58,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.objectstyle.cayenne.DataRow;
import org.objectstyle.cayenne.map.EntityResolver;
import org.objectstyle.cayenne.query.AbstractQuery;
import org.objectstyle.cayenne.util.PersistentObjectList;
@@ -78,10 +79,12 @@
private EntityResolver serverResolver;
private ServerPersistentObjectListSerializer persistentObjectListSerializer;
+ private ServerDataRowSerializer dataRowSerilaizer;
private Map deserializers;
ServerSerializerFactory() {
this.persistentObjectListSerializer = new ServerPersistentObjectListSerializer();
+ this.dataRowSerilaizer = new ServerDataRowSerializer();
}
// this method is used by HessianCOnfig to inject resolver
@@ -93,6 +96,9 @@
if (PersistentObjectList.class.isAssignableFrom(cl)) {
return persistentObjectListSerializer;
+ }
+ else if (DataRow.class.isAssignableFrom(cl)) {
+ return dataRowSerilaizer;
}
return null;
Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/DataRowTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/DataRowTst.java?rev=414754&r1=414753&r2=414754&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/DataRowTst.java (original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/DataRowTst.java Thu Jun 15 23:46:13 2006
@@ -58,13 +58,37 @@
import org.objectstyle.cayenne.map.DataMap;
import org.objectstyle.cayenne.map.DbAttribute;
import org.objectstyle.cayenne.map.DbEntity;
+import org.objectstyle.cayenne.map.EntityResolver;
import org.objectstyle.cayenne.map.ObjEntity;
+import org.objectstyle.cayenne.remote.hessian.service.HessianUtil;
import org.objectstyle.cayenne.unit.CayenneTestCase;
/**
* @author Andrei Adamchik
*/
public class DataRowTst extends CayenneTestCase {
+
+ public void testHessianSerializability() throws Exception {
+ DataRow s1 = new DataRow(10);
+ s1.put("a", "b");
+
+ DataRow s2 = (DataRow) HessianUtil.cloneViaServerClientSerialization(
+ s1,
+ new EntityResolver());
+
+ assertNotSame(s1, s2);
+ assertEquals(s1, s2);
+ assertEquals(s1.getVersion(), s2.getVersion());
+ assertEquals(s1.getReplacesVersion(), s2.getReplacesVersion());
+
+ // at the moment there are no serializers that can go from client to server.
+ // DataRow s3 = (DataRow) HessianUtil.cloneViaClientServerSerialization(
+ // s1,
+ // new EntityResolver());
+ //
+ // assertNotSame(s1, s3);
+ // assertEquals(s1, s3);
+ }
public void testVersion() throws Exception {
DataRow s1 = new DataRow(10);