summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-02-10 05:11:20 (EST)
committerEike Stepper2008-02-10 05:11:20 (EST)
commit9978960de6d97702457d326046cffbf94d299201 (patch)
tree9ea9fd0855276e73e0948e16bfa5089633eddaf7
parent8c3a93f9da597a0eb5f07b95f4673af6edbe2c15 (diff)
downloadcdo-9978960de6d97702457d326046cffbf94d299201.zip
cdo-9978960de6d97702457d326046cffbf94d299201.tar.gz
cdo-9978960de6d97702457d326046cffbf94d299201.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.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java107
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java71
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStore.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStoreAccessor.java25
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java15
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/StoreAccessor.java127
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java142
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CommitTransactionIndication.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreWriter.java32
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java8
12 files changed, 294 insertions, 260 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
index aec44d3..5f744b9 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
@@ -101,18 +101,21 @@ public class DBStore extends LongIDStore implements IDBStore
return dbConnectionProvider;
}
- @Override
public boolean hasAuditingSupport()
{
return true;
}
- @Override
public boolean hasBranchingSupport()
{
return false;
}
+ public boolean hasWriteDeltaSupport()
+ {
+ return false;
+ }
+
@Override
public DBStoreReader getReader(ISession session)
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java
index 3ee17d2..b9d6789 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java
@@ -12,14 +12,12 @@ package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.internal.protocol.model.CDOClassImpl;
import org.eclipse.emf.cdo.internal.protocol.model.CDOClassProxy;
-import org.eclipse.emf.cdo.protocol.id.CDOID;
import org.eclipse.emf.cdo.protocol.id.CDOIDMeta;
import org.eclipse.emf.cdo.protocol.id.CDOIDMetaRange;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOFeature;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
-import org.eclipse.emf.cdo.protocol.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.emf.cdo.server.db.IClassMapping;
import org.eclipse.emf.cdo.server.db.IDBStoreWriter;
@@ -47,38 +45,13 @@ public class DBStoreWriter extends DBStoreReader implements IDBStoreWriter
super(store, view);
}
- public void beginCommit(CommitContext context)
+ @Override
+ public void commit(CommitContext context)
{
- writePackages(context.getNewPackages());
- }
-
- public void createNewIDs(CommitContext context, CDORevision[] newObjects, CDOID[] newIDs)
- {
- for (int i = 0; i < newObjects.length; i++)
- {
- newIDs[i] = getStore().getNextCDOID();
- }
- }
-
- public void finishCommit(CommitContext context, CDORevision[] newObjects, CDORevision[] dirtyObjects)
- {
- for (CDORevision revision : newObjects)
- {
- writeRevision(revision);
- }
-
- for (CDORevision revision : dirtyObjects)
- {
- writeRevision(revision);
- }
+ super.commit(context);
try
{
- if (TRACER.isEnabled())
- {
- TRACER.format("Committing transaction: {0}", getView());
- }
-
getConnection().commit();
}
catch (SQLException ex)
@@ -87,20 +60,13 @@ public class DBStoreWriter extends DBStoreReader implements IDBStoreWriter
}
}
- public void finishCommit(CommitContext context, CDORevision[] newObjects, CDORevisionDelta[] dirtyObjectDeltas)
+ @Override
+ public void rollback(CommitContext context)
{
- throw new UnsupportedOperationException();
- }
+ super.rollback(context);
- public void cancelCommit(CommitContext context)
- {
try
{
- if (TRACER.isEnabled())
- {
- TRACER.format("Rolling back transaction: {0}", getView());
- }
-
getConnection().rollback();
}
catch (SQLException ex)
@@ -109,37 +75,22 @@ public class DBStoreWriter extends DBStoreReader implements IDBStoreWriter
}
}
+ @Override
protected void writePackages(CDOPackage... cdoPackages)
{
- for (CDOPackage cdoPackage : cdoPackages)
- {
- writePackage(cdoPackage);
- }
-
+ super.writePackages(cdoPackages);
Set<IDBTable> affectedTables = mapPackages(cdoPackages);
getStore().getDBAdapter().createTables(affectedTables, getConnection());
}
- protected void writeRevision(CDORevision revision)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Inserting revision: {0}", revision);
- }
-
- CDOClass cdoClass = revision.getCDOClass();
- IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
- IClassMapping mapping = mappingStrategy.getClassMapping(cdoClass);
- mapping.writeRevision(this, revision);
- }
-
+ @Override
protected void writePackage(CDOPackage cdoPackage)
{
int id = getStore().getNextPackageID();
PackageServerInfo.setDBID(cdoPackage, id);
if (TRACER.isEnabled())
{
- TRACER.format("Inserting package: {0} --> {1}", cdoPackage, id);
+ TRACER.format("Writing package: {0} --> {1}", cdoPackage, id);
}
String packageURI = cdoPackage.getPackageURI();
@@ -184,12 +135,10 @@ public class DBStoreWriter extends DBStoreReader implements IDBStoreWriter
DBUtil.close(pstmt);
}
- for (CDOClass cdoClass : cdoPackage.getClasses())
- {
- writeClass((CDOClassImpl)cdoClass);
- }
+ super.writePackage(cdoPackage);
}
+ @Override
protected void writeClass(CDOClassImpl cdoClass)
{
int id = getStore().getNextClassID();
@@ -203,25 +152,19 @@ public class DBStoreWriter extends DBStoreReader implements IDBStoreWriter
DBUtil.insertRow(getConnection(), getStore().getDBAdapter(), CDODBSchema.CLASSES, id, packageID, classifierID,
name, isAbstract);
- for (CDOClassProxy superType : cdoClass.getSuperTypeProxies())
- {
- writeSuperType(id, superType);
- }
-
- for (CDOFeature feature : cdoClass.getFeatures())
- {
- writeFeature(feature);
- }
+ super.writeClass(cdoClass);
}
- protected void writeSuperType(int type, CDOClassProxy superType)
+ @Override
+ protected void writeSuperType(CDOClassImpl type, CDOClassProxy superType)
{
+ int id = ClassServerInfo.getDBID(type);
String packageURI = superType.getPackageURI();
int classifierID = superType.getClassifierID();
- DBUtil
- .insertRow(getConnection(), getStore().getDBAdapter(), CDODBSchema.SUPERTYPES, type, packageURI, classifierID);
+ DBUtil.insertRow(getConnection(), getStore().getDBAdapter(), CDODBSchema.SUPERTYPES, id, packageURI, classifierID);
}
+ @Override
protected void writeFeature(CDOFeature feature)
{
int id = getStore().getNextFeatureID();
@@ -240,4 +183,18 @@ public class DBStoreWriter extends DBStoreReader implements IDBStoreWriter
DBUtil.insertRow(getConnection(), getStore().getDBAdapter(), CDODBSchema.FEATURES, id, classID, featureID, name,
type, packageURI, classifierID, many, containment, idx);
}
+
+ @Override
+ protected void writeRevision(CDORevision revision)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Writing revision: {0}", revision);
+ }
+
+ CDOClass cdoClass = revision.getCDOClass();
+ IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
+ IClassMapping mapping = mappingStrategy.getClassMapping(cdoClass);
+ mapping.writeRevision(this, revision);
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java
index b8ec221..7a445e8 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java
@@ -132,13 +132,16 @@ public class MEMStore extends LongIDStore
return false;
}
- @Override
+ public boolean hasBranchingSupport()
+ {
+ return false;
+ }
+
public boolean hasWriteDeltaSupport()
{
return true;
}
- @Override
public boolean hasAuditingSupport()
{
return true;
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java
index 88f8aa3..f76fba0 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java
@@ -128,63 +128,50 @@ public class MEMStoreAccessor extends StoreAccessor implements IStoreReader, ISt
throw new UnsupportedOperationException();
}
- public void beginCommit(CommitContext context)
- {
- // Do nothing
- }
-
- public void createNewIDs(CommitContext context, CDORevision[] newObjects, CDOID[] newIDs)
+ @Override
+ public void commit(CommitContext context)
{
- for (int i = 0; i < newObjects.length; i++)
+ MEMStore store = getStore();
+ synchronized (store)
{
- newIDs[i] = getStore().getNextCDOID();
+ super.commit(context);
}
}
- public void finishCommit(CommitContext context, CDORevision[] newObjects, CDORevision[] dirtyObjects)
- {
- writeRevisions(newObjects);
- writeRevisions(dirtyObjects);
- commit();
- }
-
- public void finishCommit(CommitContext context, CDORevision[] newObjects, CDORevisionDelta[] dirtyObjectDeltas)
- {
- writeRevisions(newObjects);
- writeRevisionDeltas(dirtyObjectDeltas);
- commit();
- }
-
- public void cancelCommit(CommitContext context)
+ @Override
+ public void rollback(CommitContext context)
{
+ MEMStore store = getStore();
+ synchronized (store)
+ {
+ super.rollback(context);
+ for (CDORevision revision : newRevisions)
+ {
+ store.removeRevision(revision);
+ }
+ }
}
- protected void writeRevisions(CDORevision[] revisions)
+ @Override
+ protected void writePackages(CDOPackage... cdoPackages)
{
- for (CDORevision revision : revisions)
- {
- newRevisions.add(revision);
- }
+ // Do nothing
}
- protected void writeRevisionDeltas(CDORevisionDelta[] revisionDeltas)
+ @Override
+ protected void writeRevision(CDORevision revision)
{
- for (CDORevisionDelta revisionDelta : revisionDeltas)
- {
- CDORevision revision = getStore().getRevision(revisionDelta.getID());
- CDORevision newRevision = CDORevisionUtil.copy(revision);
- revisionDelta.apply(newRevision);
- newRevisions.add(newRevision);
- }
+ newRevisions.add(revision);
+ getStore().addRevision(revision);
}
- protected void commit()
+ @Override
+ protected void writeRevisionDelta(CDORevisionDelta revisionDelta)
{
- MEMStore store = getStore();
- for (CDORevision revision : newRevisions)
- {
- store.addRevision(revision);
- }
+ CDORevision revision = getStore().getRevision(revisionDelta.getID());
+ CDORevision newRevision = CDORevisionUtil.copy(revision);
+ revisionDelta.apply(newRevision);
+ writeRevision(newRevision);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStore.java
index 174f2a4..56e4acf 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStore.java
@@ -25,7 +25,16 @@ public class NOOPStore extends LongIDStore
super(TYPE);
}
- @Override
+ public boolean hasBranchingSupport()
+ {
+ return false;
+ }
+
+ public boolean hasWriteDeltaSupport()
+ {
+ return true;
+ }
+
public boolean hasAuditingSupport()
{
return true;
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStoreAccessor.java
index a205e62..03a140f 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/NOOPStoreAccessor.java
@@ -16,7 +16,6 @@ import org.eclipse.emf.cdo.protocol.model.CDOFeature;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.protocol.model.CDOPackageInfo;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
-import org.eclipse.emf.cdo.protocol.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IStoreChunkReader;
import org.eclipse.emf.cdo.server.IStoreReader;
@@ -98,28 +97,4 @@ public class NOOPStoreAccessor extends StoreAccessor implements IStoreReader, IS
{
throw new UnsupportedOperationException();
}
-
- public void beginCommit(CommitContext context)
- {
- }
-
- public void createNewIDs(CommitContext context, CDORevision[] newObjects, CDOID[] newIDs)
- {
- for (int i = 0; i < newObjects.length; i++)
- {
- newIDs[i] = getStore().getNextCDOID();
- }
- }
-
- public void finishCommit(CommitContext context, CDORevision[] newObjects, CDORevision[] dirtyObjects)
- {
- }
-
- public void finishCommit(CommitContext context, CDORevision[] newObjects, CDORevisionDelta[] dirtyObjectDeltas)
- {
- }
-
- public void cancelCommit(CommitContext context)
- {
- }
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java
index b390f85..e753757 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java
@@ -68,21 +68,6 @@ public abstract class Store extends Lifecycle implements IStore
this.repository = repository;
}
- public boolean hasWriteDeltaSupport()
- {
- return false;
- }
-
- public boolean hasAuditingSupport()
- {
- return false;
- }
-
- public boolean hasBranchingSupport()
- {
- return false;
- }
-
public IStoreReader getReader(ISession session)
{
return createReader(session);
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/StoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/StoreAccessor.java
index a2b4252..f3768fe 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/StoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/StoreAccessor.java
@@ -11,17 +11,31 @@
**************************************************************************/
package org.eclipse.emf.cdo.internal.server;
+import org.eclipse.emf.cdo.internal.protocol.model.CDOClassImpl;
+import org.eclipse.emf.cdo.internal.protocol.model.CDOClassProxy;
import org.eclipse.emf.cdo.internal.protocol.revision.InternalCDORevision;
+import org.eclipse.emf.cdo.internal.server.bundle.OM;
+import org.eclipse.emf.cdo.protocol.id.CDOID;
+import org.eclipse.emf.cdo.protocol.id.CDOIDTemp;
+import org.eclipse.emf.cdo.protocol.model.CDOClass;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
+import org.eclipse.emf.cdo.protocol.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.IView;
+import org.eclipse.emf.cdo.server.IStoreWriter.CommitContext;
+
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
/**
* @author Eike Stepper
*/
public class StoreAccessor implements IStoreAccessor
{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, StoreAccessor.class);
+
private Store store;
private Object context;
@@ -88,4 +102,117 @@ public class StoreAccessor implements IStoreAccessor
{
return (InternalCDORevision)revision;
}
+
+ public void commit(CommitContext context)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Committing transaction: {0}", getView());
+ }
+
+ writePackages(context.getNewPackages());
+ addIDMappings(context);
+ context.applyIDMappings();
+ writeRevisions(context.getNewObjects());
+ if (store.hasWriteDeltaSupport() && store.getRepository().isSupportingRevisionDeltas())
+ {
+ writeRevisionDeltas(context.getDirtyObjectDeltas());
+ }
+ else
+ {
+ writeRevisions(context.getDirtyObjects());
+ }
+ }
+
+ public void rollback(CommitContext context)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Rolling back transaction: {0}", getView());
+ }
+ }
+
+ protected void addIDMappings(CommitContext context)
+ {
+ if (store instanceof LongIDStore)
+ {
+ LongIDStore longIDStore = (LongIDStore)getStore();
+ for (CDORevision revision : context.getNewObjects())
+ {
+ CDOIDTemp oldID = (CDOIDTemp)revision.getID();
+ CDOID newID = longIDStore.getNextCDOID();
+ if (newID == null || newID.isNull() || newID.isTemporary())
+ {
+ throw new IllegalStateException("newID=" + newID);
+ }
+
+ context.addIDMapping(oldID, newID);
+ }
+ }
+ }
+
+ protected void writePackages(CDOPackage... cdoPackages)
+ {
+ for (CDOPackage cdoPackage : cdoPackages)
+ {
+ writePackage(cdoPackage);
+ }
+ }
+
+ protected void writePackage(CDOPackage cdoPackage)
+ {
+ for (CDOClass cdoClass : cdoPackage.getClasses())
+ {
+ writeClass((CDOClassImpl)cdoClass);
+ }
+ }
+
+ protected void writeClass(CDOClassImpl cdoClass)
+ {
+ for (CDOClassProxy superType : cdoClass.getSuperTypeProxies())
+ {
+ writeSuperType(cdoClass, superType);
+ }
+
+ for (CDOFeature feature : cdoClass.getFeatures())
+ {
+ writeFeature(feature);
+ }
+ }
+
+ protected void writeSuperType(CDOClassImpl type, CDOClassProxy superType)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void writeFeature(CDOFeature feature)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void writeRevisions(CDORevision[] revisions)
+ {
+ for (CDORevision revision : revisions)
+ {
+ writeRevision(revision);
+ }
+ }
+
+ protected void writeRevision(CDORevision revision)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void writeRevisionDeltas(CDORevisionDelta[] revisionDeltas)
+ {
+ for (CDORevisionDelta revisionDelta : revisionDeltas)
+ {
+ writeRevisionDelta(revisionDelta);
+ }
+ }
+
+ protected void writeRevisionDelta(CDORevisionDelta revisionDelta)
+ {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java
index 4483c5a..55befcc 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java
@@ -64,10 +64,10 @@ public class Transaction extends View implements ITransaction, IStoreWriter.Comm
private CDORevision[] newObjects;
- private CDORevisionDelta[] dirtyObjectDeltas;
-
private CDORevision[] dirtyObjects;
+ private CDORevisionDelta[] dirtyObjectDeltas;
+
private List<CDOIDMetaRange> metaIDRanges = new ArrayList<CDOIDMetaRange>();
private ConcurrentMap<CDOIDTemp, CDOID> idMappings = new ConcurrentHashMap<CDOIDTemp, CDOID>();
@@ -103,14 +103,19 @@ public class Transaction extends View implements ITransaction, IStoreWriter.Comm
return newPackages;
}
- public int getNumberOfNewObjects()
+ public CDORevision[] getNewObjects()
+ {
+ return newObjects;
+ }
+
+ public CDORevision[] getDirtyObjects()
{
- return newObjects == null ? 0 : newObjects.length;
+ return dirtyObjects;
}
- public int getNumberOfDirtyObjects()
+ public CDORevisionDelta[] getDirtyObjectDeltas()
{
- return dirtyObjects == null ? 0 : dirtyObjects.length;
+ return dirtyObjectDeltas;
}
public List<CDOIDMetaRange> getMetaIDRanges()
@@ -118,11 +123,35 @@ public class Transaction extends View implements ITransaction, IStoreWriter.Comm
return Collections.unmodifiableList(metaIDRanges);
}
- public Map<CDOIDTemp, CDOID> getIdMappings()
+ public Map<CDOIDTemp, CDOID> getIDMappings()
{
return Collections.unmodifiableMap(idMappings);
}
+ public void addIDMapping(CDOIDTemp oldID, CDOID newID)
+ {
+ if (newID == null || newID.isNull() || newID.isTemporary())
+ {
+ throw new IllegalStateException("newID=" + newID);
+ }
+
+ CDOID previousMapping = idMappings.putIfAbsent(oldID, newID);
+ if (previousMapping != null)
+ {
+ throw new IllegalStateException("previousMapping != null");
+ }
+ }
+
+ public void applyIDMappings()
+ {
+ applyIDMappings(newObjects);
+ applyIDMappings(dirtyObjects);
+ for (CDORevisionDelta dirtyObjectDelta : dirtyObjectDeltas)
+ {
+ ((InternalCDORevisionDelta)dirtyObjectDelta).adjustReferences(idMappings);
+ }
+ }
+
public String getRollbackMessage()
{
return rollbackMessage;
@@ -142,17 +171,17 @@ public class Transaction extends View implements ITransaction, IStoreWriter.Comm
try
{
adjustMetaRanges();
- beginCommit();
- populateIDMappings();
- adjust();
- finishCommit();
+ adjustTimeStamps();
+ computeDirtyObjects(!repository.isSupportingRevisionDeltas());
+
+ storeWriter.commit(this);
updateInfraStructure();
}
catch (RuntimeException ex)
{
OM.LOG.error(ex);
rollbackMessage = ex.getMessage();
- cancelCommit();
+ rollback();
}
finally
{
@@ -196,6 +225,15 @@ public class Transaction extends View implements ITransaction, IStoreWriter.Comm
}
}
+ private void adjustTimeStamps()
+ {
+ for (CDORevision newObject : newObjects)
+ {
+ InternalCDORevision revision = (InternalCDORevision)newObject;
+ revision.setCreated(timeStamp);
+ }
+ }
+
private void adjustMetaRanges()
{
for (CDOPackage newPackage : newPackages)
@@ -229,55 +267,6 @@ public class Transaction extends View implements ITransaction, IStoreWriter.Comm
metaIDRanges.add(newRange);
}
- private void beginCommit()
- {
- storeWriter.beginCommit(this);
- }
-
- private void populateIDMappings()
- {
- CDOID[] newIDs = new CDOID[newObjects.length];
- storeWriter.createNewIDs(this, newObjects, newIDs);
- for (int i = 0; i < newObjects.length; i++)
- {
- addIDMapping((CDOIDTemp)newObjects[i].getID(), newIDs[i]);
- }
- }
-
- private void addIDMapping(CDOIDTemp oldID, CDOID newID)
- {
- if (newID == null)
- {
- throw new IllegalArgumentException("newID == null");
- }
-
- CDOID previousMapping = idMappings.putIfAbsent(oldID, newID);
- if (previousMapping != null)
- {
- throw new IllegalStateException("previousMapping != null");
- }
- }
-
- private void adjust()
- {
- for (CDORevision newObject : newObjects)
- {
- adjustRevision((InternalCDORevision)newObject);
- }
-
- for (CDORevisionDelta dirtyObjectDelta : dirtyObjectDeltas)
- {
- ((InternalCDORevisionDelta)dirtyObjectDelta).adjustReferences(idMappings);
- }
- }
-
- private void adjustRevision(InternalCDORevision revision)
- {
- revision.setID(idMappings.get(revision.getID()));
- revision.setCreated(timeStamp);
- revision.adjustReferences(idMappings);
- }
-
private void computeDirtyObjects(boolean failOnNull)
{
for (int i = 0; i < dirtyObjectDeltas.length; i++)
@@ -299,36 +288,41 @@ public class Transaction extends View implements ITransaction, IStoreWriter.Comm
CDORevision originObject = revisionResolver.getRevisionByVersion(id, CDORevision.UNCHUNKED, version, false);
if (originObject != null)
{
- CDORevision dirtyObject = CDORevisionUtil.copy(originObject);
+ InternalCDORevision dirtyObject = (InternalCDORevision)CDORevisionUtil.copy(originObject);
dirtyObjectDelta.apply(dirtyObject);
- ((InternalCDORevision)dirtyObject).setCreated(timeStamp);
+ dirtyObject.setCreated(timeStamp);
+ // dirtyObject.setVersion(originObject.getVersion() + 1);
return dirtyObject;
}
return null;
}
- private void finishCommit()
+ private void applyIDMappings(CDORevision[] revisions)
{
- if (repository.isSupportingRevisionDeltas())
- {
- computeDirtyObjects(false);
- storeWriter.finishCommit(this, newObjects, dirtyObjectDeltas);
- }
- else
+ for (CDORevision revision : revisions)
{
- computeDirtyObjects(true);
- storeWriter.finishCommit(this, newObjects, dirtyObjects);
+ if (revision != null)
+ {
+ InternalCDORevision internal = (InternalCDORevision)revision;
+ CDOID newID = idMappings.get(internal.getID());
+ if (newID != null)
+ {
+ internal.setID(newID);
+ }
+
+ internal.adjustReferences(idMappings);
+ }
}
}
- private void cancelCommit()
+ private void rollback()
{
if (storeWriter != null)
{
try
{
- storeWriter.cancelCommit(this);
+ storeWriter.rollback(this);
}
catch (RuntimeException ex)
{
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CommitTransactionIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CommitTransactionIndication.java
index 42b2dfc..aabbfc9 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CommitTransactionIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CommitTransactionIndication.java
@@ -126,7 +126,7 @@ public class CommitTransactionIndication extends CDOServerIndication
}
// ID mappings
- Map<CDOIDTemp, CDOID> idMappings = transaction.getIdMappings();
+ Map<CDOIDTemp, CDOID> idMappings = transaction.getIDMappings();
for (Entry<CDOIDTemp, CDOID> entry : idMappings.entrySet())
{
CDOIDTemp oldID = entry.getKey();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreWriter.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreWriter.java
index 7e6e8e9..db8136b 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreWriter.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreWriter.java
@@ -12,14 +12,12 @@
package org.eclipse.emf.cdo.server;
import org.eclipse.emf.cdo.protocol.id.CDOID;
-import org.eclipse.emf.cdo.protocol.id.CDOIDMetaRange;
import org.eclipse.emf.cdo.protocol.id.CDOIDTemp;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.cdo.protocol.model.CDOPackageManager;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
import org.eclipse.emf.cdo.protocol.revision.delta.CDORevisionDelta;
-import java.util.List;
import java.util.Map;
/**
@@ -29,15 +27,9 @@ public interface IStoreWriter extends IStoreReader
{
public IView getView();
- public void beginCommit(CommitContext context);
+ public void commit(CommitContext context);
- public void createNewIDs(CommitContext context, CDORevision[] newObjects, CDOID[] newIDs);
-
- public void finishCommit(CommitContext context, CDORevision[] newObjects, CDORevision[] dirtyObjects);
-
- public void finishCommit(CommitContext context, CDORevision[] newObjects, CDORevisionDelta[] dirtyObjectDeltas);
-
- public void cancelCommit(CommitContext context);
+ public void rollback(CommitContext context);
/**
* Represents the state of a single, logical commit operation which is driven through multiple calls to several
@@ -74,27 +66,31 @@ public interface IStoreWriter extends IStoreReader
public CDOPackage[] getNewPackages();
/**
- * Returns the number of new objects that are part of the commit operation represented by this
+ * Returns an array of the new objects that are part of the commit operation represented by this
* <code>CommitContext</code>.
*/
- public int getNumberOfNewObjects();
+ public CDORevision[] getNewObjects();
/**
- * Returns the number of dirty objects that are part of the commit operation represented by this
+ * Returns an array of the dirty objects that are part of the commit operation represented by this
* <code>CommitContext</code>.
*/
- public int getNumberOfDirtyObjects();
+ public CDORevision[] getDirtyObjects();
/**
- * Returns an unmodifiable list of the temporary meta ID ranges of the new packages as they are received by the
- * framework.
+ * Returns an array of the dirty object deltas that are part of the commit operation represented by this
+ * <code>CommitContext</code>.
*/
- public List<CDOIDMetaRange> getMetaIDRanges();
+ public CDORevisionDelta[] getDirtyObjectDeltas();
/**
* Returns an unmodifiable map from all temporary IDs (meta or not) to their persistent counter parts. It is
* initially populated with the mappings of all new meta objects.
*/
- public Map<CDOIDTemp, CDOID> getIdMappings();
+ public Map<CDOIDTemp, CDOID> getIDMappings();
+
+ public void addIDMapping(CDOIDTemp oldID, CDOID newID);
+
+ public void applyIDMappings();
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
index 5ed5141..c32e966 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InvalidationTest.java
@@ -318,7 +318,7 @@ public class InvalidationTest extends AbstractCDOTest
msg("Changing name");
category1A.setName("CHANGED NAME");
- ITimeOuter timeOuter = new PollingTimeOuter(10, 100)
+ ITimeOuter timeOuter = new PollingTimeOuter(20, 100)
{
@Override
protected boolean successful()
@@ -328,14 +328,12 @@ public class InvalidationTest extends AbstractCDOTest
};
msg("Checking before commit");
- boolean timedOut = timeOuter.timedOut();
- assertEquals(true, timedOut);
+ assertEquals(true, timeOuter.timedOut());
msg("Committing");
transaction.commit();
msg("Checking after commit");
- timedOut = timeOuter.timedOut();
- assertEquals(false, timedOut);
+ assertEquals(false, timeOuter.timedOut());
}
}