Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/lob/CDOLobHandler.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java19
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreAccessor.java48
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java42
-rw-r--r--plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/ObjectivityStoreAccessor.java45
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerExporter.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerImporter.java360
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreAccessor.java392
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BackupTest.java40
-rw-r--r--plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java2
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/HexUtil.java6
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/AsyncOutputStream.java74
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/AsyncWriter.java74
17 files changed, 685 insertions, 446 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/lob/CDOLobHandler.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/lob/CDOLobHandler.java
index db684e4bb0..ee80a6ebf9 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/lob/CDOLobHandler.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/lob/CDOLobHandler.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.emf.cdo.common.model.lob;
+import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
@@ -27,7 +28,7 @@ public interface CDOLobHandler
* {@link OutputStream stream} that the blob content will be written to by the caller of this method, or
* <code>null</code> to indicate that the content is not needed.
*/
- public OutputStream handleBlob(byte[] id, long size);
+ public OutputStream handleBlob(byte[] id, long size) throws IOException;
/**
* A callback method for handling a {@link CDOClob character large object}. The {@link CDOLob#getID() ID} and
@@ -35,5 +36,5 @@ public interface CDOLobHandler
* writer} that the blob content will be written to by the caller of this method, or <code>null</code> to indicate
* that the content is not needed.
*/
- public Writer handleClob(byte[] id, long size);
+ public Writer handleClob(byte[] id, long size) throws IOException;
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
index 41eec5e892..f4df911962 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
@@ -17,7 +17,7 @@ import java.sql.Connection;
/**
* @author Eike Stepper
*/
-public interface IDBStoreAccessor extends IStoreAccessor
+public interface IDBStoreAccessor extends IStoreAccessor.Raw
{
public IDBStore getStore();
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
index c9f361f2e8..22832c865d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
@@ -23,7 +23,6 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
-import org.eclipse.emf.cdo.common.model.lob.CDOLob;
import org.eclipse.emf.cdo.common.model.lob.CDOLobHandler;
import org.eclipse.emf.cdo.common.protocol.CDODataInput;
import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
@@ -452,12 +451,6 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
}
- public Object rawStore(CDOLob<?> lob, Object context, OMMonitor monitor)
- {
- // TODO: implement DBStoreAccessor.rawStore(lob, context, monitor)
- throw new UnsupportedOperationException();
- }
-
@Override
protected void applyIDMappings(InternalCommitContext context, OMMonitor monitor)
{
@@ -1165,6 +1158,18 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return context;
}
+ public Object rawStore(byte[] id, long size, InputStream inputStream, Object context) throws IOException
+ {
+ writeBlob(id, size, inputStream);
+ return context;
+ }
+
+ public Object rawStore(byte[] id, long size, Reader reader, Object context) throws IOException
+ {
+ writeClob(id, size, reader);
+ return context;
+ }
+
public void rawCommit(Object context, OMMonitor monitor)
{
Async async = monitor.forkAsync();
diff --git a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreAccessor.java
index f8d2c5e404..2976912d2b 100644
--- a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreAccessor.java
@@ -17,10 +17,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
-import org.eclipse.emf.cdo.common.model.lob.CDOLob;
import org.eclipse.emf.cdo.common.model.lob.CDOLobHandler;
-import org.eclipse.emf.cdo.common.protocol.CDODataInput;
-import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionCacheAdder;
import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
@@ -373,51 +370,6 @@ public class DB4OStoreAccessor extends LongIDStoreAccessor
}
}
- public void rawExport(CDODataOutput out, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime)
- throws IOException
- {
- // TODO: implement DB4OStoreAccessor.rawExport(out, fromBranchID, toBranchID, fromCommitTime, toCommitTime)
- throw new UnsupportedOperationException();
- }
-
- public void rawImport(CDODataInput in, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime)
- throws IOException
- {
- // TODO: implement DB4OStoreAccessor.rawImport(in, fromBranchID, toBranchID, fromCommitTime, toCommitTime)
- throw new UnsupportedOperationException();
- }
-
- public void rawImport(CDODataInput in, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime,
- OMMonitor monitor) throws IOException
- {
- // TODO: implement DB4OStoreAccessor.rawImport(in, fromBranchID, toBranchID, fromCommitTime, toCommitTime, monitor)
- throw new UnsupportedOperationException();
- }
-
- public Object rawStore(InternalCDOPackageUnit[] packageUnits, Object context, OMMonitor monitor)
- {
- // TODO: implement DB4OStoreAccessor.rawStore(packageUnits, context, monitor)
- throw new UnsupportedOperationException();
- }
-
- public Object rawStore(InternalCDORevision revision, Object context, OMMonitor monitor)
- {
- // TODO: implement DB4OStoreAccessor.rawStore(revision, context, monitor)
- throw new UnsupportedOperationException();
- }
-
- public Object rawStore(CDOLob<?> lob, Object context, OMMonitor monitor)
- {
- // TODO: implement DB4OStoreAccessor.rawStore(lob, context, monitor)
- throw new UnsupportedOperationException();
- }
-
- public void rawCommit(Object context, OMMonitor monitor)
- {
- // TODO: implement DB4OStoreAccessor.rawCommit(context, monitor)
- throw new UnsupportedOperationException();
- }
-
public void queryLobs(List<byte[]> ids)
{
for (Iterator<byte[]> it = ids.iterator(); it.hasNext();)
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
index 5760c31889..c0697b0173 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStoreAccessor.java
@@ -20,10 +20,7 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDTemp;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
-import org.eclipse.emf.cdo.common.model.lob.CDOLob;
import org.eclipse.emf.cdo.common.model.lob.CDOLobHandler;
-import org.eclipse.emf.cdo.common.protocol.CDODataInput;
-import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionCacheAdder;
import org.eclipse.emf.cdo.common.revision.CDORevisionData;
@@ -809,45 +806,6 @@ public class HibernateStoreAccessor extends StoreAccessor implements IHibernateS
throw new UnsupportedOperationException();
}
- public void rawExport(CDODataOutput out, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime)
- throws IOException
- {
- // TODO: implement HibernateStoreAccessor.rawExport(out, fromBranchID, toBranchID, fromCommitTime, toCommitTime)
- throw new UnsupportedOperationException();
- }
-
- public void rawImport(CDODataInput in, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime,
- OMMonitor monitor) throws IOException
- {
- // TODO: implement HibernateStoreAccessor.rawImport(in, fromBranchID, toBranchID, fromCommitTime, toCommitTime,
- // monitor)
- throw new UnsupportedOperationException();
- }
-
- public Object rawStore(InternalCDOPackageUnit[] packageUnits, Object context, OMMonitor monitor)
- {
- // TODO: implement HibernateStoreAccessor.rawStore(packageUnits, context, monitor)
- throw new UnsupportedOperationException();
- }
-
- public Object rawStore(InternalCDORevision revision, Object context, OMMonitor monitor)
- {
- // TODO: implement HibernateStoreAccessor.rawStore(revision, context, monitor)
- throw new UnsupportedOperationException();
- }
-
- public Object rawStore(CDOLob<?> lob, Object context, OMMonitor monitor)
- {
- // TODO: implement HibernateStoreAccessor.rawStore(lob, context, monitor)
- throw new UnsupportedOperationException();
- }
-
- public void rawCommit(Object context, OMMonitor monitor)
- {
- // TODO: implement HibernateStoreAccessor.rawCommit(context, monitor)
- throw new UnsupportedOperationException();
- }
-
public void queryLobs(List<byte[]> ids)
{
for (Iterator<byte[]> it = ids.iterator(); it.hasNext();)
diff --git a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/ObjectivityStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/ObjectivityStoreAccessor.java
index 5b41b4db98..5afba195dc 100644
--- a/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/ObjectivityStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.objectivity/src/org/eclipse/emf/cdo/server/internal/objectivity/ObjectivityStoreAccessor.java
@@ -22,10 +22,7 @@ import org.eclipse.emf.cdo.common.id.CDOIDMeta;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.common.model.EMFUtil;
-import org.eclipse.emf.cdo.common.model.lob.CDOLob;
import org.eclipse.emf.cdo.common.model.lob.CDOLobHandler;
-import org.eclipse.emf.cdo.common.protocol.CDODataInput;
-import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionCacheAdder;
import org.eclipse.emf.cdo.common.revision.CDORevisionHandler;
@@ -1229,48 +1226,6 @@ public class ObjectivityStoreAccessor extends StoreAccessor implements IObjectiv
return results;
}
- public void rawExport(CDODataOutput out, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime)
- throws IOException
- {
- // TODO: implement ObjectivityStoreAccessor.rawExport(out, fromBranchID, toBranchID, fromCommitTime, toCommitTime)
- throw new UnsupportedOperationException();
- }
-
- /**
- * @since 4.0
- */
- public void rawImport(CDODataInput in, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime,
- OMMonitor monitor) throws IOException
- {
- // TODO: implement ObjectivityStoreAccessor.rawImport(in, fromBranchID, toBranchID, fromCommitTime, toCommitTime,
- // monitor)
- throw new UnsupportedOperationException();
- }
-
- public Object rawStore(InternalCDOPackageUnit[] packageUnits, Object context, OMMonitor monitor)
- {
- // TODO: implement ObjectivityStoreAccessor.rawStore(packageUnits, context, monitor)
- throw new UnsupportedOperationException();
- }
-
- public Object rawStore(InternalCDORevision revision, Object context, OMMonitor monitor)
- {
- // TODO: implement ObjectivityStoreAccessor.rawStore(revision, context, monitor)
- throw new UnsupportedOperationException();
- }
-
- public Object rawStore(CDOLob<?> lob, Object context, OMMonitor monitor)
- {
- // TODO: implement ObjectivityStoreAccessor.rawStore(lob, context, monitor)
- throw new UnsupportedOperationException();
- }
-
- public void rawCommit(Object context, OMMonitor monitor)
- {
- // TODO: implement ObjectivityStoreAccessor.rawCommit(context, monitor)
- throw new UnsupportedOperationException();
- }
-
public void queryLobs(List<byte[]> ids)
{
// TODO: implement ObjectivityStoreAccessor.queryLobs(ids)
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
index 2f027d1a2d..80dd76bb39 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
@@ -1051,7 +1051,7 @@ public class Repository extends Container<Object> implements InternalRepository
out.writeInt(toBranchID);
out.writeLong(toCommitTime);
- IStoreAccessor accessor = StoreThreadLocal.getAccessor();
+ IStoreAccessor.Raw accessor = (IStoreAccessor.Raw)StoreThreadLocal.getAccessor();
accessor.rawExport(out, fromBranchID, toBranchID, fromCommitTime, toCommitTime);
return new CDOReplicationInfo()
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java
index faeaee78f7..8e9793d742 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStoreAccessor.java
@@ -18,7 +18,6 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler;
import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.model.lob.CDOLob;
import org.eclipse.emf.cdo.common.model.lob.CDOLobHandler;
import org.eclipse.emf.cdo.common.protocol.CDODataInput;
import org.eclipse.emf.cdo.common.protocol.CDODataOutput;
@@ -28,6 +27,7 @@ import org.eclipse.emf.cdo.common.util.CDOQueryInfo;
import org.eclipse.emf.cdo.server.IQueryContext;
import org.eclipse.emf.cdo.server.IQueryHandler;
import org.eclipse.emf.cdo.server.ISession;
+import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.spi.common.commit.CDOChangeSetSegment;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
@@ -58,7 +58,7 @@ import java.util.Set;
/**
* @author Simon McDuff
*/
-public class MEMStoreAccessor extends LongIDStoreAccessor
+public class MEMStoreAccessor extends LongIDStoreAccessor implements IStoreAccessor.Raw
{
private final IQueryHandler testQueryHandler = new IQueryHandler()
{
@@ -384,10 +384,16 @@ public class MEMStoreAccessor extends LongIDStoreAccessor
return rawStoreContext;
}
- public Object rawStore(CDOLob<?> lob, Object context, OMMonitor monitor)
+ public Object rawStore(byte[] id, long size, InputStream inputStream, Object context) throws IOException
{
- // TODO: implement MEMStoreAccessor.rawStore(lob, context, monitor)
- throw new UnsupportedOperationException();
+ writeBlob(id, size, inputStream);
+ return context;
+ }
+
+ public Object rawStore(byte[] id, long size, Reader reader, Object context) throws IOException
+ {
+ writeClob(id, size, reader);
+ return context;
}
public void rawCommit(Object context, OMMonitor monitor)
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java
index 72d23fb48a..c879c6d1e9 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java
@@ -237,7 +237,7 @@ public abstract class SynchronizableRepository extends Repository.Default implem
long toCommitTime = in.readLong();
StoreThreadLocal.setSession(replicatorSession);
- IStoreAccessor accessor = StoreThreadLocal.getAccessor();
+ IStoreAccessor.Raw accessor = (IStoreAccessor.Raw)StoreThreadLocal.getAccessor();
accessor.rawImport(in, fromBranchID, toBranchID, fromCommitTime, toCommitTime, monitor);
replicateRawReviseRevisions();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerExporter.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerExporter.java
index eafeb5b1b0..1b59184d32 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerExporter.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerExporter.java
@@ -564,7 +564,7 @@ public abstract class CDOServerExporter<OUT>
@Override
protected Writer startClob(XMLOutput out, byte[] id, long size) throws Exception
{
- out.element(BLOB);
+ out.element(CLOB);
out.attribute(LOB_ID, HexUtil.bytesToHex(id));
out.attribute(LOB_SIZE, size);
return out.characters();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerImporter.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerImporter.java
index 21cac996b7..e3136827fd 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerImporter.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/CDOServerImporter.java
@@ -21,6 +21,7 @@ import org.eclipse.emf.cdo.common.model.CDOModelUtil;
import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
import org.eclipse.emf.cdo.common.model.CDOPackageUnit.Type;
import org.eclipse.emf.cdo.common.model.EMFUtil;
+import org.eclipse.emf.cdo.common.model.lob.CDOLobHandler;
import org.eclipse.emf.cdo.common.model.lob.CDOLobUtil;
import org.eclipse.emf.cdo.common.revision.CDOList;
import org.eclipse.emf.cdo.common.revision.CDORevision;
@@ -38,6 +39,10 @@ import org.eclipse.emf.cdo.spi.server.InternalSession;
import org.eclipse.net4j.util.CheckUtil;
import org.eclipse.net4j.util.HexUtil;
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.io.AsyncOutputStream;
+import org.eclipse.net4j.util.io.AsyncWriter;
+import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.monitor.Monitor;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
@@ -54,7 +59,11 @@ import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
@@ -86,165 +95,193 @@ public abstract class CDOServerImporter
public void importRepository(InputStream in) throws Exception
{
- class FlushHandler implements Handler
+ try
+ {
+ FlushHandler handler = new FlushHandler();
+ importAll(in, handler);
+ handler.flush();
+ }
+ finally
{
- private IStoreAccessor accessor = repository.getStore().getWriter(null);
+ StoreThreadLocal.release();
+ repository = null;
+ }
+ }
- private OMMonitor monitor = new Monitor();
+ protected abstract void importAll(InputStream in, Handler handler) throws Exception;
- private Object context;
+ /**
+ * @author Eike Stepper
+ */
+ public static interface Handler extends CDORevisionHandler, CDOLobHandler, CDOCommitInfoHandler
+ {
+ public void handleRepository(String name, String uuid, CDOID root, long created, long committed);
- private Map<String, String> models = new HashMap<String, String>();
+ public InternalCDOPackageUnit handlePackageUnit(String id, Type type, long time, String data);
- private LinkedList<InternalCDOPackageUnit> packageUnits = new LinkedList<InternalCDOPackageUnit>();
+ public InternalCDOPackageInfo handlePackageInfo(String packageURI, CDOIDMetaRange metaIDRange);
- private List<InternalCDOPackageInfo> packageInfos;
+ public InternalCDOPackageRegistry handleModels();
- private InternalCDOPackageRegistry packageRegistry = getRepository().getPackageRegistry(false);
+ public InternalCDOBranch handleBranch(int id, String name, long time, int parentID);
- public FlushHandler()
- {
- }
+ public void flush();
- public void handleRepository(String name, String uuid, CDOID root, long created, long committed)
- {
- // lastCommitTimeStamp = Math.max(store.getCreationTime(), store.getLastCommitTime());
- InternalCDOBranchManager branchManager = repository.getBranchManager();
- repository.initMainBranch(branchManager, created);
- LifecycleUtil.activate(branchManager);
+ }
- repository.initSystemPackages();
- repository.setRootResourceID(root);
+ /**
+ * @author Eike Stepper
+ */
+ private final class FlushHandler implements Handler
+ {
+ private OMMonitor monitor = new Monitor();
- InternalSession session = repository.getSessionManager().openSession(null);
- StoreThreadLocal.setSession(session);
- }
+ private IStoreAccessor.Raw accessor;
- public InternalCDOPackageUnit handlePackageUnit(String id, Type type, long time, String data)
- {
- collectPackageInfos();
+ private Object context;
- InternalCDOPackageUnit packageUnit = packageRegistry.createPackageUnit();
- packageUnit.setOriginalType(type);
- packageUnit.setTimeStamp(time);
+ private Map<String, String> models = new HashMap<String, String>();
- models.put(id, data);
- packageUnits.add(packageUnit);
- packageInfos = new ArrayList<InternalCDOPackageInfo>();
- return packageUnit;
- }
+ private LinkedList<InternalCDOPackageUnit> packageUnits = new LinkedList<InternalCDOPackageUnit>();
- public InternalCDOPackageInfo handlePackageInfo(String packageURI, CDOIDMetaRange metaIDRange)
- {
- InternalCDOPackageInfo packageInfo = (InternalCDOPackageInfo)CDOModelUtil.createPackageInfo();
- packageInfo.setPackageURI(packageURI);
- packageInfo.setMetaIDRange(metaIDRange);
- packageInfos.add(packageInfo);
- return packageInfo;
- }
+ private List<InternalCDOPackageInfo> packageInfos;
- public InternalCDOPackageRegistry handleModels()
- {
- collectPackageInfos();
- InternalCDOPackageUnit[] array = packageUnits.toArray(new InternalCDOPackageUnit[packageUnits.size()]);
- packageUnits = null;
+ private InternalCDOPackageRegistry packageRegistry = getRepository().getPackageRegistry(false);
- PackageLoader loader = new PackageLoader()
- {
- private ResourceSet resourceSet = EMFUtil.newEcoreResourceSet(packageRegistry);
+ public FlushHandler()
+ {
+ accessor = (IStoreAccessor.Raw)repository.getStore().getWriter(null);
+ }
- public EPackage[] loadPackages(CDOPackageUnit packageUnit)
- {
- String id = packageUnit.getID();
- String data = models.get(id);
+ public void handleRepository(String name, String uuid, CDOID root, long created, long committed)
+ {
+ // lastCommitTimeStamp = Math.max(store.getCreationTime(), store.getLastCommitTime());
+ InternalCDOBranchManager branchManager = repository.getBranchManager();
+ repository.initMainBranch(branchManager, created);
+ LifecycleUtil.activate(branchManager);
- EPackage ePackage = EMFUtil.createEPackage(id, data.getBytes(), false, resourceSet, true);
- return EMFUtil.getAllPackages(ePackage);
- }
- };
+ repository.initSystemPackages();
+ repository.setRootResourceID(root);
- packageRegistry.putPackageUnits(array, CDOPackageUnit.State.PROXY);
- for (InternalCDOPackageUnit packageUnit : array)
- {
- packageUnit.load(loader);
- }
+ InternalSession session = repository.getSessionManager().openSession(null);
+ StoreThreadLocal.setSession(session);
+ }
- context = accessor.rawStore(array, context, monitor);
+ public InternalCDOPackageUnit handlePackageUnit(String id, Type type, long time, String data)
+ {
+ collectPackageInfos();
- return packageRegistry;
- }
+ InternalCDOPackageUnit packageUnit = packageRegistry.createPackageUnit();
+ packageUnit.setOriginalType(type);
+ packageUnit.setTimeStamp(time);
+
+ models.put(id, data);
+ packageUnits.add(packageUnit);
+ packageInfos = new ArrayList<InternalCDOPackageInfo>();
+ return packageUnit;
+ }
- public InternalCDOBranch handleBranch(int id, String name, long time, int parentID)
+ public InternalCDOPackageInfo handlePackageInfo(String packageURI, CDOIDMetaRange metaIDRange)
+ {
+ InternalCDOPackageInfo packageInfo = (InternalCDOPackageInfo)CDOModelUtil.createPackageInfo();
+ packageInfo.setPackageURI(packageURI);
+ packageInfo.setMetaIDRange(metaIDRange);
+ packageInfos.add(packageInfo);
+ return packageInfo;
+ }
+
+ public InternalCDOPackageRegistry handleModels()
+ {
+ collectPackageInfos();
+ InternalCDOPackageUnit[] array = packageUnits.toArray(new InternalCDOPackageUnit[packageUnits.size()]);
+ packageUnits = null;
+
+ PackageLoader loader = new PackageLoader()
{
- InternalCDOBranchManager branchManager = repository.getBranchManager();
- if (id == CDOBranch.MAIN_BRANCH_ID)
+ private ResourceSet resourceSet = EMFUtil.newEcoreResourceSet(packageRegistry);
+
+ public EPackage[] loadPackages(CDOPackageUnit packageUnit)
{
- return branchManager.getMainBranch();
- }
+ String id = packageUnit.getID();
+ String data = models.get(id);
- InternalCDOBranch parent = branchManager.getBranch(parentID);
- return branchManager.createBranch(id, name, parent, time);
- }
+ EPackage ePackage = EMFUtil.createEPackage(id, data.getBytes(), false, resourceSet, true);
+ return EMFUtil.getAllPackages(ePackage);
+ }
+ };
- public boolean handleRevision(CDORevision revision)
+ packageRegistry.putPackageUnits(array, CDOPackageUnit.State.PROXY);
+ for (InternalCDOPackageUnit packageUnit : array)
{
- context = accessor.rawStore((InternalCDORevision)revision, context, monitor);
- return true;
+ packageUnit.load(loader);
}
- public void handleCommitInfo(CDOCommitInfo commitInfo)
- {
- }
+ context = accessor.rawStore(array, context, monitor);
- public void flush()
+ return packageRegistry;
+ }
+
+ public InternalCDOBranch handleBranch(int id, String name, long time, int parentID)
+ {
+ InternalCDOBranchManager branchManager = repository.getBranchManager();
+ if (id == CDOBranch.MAIN_BRANCH_ID)
{
- accessor.rawCommit(context, monitor);
- context = null;
+ return branchManager.getMainBranch();
}
- private void collectPackageInfos()
+ InternalCDOBranch parent = branchManager.getBranch(parentID);
+ return branchManager.createBranch(id, name, parent, time);
+ }
+
+ public boolean handleRevision(CDORevision revision)
+ {
+ context = accessor.rawStore((InternalCDORevision)revision, context, monitor);
+ return true;
+ }
+
+ public OutputStream handleBlob(final byte[] id, final long size) throws IOException
+ {
+ return new AsyncOutputStream()
{
- if (packageInfos != null)
+ @Override
+ protected void asyncWrite(InputStream in) throws IOException
{
- InternalCDOPackageUnit packageUnit = packageUnits.getLast();
- packageUnit.setPackageInfos(packageInfos.toArray(new InternalCDOPackageInfo[packageInfos.size()]));
- packageInfos = null;
+ accessor.rawStore(id, size, in, context);
}
- }
+ };
}
- try
+ public Writer handleClob(final byte[] id, final long size) throws IOException
{
- FlushHandler handler = new FlushHandler();
- importAll(in, handler);
- handler.flush();
+ return new AsyncWriter()
+ {
+ @Override
+ protected void asyncWrite(Reader in) throws IOException
+ {
+ accessor.rawStore(id, size, in, context);
+ }
+ };
}
- finally
+
+ public void handleCommitInfo(CDOCommitInfo commitInfo)
{
- StoreThreadLocal.release();
- repository = null;
}
- }
-
- protected abstract void importAll(InputStream in, Handler handler) throws Exception;
-
- /**
- * @author Eike Stepper
- */
- public static interface Handler extends CDORevisionHandler, CDOCommitInfoHandler
- {
- public void handleRepository(String name, String uuid, CDOID root, long created, long committed);
- public InternalCDOPackageUnit handlePackageUnit(String id, Type type, long time, String data);
-
- public InternalCDOPackageInfo handlePackageInfo(String packageURI, CDOIDMetaRange metaIDRange);
-
- public InternalCDOPackageRegistry handleModels();
-
- public InternalCDOBranch handleBranch(int id, String name, long time, int parentID);
-
- public void flush();
+ public void flush()
+ {
+ accessor.rawCommit(context, monitor);
+ context = null;
+ }
+ private void collectPackageInfos()
+ {
+ if (packageInfos != null)
+ {
+ InternalCDOPackageUnit packageUnit = packageUnits.getLast();
+ packageUnit.setPackageInfos(packageInfos.toArray(new InternalCDOPackageInfo[packageInfos.size()]));
+ packageInfos = null;
+ }
+ }
}
/**
@@ -268,6 +305,12 @@ public abstract class CDOServerImporter
private InternalCDORevision revision;
+ private Character blobChar;
+
+ private OutputStream blob;
+
+ private Writer clob;
+
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
{
@@ -362,6 +405,85 @@ public abstract class CDOServerImporter
}
}
}
+ else if (BLOB.equals(qName))
+ {
+ try
+ {
+ byte[] id = HexUtil.hexToBytes(attributes.getValue(LOB_ID));
+ long size = Long.parseLong(attributes.getValue(LOB_SIZE));
+ blob = handler.handleBlob(id, size);
+ }
+ catch (IOException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+ else if (CLOB.equals(qName))
+ {
+ try
+ {
+ byte[] id = HexUtil.hexToBytes(attributes.getValue(LOB_ID));
+ long size = Long.parseLong(attributes.getValue(LOB_SIZE));
+ clob = handler.handleClob(id, size);
+ }
+ catch (IOException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException
+ {
+ if (blob != null)
+ {
+ try
+ {
+ if (blobChar != null)
+ {
+ char[] firstChars = { blobChar, ch[start] };
+ blobChar = null;
+
+ byte[] firstByte = HexUtil.hexToBytes(new String(firstChars));
+ blob.write(firstByte, 0, 1);
+
+ ++start;
+ --length;
+ }
+
+ if ((length & 1) == 1) // odd length?
+ {
+ --length;
+ blobChar = ch[ch.length - 1];
+ }
+
+ if (start != 0 || length != ch.length)
+ {
+ char[] tmp = new char[length];
+ System.arraycopy(ch, start, tmp, 0, length);
+ ch = tmp;
+ }
+
+ byte[] buf = HexUtil.hexToBytes(new String(ch));
+ blob.write(buf);
+ }
+ catch (IOException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+ else if (clob != null)
+ {
+ try
+ {
+ clob.write(ch, start, length);
+ }
+ catch (IOException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
}
@Override
@@ -380,6 +502,16 @@ public abstract class CDOServerImporter
handler.handleRevision(revision);
revision = null;
}
+ else if (BLOB.equals(qName))
+ {
+ IOUtil.close(blob);
+ blob = null;
+ }
+ else if (CLOB.equals(qName))
+ {
+ IOUtil.close(clob);
+ clob = null;
+ }
}
};
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreAccessor.java
index 8d223e430c..5ffc7fa5fc 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreAccessor.java
@@ -51,7 +51,9 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
+import java.io.Reader;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -252,178 +254,6 @@ public interface IStoreAccessor extends IQueryHandlerProvider, BranchLoader, Com
*/
public void rollback();
- /**
- * Serializes all backend data within the given ranges such that it can be deserialized by the
- * {@link #rawImport(CDODataInput, int, int, long, long, OMMonitor) rawImport()} method of a different instance of the
- * same implementation of {@link IStoreAccessor}.
- * <p>
- * <b>Implementation note:</b> The implementor of this method is free to choose a serialization format as it only
- * needs to be understood by different instances of the same implementation of {@link IStoreAccessor}.
- * <p>
- * <b>Usage context:</b> This method is only called in the context of a
- * {@link CDOProtocolConstants#SIGNAL_REPLICATE_REPOSITORY_RAW REPLICATE_REPOSITORY_RAW} signal that is triggered from
- * {@link IRepositorySynchronizer}.
- *
- * @param out
- * the <i>stream</i> to serialize the data to.
- * @param fromBranchID
- * the {@link CDOBranch#getID() ID} of the first branch to be exported.
- * @param toBranchID
- * the {@link CDOBranch#getID() ID} of the last branch to be exported.
- * @param fromCommitTime
- * the first {@link CDOBranchPoint#getTimeStamp() time stamp} of all non-branch data (e.g.
- * {@link CDORevision revisions}, {@link CDOCommitInfo commit infos}, {@link CDOPackageUnit package units},
- * etc...) to be exported.
- * @param toCommitTime
- * the last {@link CDOBranchPoint#getTimeStamp() time stamp} of all non-branch data (e.g. {@link CDORevision
- * revisions}, {@link CDOCommitInfo commit infos}, {@link CDOPackageUnit package units}, etc...) to be
- * exported.
- * @throws IOException
- * if the <i>stream</i> could not be written to.
- * @throws UnsupportedOperationException
- * if this {@link IStoreAccessor} does not support branching.
- * @since 3.0
- */
- public void rawExport(CDODataOutput out, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime)
- throws IOException;
-
- /**
- * Deserializes backend data that has been serialized by the {@link #rawExport(CDODataOutput, int, int, long, long)
- * rawExport()} method of a different instance of the same implementation of {@link IStoreAccessor}.
- * <p>
- * <b>Implementation note:</b> The implementor of this method is free to choose a serialization format as it only
- * needs to be understood by different instances of the same implementation of {@link IStoreAccessor}.
- * <p>
- * <b>Usage context:</b> This method is only called in the context of a
- * {@link CDOProtocolConstants#SIGNAL_REPLICATE_REPOSITORY_RAW REPLICATE_REPOSITORY_RAW} signal that is triggered from
- * {@link IRepositorySynchronizer}.
- *
- * @param in
- * the <i>stream</i> to deserialize the data from.
- * @param fromBranchID
- * the {@link CDOBranch#getID() ID} of the first branch to be imported.
- * @param toBranchID
- * the {@link CDOBranch#getID() ID} of the last branch to be imported.
- * @param fromCommitTime
- * the first {@link CDOBranchPoint#getTimeStamp() time stamp} of all non-branch data (e.g.
- * {@link CDORevision revisions}, {@link CDOCommitInfo commit infos}, {@link CDOPackageUnit package units},
- * etc...) to be imported.
- * @param toCommitTime
- * the last {@link CDOBranchPoint#getTimeStamp() time stamp} of all non-branch data (e.g. {@link CDORevision
- * revisions}, {@link CDOCommitInfo commit infos}, {@link CDOPackageUnit package units}, etc...) to be
- * imported.
- * @throws IOException
- * if the <i>stream</i> could not be read from.
- * @throws UnsupportedOperationException
- * if this {@link IStoreAccessor} does not support branching.
- * @since 4.0
- */
- public void rawImport(CDODataInput in, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime,
- OMMonitor monitor) throws IOException;
-
- /**
- * Stores the given {@link CDOPackageUnit package units} in the backend represented by this {@link IStoreAccessor}
- * without going through a regular {@link #commit(OMMonitor) commit}. A regular commit operation would assign new
- * {@link CDOPackageInfo#getMetaIDRange() meta IDs} and {@link CDOPackageUnit#getTimeStamp() time stamps}, which is
- * not desired in the context of a replication operation.
- * <p>
- * <b>Implementation note:</b> The implementor of this method may rely on the fact that multiple subsequent calls to
- * this method are followed by a single final call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method
- * where the accumulated backend changes can be committed atomically.
- *
- * @param packageUnits
- * the package units to be stored in the backend represented by this {@link IStoreAccessor}.
- * @param context
- * an object of an arbitrary class that has been created during previous calls to this method (but after the
- * last call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method. This context object may be used
- * to remember implementation specific state between calls to the rawStore() methods and the rawCommit()
- * method. Its type and value are opaque to the caller, which maintains the context object between these
- * calls. A new object may be created by the implementor of this method at any time and should be returned by
- * this method to preserve it for later calls. Can be <code>null</code>.
- * @param monitor
- * a progress monitor that <b>may be</b> used to report proper progress of this operation to the caller and
- * <b>may be</b> used to react to cancelation requests of the caller and <b>must be</b> touched regularly to
- * prevent timeouts from expiring in the caller.
- * @return the context object (see above) to be preserved by the caller of this method for later calls.
- * @since 4.0
- * @see #rawCommit(Object, OMMonitor)
- */
- public Object rawStore(InternalCDOPackageUnit[] packageUnits, Object context, OMMonitor monitor);
-
- /**
- * Stores the given {@link CDORevision revision} in the backend represented by this {@link IStoreAccessor} without
- * going through a regular {@link #commit(OMMonitor) commit}. A regular commit operation would assign new
- * {@link CDORevisionKey#getID() IDs} and {@link CDOBranchPoint#getTimeStamp() time stamps}, which is not desired in
- * the context of a replication operation.
- * <p>
- * <b>Implementation note:</b> The implementor of this method may rely on the fact that multiple subsequent calls to
- * this method are followed by a single final call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method
- * where the accumulated backend changes can be committed atomically.
- *
- * @param revision
- * the revision to be stored in the backend represented by this {@link IStoreAccessor}.
- * @param context
- * an object of an arbitrary class that has been created during previous calls to this method (but after the
- * last call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method. This context object may be used
- * to remember implementation specific state between calls to the rawStore() methods and the rawCommit()
- * method. Its type and value are opaque to the caller, which maintains the context object between these
- * calls. A new object may be created by the implementor of this method at any time and should be returned by
- * this method to preserve it for later calls. Can be <code>null</code>.
- * @param monitor
- * a progress monitor that <b>may be</b> used to report proper progress of this operation to the caller and
- * <b>may be</b> used to react to cancelation requests of the caller and <b>must be</b> touched regularly to
- * prevent timeouts from expiring in the caller.
- * @return the context object (see above) to be preserved by the caller of this method for later calls.
- * @since 4.0
- * @see #rawCommit(Object, OMMonitor)
- */
- public Object rawStore(InternalCDORevision revision, Object context, OMMonitor monitor);
-
- /**
- * Stores the given {@link CDOLob large object} in the backend represented by this {@link IStoreAccessor} without
- * going through a regular {@link #commit(OMMonitor) commit}.
- * <p>
- * <b>Implementation note:</b> The implementor of this method may rely on the fact that multiple subsequent calls to
- * this method are followed by a single final call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method
- * where the accumulated backend changes can be committed atomically.
- *
- * @param lob
- * the large object to be stored in the backend represented by this {@link IStoreAccessor}.
- * @param context
- * an object of an arbitrary class that has been created during previous calls to this method (but after the
- * last call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method. This context object may be used
- * to remember implementation specific state between calls to the rawStore() methods and the rawCommit()
- * method. Its type and value are opaque to the caller, which maintains the context object between these
- * calls. A new object may be created by the implementor of this method at any time and should be returned by
- * this method to preserve it for later calls. Can be <code>null</code>.
- * @param monitor
- * a progress monitor that <b>may be</b> used to report proper progress of this operation to the caller and
- * <b>may be</b> used to react to cancelation requests of the caller and <b>must be</b> touched regularly to
- * prevent timeouts from expiring in the caller.
- * @return the context object (see above) to be preserved by the caller of this method for later calls.
- * @since 4.0
- * @see #rawCommit(Object, OMMonitor)
- */
- public Object rawStore(CDOLob<?> lob, Object context, OMMonitor monitor);
-
- /**
- * Atomically commits the accumulated backend changes resulting from previous calls to the rawStore() methods.
- *
- * @param context
- * an object of an arbitrary class that has been created during previous calls to the rawStore() methods.
- * This context object may be used to remember implementation specific state between calls to the rawStore()
- * methods and the rawCommit() method. Its type and value are opaque to the caller, which maintains the
- * context object between these calls.Can be <code>null</code>.
- * @param monitor
- * a progress monitor that <b>may be</b> used to report proper progress of this operation to the caller and
- * <b>may be</b> used to react to cancelation requests of the caller and <b>must be</b> touched regularly to
- * prevent timeouts from expiring in the caller.
- * @since 4.0
- * @see #rawStore(InternalCDOPackageUnit[], Object, OMMonitor)
- * @see #rawStore(InternalCDORevision, Object, OMMonitor)
- */
- public void rawCommit(Object context, OMMonitor monitor);
-
public void release();
/**
@@ -630,4 +460,222 @@ public interface IStoreAccessor extends IQueryHandlerProvider, BranchLoader, Com
*/
public boolean addXRef(CDOID targetID, CDOID sourceID, EReference sourceReference, int sourceIndex);
}
+
+ /**
+ * @author Eike Stepper
+ * @since 4.0
+ */
+ public interface Raw extends IStoreAccessor
+ {
+ /**
+ * Serializes all backend data within the given ranges such that it can be deserialized by the
+ * {@link #rawImport(CDODataInput, int, int, long, long, OMMonitor) rawImport()} method of a different instance of
+ * the same implementation of {@link IStoreAccessor.Raw raw store accessor}.
+ * <p>
+ * <b>Implementation note:</b> The implementor of this method is free to choose a serialization format as it only
+ * needs to be understood by different instances of the same implementation of {@link IStoreAccessor.Raw raw store
+ * accessor}.
+ * <p>
+ * <b>Usage context:</b> This method is only called in the context of a
+ * {@link CDOProtocolConstants#SIGNAL_REPLICATE_REPOSITORY_RAW REPLICATE_REPOSITORY_RAW} signal that is triggered
+ * from {@link IRepositorySynchronizer}.
+ *
+ * @param out
+ * the <i>stream</i> to serialize the data to.
+ * @param fromBranchID
+ * the {@link CDOBranch#getID() ID} of the first branch to be exported.
+ * @param toBranchID
+ * the {@link CDOBranch#getID() ID} of the last branch to be exported.
+ * @param fromCommitTime
+ * the first {@link CDOBranchPoint#getTimeStamp() time stamp} of all non-branch data (e.g.
+ * {@link CDORevision revisions}, {@link CDOCommitInfo commit infos}, {@link CDOPackageUnit package units},
+ * etc...) to be exported.
+ * @param toCommitTime
+ * the last {@link CDOBranchPoint#getTimeStamp() time stamp} of all non-branch data (e.g.
+ * {@link CDORevision revisions}, {@link CDOCommitInfo commit infos}, {@link CDOPackageUnit package units},
+ * etc...) to be exported.
+ * @throws IOException
+ * if the <i>stream</i> could not be written to.
+ * @throws UnsupportedOperationException
+ * if this {@link IStoreAccessor.Raw raw store accessor} does not support branching.
+ * @since 3.0
+ */
+ public void rawExport(CDODataOutput out, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime)
+ throws IOException;
+
+ /**
+ * Deserializes backend data that has been serialized by the {@link #rawExport(CDODataOutput, int, int, long, long)
+ * rawExport()} method of a different instance of the same implementation of {@link IStoreAccessor.Raw raw store
+ * accessor}.
+ * <p>
+ * <b>Implementation note:</b> The implementor of this method is free to choose a serialization format as it only
+ * needs to be understood by different instances of the same implementation of {@link IStoreAccessor.Raw raw store
+ * accessor}.
+ * <p>
+ * <b>Usage context:</b> This method is only called in the context of a
+ * {@link CDOProtocolConstants#SIGNAL_REPLICATE_REPOSITORY_RAW REPLICATE_REPOSITORY_RAW} signal that is triggered
+ * from {@link IRepositorySynchronizer}.
+ *
+ * @param in
+ * the <i>stream</i> to deserialize the data from.
+ * @param fromBranchID
+ * the {@link CDOBranch#getID() ID} of the first branch to be imported.
+ * @param toBranchID
+ * the {@link CDOBranch#getID() ID} of the last branch to be imported.
+ * @param fromCommitTime
+ * the first {@link CDOBranchPoint#getTimeStamp() time stamp} of all non-branch data (e.g.
+ * {@link CDORevision revisions}, {@link CDOCommitInfo commit infos}, {@link CDOPackageUnit package units},
+ * etc...) to be imported.
+ * @param toCommitTime
+ * the last {@link CDOBranchPoint#getTimeStamp() time stamp} of all non-branch data (e.g.
+ * {@link CDORevision revisions}, {@link CDOCommitInfo commit infos}, {@link CDOPackageUnit package units},
+ * etc...) to be imported.
+ * @throws IOException
+ * if the <i>stream</i> could not be read from.
+ * @throws UnsupportedOperationException
+ * if this {@link IStoreAccessor.Raw raw store accessor} does not support branching.
+ * @since 4.0
+ */
+ public void rawImport(CDODataInput in, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime,
+ OMMonitor monitor) throws IOException;
+
+ /**
+ * Stores the given {@link CDOPackageUnit package units} in the backend represented by this
+ * {@link IStoreAccessor.Raw raw store accessor} without going through a regular
+ * {@link IStoreAccessor #commit(OMMonitor) commit}. A regular commit operation would assign new
+ * {@link CDOPackageInfo#getMetaIDRange() meta IDs} and {@link CDOPackageUnit#getTimeStamp() time stamps}, which is
+ * not desired in the context of a replication operation.
+ * <p>
+ * <b>Implementation note:</b> The implementor of this method may rely on the fact that multiple subsequent calls to
+ * this method are followed by a single final call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method
+ * where the accumulated backend changes can be committed atomically.
+ *
+ * @param packageUnits
+ * the package units to be stored in the backend represented by this {@link IStoreAccessor.Raw raw store
+ * accessor}.
+ * @param context
+ * an object of an arbitrary class that has been created during previous calls to this method (but after
+ * the last call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method. This context object may
+ * be used to remember implementation specific state between calls to the rawStore() methods and the
+ * rawCommit() method. Its type and value are opaque to the caller, which maintains the context object
+ * between these calls. A new object may be created by the implementor of this method at any time and
+ * should be returned by this method to preserve it for later calls. Can be <code>null</code>.
+ * @param monitor
+ * a progress monitor that <b>may be</b> used to report proper progress of this operation to the caller and
+ * <b>may be</b> used to react to cancelation requests of the caller and <b>must be</b> touched regularly
+ * to prevent timeouts from expiring in the caller.
+ * @return the context object (see above) to be preserved by the caller of this method for later calls.
+ * @since 4.0
+ * @see #rawCommit(Object, OMMonitor)
+ */
+ public Object rawStore(InternalCDOPackageUnit[] packageUnits, Object context, OMMonitor monitor);
+
+ /**
+ * Stores the given {@link CDORevision revision} in the backend represented by this {@link IStoreAccessor.Raw raw
+ * store accessor} without going through a regular {@link IStoreAccessor#commit(OMMonitor) commit}. A regular commit
+ * operation would assign new {@link CDORevisionKey#getID() IDs} and {@link CDOBranchPoint#getTimeStamp() time
+ * stamps}, which is not desired in the context of a replication operation.
+ * <p>
+ * <b>Implementation note:</b> The implementor of this method may rely on the fact that multiple subsequent calls to
+ * this method are followed by a single final call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method
+ * where the accumulated backend changes can be committed atomically.
+ *
+ * @param revision
+ * the revision to be stored in the backend represented by this {@link IStoreAccessor.Raw raw store
+ * accessor}.
+ * @param context
+ * an object of an arbitrary class that has been created during previous calls to this method (but after
+ * the last call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method. This context object may
+ * be used to remember implementation specific state between calls to the rawStore() methods and the
+ * rawCommit() method. Its type and value are opaque to the caller, which maintains the context object
+ * between these calls. A new object may be created by the implementor of this method at any time and
+ * should be returned by this method to preserve it for later calls. Can be <code>null</code>.
+ * @param monitor
+ * a progress monitor that <b>may be</b> used to report proper progress of this operation to the caller and
+ * <b>may be</b> used to react to cancelation requests of the caller and <b>must be</b> touched regularly
+ * to prevent timeouts from expiring in the caller.
+ * @return the context object (see above) to be preserved by the caller of this method for later calls.
+ * @since 4.0
+ * @see #rawCommit(Object, OMMonitor)
+ */
+ public Object rawStore(InternalCDORevision revision, Object context, OMMonitor monitor);
+
+ /**
+ * Stores the given {@link CDOBlob blob} in the backend represented by this {@link IStoreAccessor.Raw raw store
+ * accessor} without going through a regular {@link IStoreAccessor#commit(OMMonitor) commit}.
+ * <p>
+ * <b>Implementation note:</b> The implementor of this method may rely on the fact that multiple subsequent calls to
+ * this method are followed by a single final call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method
+ * where the accumulated backend changes can be committed atomically.
+ *
+ * @param id
+ * the {@link CDOBlob#getID() ID} of the blob to be stored in the backend represented by this
+ * {@link IStoreAccessor.Raw raw store accessor}.
+ * @param size
+ * the {@link CDOBlob#getSize() size} of the blob to be stored in the backend represented by this
+ * {@link IStoreAccessor.Raw raw store accessor}.
+ * @param inputStream
+ * the {@link CDOBlob#getContents() contents} of the blob to be stored in the backend represented by this
+ * {@link IStoreAccessor.Raw raw store accessor}.
+ * @param context
+ * an object of an arbitrary class that has been created during previous calls to this method (but after
+ * the last call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method. This context object may
+ * be used to remember implementation specific state between calls to the rawStore() methods and the
+ * rawCommit() method. Its type and value are opaque to the caller, which maintains the context object
+ * between these calls. A new object may be created by the implementor of this method at any time and
+ * should be returned by this method to preserve it for later calls. Can be <code>null</code>.
+ * @return the context object (see above) to be preserved by the caller of this method for later calls.
+ * @since 4.0
+ * @see #rawCommit(Object, OMMonitor)
+ */
+ public Object rawStore(byte[] id, long size, InputStream inputStream, Object context) throws IOException;
+
+ /**
+ * Stores the given {@link CDOClob clob} in the backend represented by this {@link IStoreAccessor.Raw raw store
+ * accessor} without going through a regular {@link IStoreAccessor#commit(OMMonitor) commit}.
+ * <p>
+ * <b>Implementation note:</b> The implementor of this method may rely on the fact that multiple subsequent calls to
+ * this method are followed by a single final call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method
+ * where the accumulated backend changes can be committed atomically.
+ *
+ * @param id
+ * the {@link CDOClob#getID() ID} of the clob to be stored in the backend represented by this
+ * {@link IStoreAccessor.Raw raw store accessor}.
+ * @param size
+ * the {@link CDOClob#getSize() size} of the clob to be stored in the backend represented by this
+ * {@link IStoreAccessor.Raw raw store accessor}.
+ * @param reader
+ * the {@link CDOClob#getContents() contents} of the clob to be stored in the backend represented by this
+ * {@link IStoreAccessor.Raw raw store accessor}.
+ * @param context
+ * an object of an arbitrary class that has been created during previous calls to this method (but after
+ * the last call to the {@link #rawCommit(Object, OMMonitor) rawCommit()} method. This context object may
+ * be used to remember implementation specific state between calls to the rawStore() methods and the
+ * rawCommit() method. Its type and value are opaque to the caller, which maintains the context object
+ * between these calls. A new object may be created by the implementor of this method at any time and
+ * should be returned by this method to preserve it for later calls. Can be <code>null</code>.
+ * @return the context object (see above) to be preserved by the caller of this method for later calls.
+ * @since 4.0
+ * @see #rawCommit(Object, OMMonitor)
+ */
+ public Object rawStore(byte[] id, long size, Reader reader, Object context) throws IOException;
+
+ /**
+ * Atomically commits the accumulated backend changes resulting from previous calls to the rawStore() methods.
+ *
+ * @param context
+ * an object of an arbitrary class that has been created during previous calls to the rawStore() methods.
+ * This context object may be used to remember implementation specific state between calls to the
+ * rawStore() methods and the rawCommit() method. Its type and value are opaque to the caller, which
+ * maintains the context object between these calls.Can be <code>null</code>.
+ * @param monitor
+ * a progress monitor that <b>may be</b> used to report proper progress of this operation to the caller and
+ * <b>may be</b> used to react to cancelation requests of the caller and <b>must be</b> touched regularly
+ * to prevent timeouts from expiring in the caller.
+ * @since 4.0
+ * @see #rawStore(InternalCDOPackageUnit[], Object, OMMonitor)
+ * @see #rawStore(InternalCDORevision, Object, OMMonitor)
+ */
+ public void rawCommit(Object context, OMMonitor monitor);
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BackupTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BackupTest.java
index f3bb6a0205..2e72ffd2ea 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BackupTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BackupTest.java
@@ -160,8 +160,6 @@ public class BackupTest extends AbstractCDOTest
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
CDOServerImporter.XML importer = new CDOServerImporter.XML(repo2);
importer.importRepository(bais);
-
- sleep(10000000);
}
public void testImportBlob() throws Exception
@@ -201,8 +199,44 @@ public class BackupTest extends AbstractCDOTest
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
CDOServerImporter.XML importer = new CDOServerImporter.XML(repo2);
importer.importRepository(bais);
+ }
+
+ public void testImportClob() throws Exception
+ {
+ InputStream clobStream = null;
+
+ try
+ {
+ clobStream = OM.BUNDLE.getInputStream("copyright.txt");
+ CDOClob clob = new CDOClob(new InputStreamReader(clobStream));
- sleep(10000000);
+ File file = getModel3Factory().createFile();
+ file.setName("copyright.txt");
+ file.setData(clob);
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource("/res1");
+ resource.getContents().add(file);
+ transaction.commit();
+ }
+ finally
+ {
+ IOUtil.close(clobStream);
+ }
+
+ InternalRepository repo1 = getRepository();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ CDOServerExporter.XML exporter = new CDOServerExporter.XML(repo1);
+ exporter.exportRepository(baos);
+ System.out.println(baos.toString());
+
+ InternalRepository repo2 = getRepository("repo2", false);
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ CDOServerImporter.XML importer = new CDOServerImporter.XML(repo2);
+ importer.importRepository(bais);
}
private Customer createCustomer(String name)
diff --git a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java
index 3a4c57fc72..e56a82ff12 100644
--- a/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java
+++ b/plugins/org.eclipse.emf.cdo.workspace/src/org/eclipse/emf/cdo/internal/workspace/CDOWorkspaceImpl.java
@@ -152,7 +152,7 @@ public class CDOWorkspaceImpl implements InternalCDOWorkspace
final OMMonitor monitor = new Monitor();
final Object[] context = { null };
- final IStoreAccessor accessor = localRepository.getStore().getWriter(null);
+ final IStoreAccessor.Raw accessor = (IStoreAccessor.Raw)localRepository.getStore().getWriter(null);
StoreThreadLocal.setAccessor(accessor);
try
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/HexUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/HexUtil.java
index b59c731e68..1d47eae74e 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/HexUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/HexUtil.java
@@ -115,14 +115,14 @@ public final class HexUtil
public static void hexToBytes(String s, byte[] out, int off) throws NumberFormatException, IndexOutOfBoundsException
{
int slen = s.length();
- if (slen % 2 != 0)
+ if ((slen & 1) == 1)
{
s = '0' + s;
}
- if (out.length < off + slen / 2)
+ if (out.length < off + (slen >> 1))
{
- throw new IndexOutOfBoundsException("Output buffer too small for input (" + out.length + '<' + off + slen / 2 //$NON-NLS-1$
+ throw new IndexOutOfBoundsException("Output buffer too small for input (" + out.length + '<' + off + (slen >> 1) //$NON-NLS-1$
+ ')');
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/AsyncOutputStream.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/AsyncOutputStream.java
new file mode 100644
index 0000000000..6a2e2c01f8
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/AsyncOutputStream.java
@@ -0,0 +1,74 @@
+/**
+ * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.io;
+
+import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.util.WrappedException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author Eike Stepper
+ * @since 3.1
+ */
+public abstract class AsyncOutputStream extends PipedOutputStream
+{
+ private CountDownLatch latch = new CountDownLatch(1);
+
+ public AsyncOutputStream() throws IOException
+ {
+ final PipedInputStream in = new PipedInputStream(this);
+ Thread thread = new Thread("AsyncOutputStream")
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ asyncWrite(in);
+ }
+ catch (IOException ex)
+ {
+ OM.LOG.error(ex);
+ throw WrappedException.wrap(ex);
+ }
+ finally
+ {
+ latch.countDown();
+ }
+ }
+ };
+
+ thread.setDaemon(true);
+ thread.start();
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ super.close();
+
+ try
+ {
+ latch.await();
+ }
+ catch (InterruptedException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ protected abstract void asyncWrite(InputStream in) throws IOException;
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/AsyncWriter.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/AsyncWriter.java
new file mode 100644
index 0000000000..678ee67da6
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/AsyncWriter.java
@@ -0,0 +1,74 @@
+/**
+ * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.io;
+
+import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.util.WrappedException;
+
+import java.io.IOException;
+import java.io.PipedReader;
+import java.io.PipedWriter;
+import java.io.Reader;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author Eike Stepper
+ * @since 3.1
+ */
+public abstract class AsyncWriter extends PipedWriter
+{
+ private CountDownLatch latch = new CountDownLatch(1);
+
+ public AsyncWriter() throws IOException
+ {
+ final PipedReader in = new PipedReader(this);
+ Thread thread = new Thread("AsyncWriter")
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ asyncWrite(in);
+ }
+ catch (IOException ex)
+ {
+ OM.LOG.error(ex);
+ throw WrappedException.wrap(ex);
+ }
+ finally
+ {
+ latch.countDown();
+ }
+ }
+ };
+
+ thread.setDaemon(true);
+ thread.start();
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ super.close();
+
+ try
+ {
+ latch.await();
+ }
+ catch (InterruptedException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+
+ protected abstract void asyncWrite(Reader in) throws IOException;
+}

Back to the top