Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-08-04 11:15:04 -0400
committerEike Stepper2011-08-04 11:15:04 -0400
commite19c81c05a03bf3a3fef7972a0f3cf631ebe7b2b (patch)
tree084a5a56ebbc2ef75f89a66242948b44507cb943
parentef55a452fbe195b0efc3857f6043ce8c6c66eee7 (diff)
downloadcdo-e19c81c05a03bf3a3fef7972a0f3cf631ebe7b2b.tar.gz
cdo-e19c81c05a03bf3a3fef7972a0f3cf631ebe7b2b.tar.xz
cdo-e19c81c05a03bf3a3fef7972a0f3cf631ebe7b2b.zip
[352191] Locking detached elements
https://bugs.eclipse.org/bugs/show_bug.cgi?id=352191
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java36
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java21
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapper.java21
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java17
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java26
5 files changed, 108 insertions, 13 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java
index c80ffcea9a..11350de431 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/LockingManagerTest.java
@@ -787,6 +787,42 @@ public class LockingManagerTest extends AbstractLockingTest
assertWriteLock(false, company);
}
+ /**
+ * Bug 352191.
+ */
+ public void testLockDetached() throws Exception
+ {
+ Company company = getModel1Factory().createCompany();
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource res = transaction.createResource(getResourcePath("/res1"));
+ res.getContents().add(company);
+ transaction.commit();
+
+ res.getContents().remove(0);
+ assertTransient(company);
+
+ CDOObject cdoObject = CDOUtil.getCDOObject(company);
+ transaction.lockObjects(Collections.singleton(cdoObject), LockType.WRITE, DEFAULT_TIMEOUT);
+
+ // Verify
+ CDOTransaction transaction2 = session.openTransaction();
+ CDOResource res2 = transaction2.getResource(getResourcePath("/res1"));
+ Company company2 = (Company)res2.getContents().get(0);
+ company2.setName("NewName");
+
+ try
+ {
+ transaction2.commit();
+ fail("CommitException expected");
+ }
+ catch (CommitException expected)
+ {
+ // SUCCESS
+ }
+ }
+
public void testTransactionClose() throws Exception
{
Company company = getModel1Factory().createCompany();
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
index bb9a1c2023..e2e2aa0924 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
@@ -184,7 +184,12 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
*/
public CDOLock cdoReadLock()
{
- if (FSMUtil.isTransient(this) || FSMUtil.isNew(this))
+ if (FSMUtil.isTransient(this))
+ {
+ throw new IllegalStateException("Call CDOView.lockObjects() for transient object " + this);
+ }
+
+ if (FSMUtil.isNew(this))
{
return CDOLockImpl.NOOP;
}
@@ -197,7 +202,12 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
*/
public CDOLock cdoWriteLock()
{
- if (FSMUtil.isTransient(this) || FSMUtil.isNew(this))
+ if (FSMUtil.isTransient(this))
+ {
+ throw new IllegalStateException("Call CDOView.lockObjects() for transient object " + this);
+ }
+
+ if (FSMUtil.isNew(this))
{
return CDOLockImpl.NOOP;
}
@@ -210,7 +220,12 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
*/
public CDOLock cdoWriteOption()
{
- if (FSMUtil.isTransient(this) || FSMUtil.isNew(this))
+ if (FSMUtil.isTransient(this))
+ {
+ throw new IllegalStateException("Call CDOView.lockObjects() for transient object " + this);
+ }
+
+ if (FSMUtil.isNew(this))
{
return CDOLockImpl.NOOP;
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapper.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapper.java
index f0c3d8f120..1ed94f3a5e 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapper.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDOObjectWrapper.java
@@ -177,7 +177,12 @@ public abstract class CDOObjectWrapper implements InternalCDOObject
*/
public CDOLock cdoReadLock()
{
- if (FSMUtil.isTransient(this) || FSMUtil.isNew(this))
+ if (FSMUtil.isTransient(this))
+ {
+ throw new IllegalStateException("Call CDOView.lockObjects() for transient object " + this);
+ }
+
+ if (FSMUtil.isNew(this))
{
return CDOLockImpl.NOOP;
}
@@ -190,7 +195,12 @@ public abstract class CDOObjectWrapper implements InternalCDOObject
*/
public CDOLock cdoWriteLock()
{
- if (FSMUtil.isTransient(this) || FSMUtil.isNew(this))
+ if (FSMUtil.isTransient(this))
+ {
+ throw new IllegalStateException("Call CDOView.lockObjects() for transient object " + this);
+ }
+
+ if (FSMUtil.isNew(this))
{
return CDOLockImpl.NOOP;
}
@@ -203,7 +213,12 @@ public abstract class CDOObjectWrapper implements InternalCDOObject
*/
public CDOLock cdoWriteOption()
{
- if (FSMUtil.isTransient(this) || FSMUtil.isNew(this))
+ if (FSMUtil.isTransient(this))
+ {
+ throw new IllegalStateException("Call CDOView.lockObjects() for transient object " + this);
+ }
+
+ if (FSMUtil.isNew(this))
{
return CDOLockImpl.NOOP;
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
index 5f1608b8c5..0968432db1 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
@@ -2269,6 +2269,23 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
return rev;
}
+ @Override
+ protected InternalCDORevision getRevision(CDOObject object)
+ {
+ if (object.cdoState() == CDOState.TRANSIENT)
+ {
+ InternalCDORevision revision = cleanRevisions.get(object);
+ if (revision == null)
+ {
+ throw new IllegalStateException("No revision for transient object " + object);
+ }
+
+ return revision;
+ }
+
+ return super.getRevision(object);
+ }
+
private final class ResolvingRevisionMap extends HashMap<InternalCDOObject, InternalCDORevision>
{
private static final long serialVersionUID = 1L;
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
index ad78f2bfa6..5f4d77d889 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
@@ -14,6 +14,7 @@ package org.eclipse.emf.internal.cdo.view;
import org.eclipse.emf.cdo.CDONotification;
import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.branch.CDOBranchPoint;
import org.eclipse.emf.cdo.common.id.CDOID;
@@ -259,14 +260,9 @@ public class CDOViewImpl extends AbstractCDOView
List<InternalCDORevision> revisions = new LinkedList<InternalCDORevision>();
for (CDOObject object : objects)
{
- if (!FSMUtil.isNew(object))
+ InternalCDORevision revision = getRevision(object);
+ if (revision != null)
{
- InternalCDORevision revision = (InternalCDORevision)object.cdoRevision();
- if (revision == null)
- {
- revision = CDOStateMachine.INSTANCE.read((InternalCDOObject)object);
- }
-
revisions.add(revision);
}
}
@@ -303,6 +299,22 @@ public class CDOViewImpl extends AbstractCDOView
}
}
+ protected InternalCDORevision getRevision(CDOObject object)
+ {
+ if (object.cdoState() == CDOState.NEW)
+ {
+ return null;
+ }
+
+ InternalCDORevision revision = (InternalCDORevision)object.cdoRevision();
+ if (revision == null)
+ {
+ revision = CDOStateMachine.INSTANCE.read((InternalCDOObject)object);
+ }
+
+ return revision;
+ }
+
/**
* @since 2.0
*/

Back to the top