summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-02-25 04:29:10 (EST)
committerEike Stepper2008-02-25 04:29:10 (EST)
commit6cb3860fbd7e656662fa1680d20eecf280abd9c8 (patch)
tree0daf32b06f48167d3d49e3b604ed397fe4f6cb37
parent82b35c4aa3d73f6c40a2770f3621e35ab72ab3b0 (diff)
downloadcdo-6cb3860fbd7e656662fa1680d20eecf280abd9c8.zip
cdo-6cb3860fbd7e656662fa1680d20eecf280abd9c8.tar.gz
cdo-6cb3860fbd7e656662fa1680d20eecf280abd9c8.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.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/CDOIDHibernateImpl.java42
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/DataInputExtender.java5
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/DataOutputExtender.java5
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInput.java2
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataInputStream.java6
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java2
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutputStream.java4
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedIOUtil.java61
8 files changed, 112 insertions, 15 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/CDOIDHibernateImpl.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/CDOIDHibernateImpl.java
index dddf437..f4087d8 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/CDOIDHibernateImpl.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/CDOIDHibernateImpl.java
@@ -15,8 +15,11 @@ import org.eclipse.emf.cdo.internal.protocol.id.AbstractCDOID;
import org.eclipse.emf.cdo.protocol.id.CDOIDObject;
import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.server.hibernate.CDOIDHibernate;
+import org.eclipse.emf.cdo.server.internal.hibernate.bundle.OM;
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.HexUtil;
+import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.io.ExtendedDataInput;
import org.eclipse.net4j.util.io.ExtendedDataOutput;
import org.eclipse.net4j.util.io.IOUtil;
@@ -34,6 +37,8 @@ import java.io.Serializable;
*/
public class CDOIDHibernateImpl extends AbstractCDOID implements CDOIDHibernate
{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDOIDHibernateImpl.class);
+
private static final long serialVersionUID = 1L;
private Serializable id;
@@ -95,6 +100,18 @@ public class CDOIDHibernateImpl extends AbstractCDOID implements CDOIDHibernate
public void read(ExtendedDataInput in) throws IOException
{
+ // id = (Serializable)in.readObject();
+ // if (TRACER.isEnabled())
+ // {
+ // TRACER.format("Read id={0}", id);
+ // }
+ //
+ // entityName = in.readString();
+ // if (TRACER.isEnabled())
+ // {
+ // TRACER.format("Read entityName={0}", entityName);
+ // }
+
final byte[] content = in.readByteArray();
System.out.println("Read CONTENT: " + HexUtil.bytesToHex(content));
setContent(content);
@@ -102,6 +119,19 @@ public class CDOIDHibernateImpl extends AbstractCDOID implements CDOIDHibernate
public void write(ExtendedDataOutput out) throws IOException
{
+ // if (TRACER.isEnabled())
+ // {
+ // TRACER.format("Writing id={0}", id);
+ // }
+ //
+ // out.writeObject(id);
+ // if (TRACER.isEnabled())
+ // {
+ // TRACER.format("Writing entityName={0}", entityName);
+ // }
+ //
+ // out.writeString(entityName);
+
byte[] content = getContent();
System.out.println("Write CONTENT: " + HexUtil.bytesToHex(content));
out.writeByteArray(content);
@@ -122,9 +152,9 @@ public class CDOIDHibernateImpl extends AbstractCDOID implements CDOIDHibernate
oos.writeObject(content);
return bos.toByteArray();
}
- catch (IOException e)
+ catch (Exception ex)
{
- throw new IllegalStateException(e);
+ throw WrappedException.wrap(ex);
}
finally
{
@@ -143,13 +173,9 @@ public class CDOIDHibernateImpl extends AbstractCDOID implements CDOIDHibernate
setId(contentObject.getId());
setEntityName(contentObject.getEntityName());
}
- catch (ClassNotFoundException e)
- {
- throw new IllegalArgumentException(e);
- }
- catch (IOException e)
+ catch (Exception ex)
{
- throw new IllegalStateException(e);
+ throw WrappedException.wrap(ex);
}
finally
{
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 af354ef..9865f69 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
@@ -100,6 +100,11 @@ public class DataInputExtender implements ExtendedDataInput
return ExtendedIOUtil.readByteArray(input);
}
+ public Object readObject() throws IOException
+ {
+ return ExtendedIOUtil.readObject(input);
+ }
+
public String readString() throws IOException
{
return ExtendedIOUtil.readString(input);
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/DataOutputExtender.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/DataOutputExtender.java
index 85ac11b..c0696bc 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/DataOutputExtender.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/DataOutputExtender.java
@@ -100,6 +100,11 @@ public class DataOutputExtender implements ExtendedDataOutput
ExtendedIOUtil.writeByteArray(output, b);
}
+ public void writeObject(Object object) throws IOException
+ {
+ ExtendedIOUtil.writeObject(output, object);
+ }
+
public void writeString(String str) throws IOException
{
ExtendedIOUtil.writeString(output, str);
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 3de2078..a73914f 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
@@ -20,5 +20,7 @@ public interface ExtendedDataInput extends DataInput
{
public byte[] readByteArray() throws IOException;
+ public Object readObject() 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 97ffedc..373e1df 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
@@ -13,7 +13,6 @@ package org.eclipse.net4j.util.io;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
/**
* @author Eike Stepper
@@ -35,10 +34,9 @@ public class ExtendedDataInputStream extends DataInputStream implements Extended
return ExtendedIOUtil.readString(this);
}
- public Object readObject() throws IOException, ClassNotFoundException
+ public Object readObject() throws IOException
{
- ObjectInputStream wrapper = new ObjectInputStream(this);
- return wrapper.readObject();
+ return ExtendedIOUtil.readObject(this);
}
public static ExtendedDataInputStream wrap(InputStream stream)
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java
index 2bf42b2..a11b10b 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutput.java
@@ -20,5 +20,7 @@ public interface ExtendedDataOutput extends DataOutput
{
public void writeByteArray(byte[] b) throws IOException;
+ public void writeObject(Object object) throws IOException;
+
public void writeString(String str) throws IOException;
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutputStream.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutputStream.java
index 3b1f20f..f304f10 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutputStream.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ExtendedDataOutputStream.java
@@ -12,7 +12,6 @@ package org.eclipse.net4j.util.io;
import java.io.DataOutputStream;
import java.io.IOException;
-import java.io.ObjectOutputStream;
import java.io.OutputStream;
/**
@@ -37,8 +36,7 @@ public class ExtendedDataOutputStream extends DataOutputStream implements Extend
public void writeObject(Object object) throws IOException
{
- ObjectOutputStream wrapper = new ObjectOutputStream(this);
- wrapper.writeObject(object);
+ ExtendedIOUtil.writeObject(this, object);
}
public static ExtendedDataOutputStream wrap(OutputStream stream)
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 52d51dd..7aa35c7 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
@@ -10,9 +10,18 @@
**************************************************************************/
package org.eclipse.net4j.util.io;
+import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.util.WrappedException;
+
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
/**
* @author Eike Stepper
@@ -44,6 +53,28 @@ public final class ExtendedIOUtil
}
}
+ public static void writeObject(final DataOutput out, Object object) throws IOException
+ {
+ ObjectOutput wrapper = null;
+ if (out instanceof ObjectOutput)
+ {
+ wrapper = (ObjectOutput)out;
+ }
+ else
+ {
+ wrapper = new ObjectOutputStream(new OutputStream()
+ {
+ @Override
+ public void write(int b) throws IOException
+ {
+ out.writeByte(b & 0xff);
+ }
+ });
+ }
+
+ wrapper.writeObject(object);
+ }
+
public static void writeString(DataOutput out, String str) throws IOException
{
if (str != null)
@@ -86,6 +117,36 @@ public final class ExtendedIOUtil
return b;
}
+ public static Object readObject(final DataInput in) throws IOException
+ {
+ ObjectInput wrapper = null;
+ if (in instanceof ObjectInput)
+ {
+ wrapper = (ObjectInput)in;
+ }
+ else
+ {
+ wrapper = new ObjectInputStream(new InputStream()
+ {
+ @Override
+ public int read() throws IOException
+ {
+ return in.readByte() - Byte.MIN_VALUE;
+ }
+ });
+ }
+
+ try
+ {
+ return wrapper.readObject();
+ }
+ catch (ClassNotFoundException ex)
+ {
+ OM.LOG.error(ex);
+ throw WrappedException.wrap(ex);
+ }
+ }
+
public static String readString(DataInput in) throws IOException
{
boolean more = in.readBoolean();