Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-06-13 05:31:12 +0000
committerEike Stepper2010-06-13 05:31:12 +0000
commitef1647b4ba07e0530534f488c51dc29151403872 (patch)
tree8fc7c8c7d47901c5b9d6e1b84f94a784437114ff
parent9d9a9f7a9dd61794b2cf38235987cb5f01b73271 (diff)
downloadcdo-ef1647b4ba07e0530534f488c51dc29151403872.tar.gz
cdo-ef1647b4ba07e0530534f488c51dc29151403872.tar.xz
cdo-ef1647b4ba07e0530534f488c51dc29151403872.zip
[316421] Provide an option to lock reference targets during commit
https://bugs.eclipse.org/bugs/show_bug.cgi?id=316421
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDOListImpl.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/BaseCDORevision.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TransactionCommitContext.java69
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreAccessor.java5
4 files changed, 79 insertions, 4 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDOListImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDOListImpl.java
index 45ddda7b3e..da8a96671c 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDOListImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDOListImpl.java
@@ -78,7 +78,7 @@ public class CDOListImpl extends MoveableArrayList<Object> implements InternalCD
Object element = super.get(i);
handleAdjustReference(i, element);
Object newID = type.adjustReferences(revisionAdjuster, element);
- if (newID != element)
+ if (newID != element) // Just an optimization for NOOP adjusters
{
super.set(i, newID);
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/BaseCDORevision.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/BaseCDORevision.java
index 1336d1e66b..f0e3326ccd 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/BaseCDORevision.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/BaseCDORevision.java
@@ -516,7 +516,12 @@ public abstract class BaseCDORevision extends AbstractCDORevision
else
{
CDOType type = CDOModelUtil.getType(feature);
- setValue(i, type.adjustReferences(revisionAdjuster, getValue(i)));
+ Object oldValue = getValue(i);
+ Object newValue = type.adjustReferences(revisionAdjuster, oldValue);
+ if (oldValue != newValue) // Just an optimization for NOOP adjusters
+ {
+ setValue(i, newValue);
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TransactionCommitContext.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TransactionCommitContext.java
index 29e154ddf3..8b67652285 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TransactionCommitContext.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TransactionCommitContext.java
@@ -18,6 +18,7 @@ import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDAndVersion;
import org.eclipse.emf.cdo.common.id.CDOIDMetaRange;
+import org.eclipse.emf.cdo.common.id.CDOIDObject;
import org.eclipse.emf.cdo.common.id.CDOIDTemp;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOModelUtil;
@@ -25,7 +26,10 @@ import org.eclipse.emf.cdo.common.model.CDOPackageUnit;
import org.eclipse.emf.cdo.common.revision.CDOReferenceAdjuster;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionKey;
+import org.eclipse.emf.cdo.common.revision.delta.CDOAddFeatureDelta;
+import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDeltaVisitor;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
+import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta;
import org.eclipse.emf.cdo.common.util.CDOCommonUtil;
import org.eclipse.emf.cdo.internal.common.commit.CDOCommitDataImpl;
import org.eclipse.emf.cdo.internal.common.model.CDOPackageRegistryImpl;
@@ -36,6 +40,7 @@ import org.eclipse.emf.cdo.spi.common.commit.InternalCDOCommitInfoManager;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageInfo;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
+import org.eclipse.emf.cdo.spi.common.revision.CDOFeatureDeltaVisitorImpl;
import org.eclipse.emf.cdo.spi.common.revision.CDOIDMapper;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
@@ -108,6 +113,8 @@ public class TransactionCommitContext implements InternalCommitContext
private String rollbackMessage;
+ private boolean autoLockNewTargetsEnabled;
+
private boolean autoReleaseLocksEnabled;
public TransactionCommitContext(InternalTransaction transaction)
@@ -115,6 +122,8 @@ public class TransactionCommitContext implements InternalCommitContext
this.transaction = transaction;
InternalRepository repository = transaction.getRepository();
+ autoLockNewTargetsEnabled = isAutoLockNewTargetsEnabled(repository);
+
packageRegistry = new TransactionPackageRegistry(repository.getPackageRegistry(false));
packageRegistry.activate();
}
@@ -532,13 +541,53 @@ public class TransactionCommitContext implements InternalCommitContext
protected void lockObjects() throws InterruptedException
{
lockedObjects.clear();
- boolean supportingBranches = transaction.getRepository().isSupportingBranches();
+ final boolean supportingBranches = transaction.getRepository().isSupportingBranches();
+
+ CDOFeatureDeltaVisitor deltaTargetLocker = null;
+ if (autoLockNewTargetsEnabled)
+ {
+ deltaTargetLocker = new CDOFeatureDeltaVisitorImpl()
+ {
+ @Override
+ public void visit(CDOAddFeatureDelta delta)
+ {
+ lockTarget(delta.getValue(), supportingBranches);
+ }
+
+ @Override
+ public void visit(CDOSetFeatureDelta delta)
+ {
+ lockTarget(delta.getValue(), supportingBranches);
+ }
+ };
+
+ CDOReferenceAdjuster revisionTargetLocker = new CDOReferenceAdjuster()
+ {
+ public Object adjustReference(Object value)
+ {
+ lockTarget(value, supportingBranches);
+ return value;
+ }
+ };
+
+ for (int i = 0; i < newObjects.length; i++)
+ {
+ InternalCDORevision newRevision = newObjects[i];
+ newRevision.adjustReferences(revisionTargetLocker);
+ }
+ }
for (int i = 0; i < dirtyObjectDeltas.length; i++)
{
- CDOID id = dirtyObjectDeltas[i].getID();
+ InternalCDORevisionDelta delta = dirtyObjectDeltas[i];
+ CDOID id = delta.getID();
Object key = supportingBranches ? CDOIDUtil.createIDAndBranch(id, transaction.getBranch()) : id;
lockedObjects.add(key);
+
+ if (deltaTargetLocker != null)
+ {
+ delta.accept(deltaTargetLocker);
+ }
}
for (int i = 0; i < detachedObjects.length; i++)
@@ -563,6 +612,22 @@ public class TransactionCommitContext implements InternalCommitContext
}
}
+ private void lockTarget(Object value, boolean supportingBranches)
+ {
+ if (value instanceof CDOIDObject)
+ {
+ CDOIDObject id = (CDOIDObject)value;
+ Object key = supportingBranches ? CDOIDUtil.createIDAndBranch(id, transaction.getBranch()) : id;
+ lockedObjects.add(key);
+ }
+ }
+
+ private boolean isAutoLockNewTargetsEnabled(InternalRepository repository)
+ {
+ String value = repository.getProperties().get(PROP_AUTO_LOCK_NEW_TARGETS);
+ return value == null ? false : Boolean.valueOf(value);
+ }
+
private synchronized void unlockObjects()
{
if (!lockedObjects.isEmpty())
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 3c29d63745..17344f51b9 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
@@ -218,6 +218,11 @@ public interface IStoreAccessor extends IQueryHandlerProvider, BranchLoader, Com
public interface CommitContext
{
/**
+ * @since 3.0
+ */
+ public static final String PROP_AUTO_LOCK_NEW_TARGETS = "autoLockNewTargets";
+
+ /**
* Returns the ID of the transactional view (<code>ITransaction</code>) which is the scope of the commit operation
* represented by this <code>CommitContext</code>.
*/

Back to the top