summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-02-25 10:07:50 (EST)
committerEike Stepper2008-02-25 10:07:50 (EST)
commit1b1facdb792c5e0534f22cba2c16e7234ed11bec (patch)
treea1e826e9e5ddbf70674eeccb6355c901b12fd86a
parent5bfffc20f2b3dda2f77d38bf8ba329307dc19edb (diff)
downloadcdo-1b1facdb792c5e0534f22cba2c16e7234ed11bec.zip
cdo-1b1facdb792c5e0534f22cba2c16e7234ed11bec.tar.gz
cdo-1b1facdb792c5e0534f22cba2c16e7234ed11bec.tar.bz2
[217117] Develop a HibernateStore
https://bugs.eclipse.org/bugs/show_bug.cgi?id=217117
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/OpenSessionIndication.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.hibernate/CDO AllTests.launch19
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/OpenSessionRequest.java37
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExtendedIOTest.java60
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/DataInputExtender.java12
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java6
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInputStream.java12
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedIOUtil.java65
8 files changed, 162 insertions, 54 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/OpenSessionIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/OpenSessionIndication.java
index 9d9ceb7..4cb625d 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/OpenSessionIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/OpenSessionIndication.java
@@ -189,6 +189,11 @@ public class OpenSessionIndication extends IndicationWithResponse
private void serializeClass(ExtendedDataOutputStream out, Class<?> c) throws IOException
{
+ if (PROTOCOL.isEnabled())
+ {
+ PROTOCOL.format("Serializing class " + c.getName());
+ }
+
out.writeObject(c);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests.hibernate/CDO AllTests.launch b/plugins/org.eclipse.emf.cdo.tests.hibernate/CDO AllTests.launch
deleted file mode 100644
index 8c875b2..0000000
--- a/plugins/org.eclipse.emf.cdo.tests.hibernate/CDO AllTests.launch
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTests.java"/>
-</listAttribute>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="1"/>
-</listAttribute>
-<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
-<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>
-<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;sourceLookupDirector&gt;&#13;&#10;&lt;sourceContainers duplicates=&quot;false&quot;&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;javaProject name=&amp;quot;org.eclipse.emf.cdo&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.javaProject&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;default/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.debug.core.containerType.default&quot;/&gt;&#13;&#10;&lt;/sourceContainers&gt;&#13;&#10;&lt;/sourceLookupDirector&gt;&#13;&#10;"/>
-<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
-<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
-<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
-<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
-<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.emf.cdo.tests.AllTests"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.emf.cdo.tests"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Ddebug=true&#13;&#10;-Dvista.cache.selector"/>
-</launchConfiguration>
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/OpenSessionRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/OpenSessionRequest.java
index f4af60f..4da1d3b 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/OpenSessionRequest.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/OpenSessionRequest.java
@@ -21,14 +21,10 @@ import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.net4j.channel.IChannel;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.signal.RequestWithConfirmation;
-import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.io.ExtendedDataInputStream;
import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectStreamClass;
import java.text.MessageFormat;
/**
@@ -135,35 +131,14 @@ public class OpenSessionRequest extends RequestWithConfirmation<OpenSessionResul
return result;
}
- private Class<?> deserializeClass(InputStream in) throws IOException
+ private Class<?> deserializeClass(ExtendedDataInputStream in) throws IOException
{
- ObjectInputStream ois = new ObjectInputStream(in)
- {
- @Override
- protected Class<?> resolveClass(ObjectStreamClass v) throws IOException, ClassNotFoundException
- {
- String className = v.getName();
- ClassLoader loader = OM.class.getClassLoader();
-
- try
- {
- return loader.loadClass(className);
- }
- catch (ClassNotFoundException ex)
- {
- ex.printStackTrace();
- return super.resolveClass(v);
- }
- }
- };
-
- try
- {
- return (Class<?>)ois.readObject();
- }
- catch (ClassNotFoundException ex)
+ Class<?> clazz = (Class<?>)in.readObject(OM.class.getClassLoader());
+ if (PROTOCOL.isEnabled())
{
- throw WrappedException.wrap(ex);
+ PROTOCOL.format("Deserialized class " + clazz.getName());
}
+
+ return clazz;
}
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExtendedIOTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExtendedIOTest.java
index ec49ac3..f48fad4 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExtendedIOTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExtendedIOTest.java
@@ -39,9 +39,51 @@ public class ExtendedIOTest extends AbstractOMTest
assertEquals(map, result);
}
- public void testByteArray() throws Exception
+ public void testObject1() throws Exception
{
- final byte[] byteArray = createByteArray();
+ final byte[] byteArray = createByteArray1();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
+ edos.writeObject(byteArray);
+ edos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
+ byte[] result = (byte[])edis.readObject();
+ assertTrue(Arrays.equals(byteArray, result));
+ }
+
+ public void testObject2() throws Exception
+ {
+ final byte[] byteArray = createByteArray2();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
+ edos.writeObject(byteArray);
+ edos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
+ byte[] result = (byte[])edis.readObject();
+ assertTrue(Arrays.equals(byteArray, result));
+ }
+
+ public void testByteArray1() throws Exception
+ {
+ final byte[] byteArray = createByteArray1();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
+ edos.writeByteArray(byteArray);
+ edos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
+ byte[] result = edis.readByteArray();
+ assertTrue(Arrays.equals(byteArray, result));
+ }
+
+ public void testByteArray2() throws Exception
+ {
+ final byte[] byteArray = createByteArray2();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
edos.writeByteArray(byteArray);
@@ -53,7 +95,7 @@ public class ExtendedIOTest extends AbstractOMTest
assertTrue(Arrays.equals(byteArray, result));
}
- private byte[] createByteArray() throws IOException
+ private byte[] createByteArray1() throws IOException
{
HashMap<String, String> map = createMap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -63,6 +105,18 @@ public class ExtendedIOTest extends AbstractOMTest
return baos.toByteArray();
}
+ private byte[] createByteArray2()
+ {
+ byte[] byteArray = new byte[256];
+ byte v = Byte.MIN_VALUE;
+ for (int i = 0; i < byteArray.length; i++)
+ {
+ byteArray[i] = v++;
+ }
+
+ return byteArray;
+ }
+
private HashMap<String, String> createMap()
{
HashMap<String, String> map = new HashMap<String, String>();
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/DataInputExtender.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/DataInputExtender.java
index 9865f69..2145d11 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/DataInputExtender.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/DataInputExtender.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.net4j.util.io;
+import org.eclipse.net4j.util.io.ExtendedIOUtil.ClassResolver;
+
import java.io.DataInput;
import java.io.IOException;
@@ -105,6 +107,16 @@ public class DataInputExtender implements ExtendedDataInput
return ExtendedIOUtil.readObject(input);
}
+ public Object readObject(ClassLoader classLoader) throws IOException
+ {
+ return ExtendedIOUtil.readObject(input, classLoader);
+ }
+
+ public Object readObject(ClassResolver classResolver) throws IOException
+ {
+ return ExtendedIOUtil.readObject(input, classResolver);
+ }
+
public String readString() throws IOException
{
return ExtendedIOUtil.readString(input);
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java
index a73914f..d5a2dd5 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.net4j.util.io;
+import org.eclipse.net4j.util.io.ExtendedIOUtil.ClassResolver;
+
import java.io.DataInput;
import java.io.IOException;
@@ -22,5 +24,9 @@ public interface ExtendedDataInput extends DataInput
public Object readObject() throws IOException;
+ public Object readObject(ClassLoader classLoader) throws IOException;
+
+ public Object readObject(ClassResolver classResolver) throws IOException;
+
public String readString() throws IOException;
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInputStream.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInputStream.java
index 373e1df..e87a579 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInputStream.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInputStream.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.net4j.util.io;
+import org.eclipse.net4j.util.io.ExtendedIOUtil.ClassResolver;
+
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -39,6 +41,16 @@ public class ExtendedDataInputStream extends DataInputStream implements Extended
return ExtendedIOUtil.readObject(this);
}
+ public Object readObject(ClassLoader classLoader) throws IOException
+ {
+ return ExtendedIOUtil.readObject(this, classLoader);
+ }
+
+ public Object readObject(ClassResolver classResolver) throws IOException
+ {
+ return ExtendedIOUtil.readObject(this, classResolver);
+ }
+
public static ExtendedDataInputStream wrap(InputStream stream)
{
if (stream instanceof ExtendedDataInputStream)
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedIOUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedIOUtil.java
index 890887a..972fc8d 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedIOUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedIOUtil.java
@@ -21,6 +21,7 @@ import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
import java.io.OutputStream;
/**
@@ -119,6 +120,16 @@ public final class ExtendedIOUtil
public static Object readObject(final DataInput in) throws IOException
{
+ return readObject(in, (ClassResolver)null);
+ }
+
+ public static Object readObject(final DataInput in, ClassLoader classLoader) throws IOException
+ {
+ return readObject(in, new ClassLoaderClassResolver(classLoader));
+ }
+
+ public static Object readObject(final DataInput in, final ClassResolver classResolver) throws IOException
+ {
ObjectInput wrapper = null;
if (in instanceof ObjectInput)
{
@@ -133,7 +144,23 @@ public final class ExtendedIOUtil
{
return in.readByte() - Byte.MIN_VALUE;
}
- });
+ })
+ {
+ @Override
+ protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException
+ {
+ if (classResolver != null)
+ {
+ Class<?> c = classResolver.resolveClass(desc);
+ if (c != null)
+ {
+ return c;
+ }
+ }
+
+ return super.resolveClass(desc);
+ }
+ };
}
try
@@ -165,4 +192,40 @@ public final class ExtendedIOUtil
return builder.toString();
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public interface ClassResolver
+ {
+ public Class<?> resolveClass(ObjectStreamClass v) throws ClassNotFoundException;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class ClassLoaderClassResolver implements ClassResolver
+ {
+ private ClassLoader classLoader;
+
+ public ClassLoaderClassResolver(ClassLoader classLoader)
+ {
+ this.classLoader = classLoader;
+ }
+
+ public Class<?> resolveClass(ObjectStreamClass v) throws ClassNotFoundException
+ {
+ String className = v.getName();
+
+ try
+ {
+ return classLoader.loadClass(className);
+ }
+ catch (ClassNotFoundException ex)
+ {
+ OM.LOG.error(ex);
+ return null;
+ }
+ }
+ }
}