summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Schedl2013-09-13 01:38:26 (EDT)
committer Eike Stepper2013-09-13 02:13:35 (EDT)
commit31c9b50ed9d3a82627843e3be2c0569da2426519 (patch)
tree66b9b74ed54cae37fb12bec00e2baa2c5619b613
parentd40b9ab44acc6301c49758e477c286e01785a0de (diff)
downloadcdo-31c9b50ed9d3a82627843e3be2c0569da2426519.zip
cdo-31c9b50ed9d3a82627843e3be2c0569da2426519.tar.gz
cdo-31c9b50ed9d3a82627843e3be2c0569da2426519.tar.bz2
[415077] Transaction could not be commited if a new object is locked
https://bugs.eclipse.org/bugs/show_bug.cgi?id=415077 Signed-off-by: Stefan Schedl <stefan.schedl@metasonic.de>
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_415077_Test.java59
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java14
2 files changed, 66 insertions, 7 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_415077_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_415077_Test.java
new file mode 100644
index 0000000..2a57cab
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_415077_Test.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 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:
+ * Stefan Schedl - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractLockingTest;
+import org.eclipse.emf.cdo.tests.LockingNotificationsTest;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CommitException;
+
+/**
+ * Bug 415077 - Transaction could not be commited if a new object is locked.
+ * <p>
+ * Testcase adapted from {@link LockingNotificationsTest#testLockStateNewAndTransient()}.
+ *
+ * @author Stefan Schedl
+ */
+public class Bugzilla_415077_Test extends AbstractLockingTest
+{
+ public void testReadLockOnNewAndTransientObject() throws CommitException
+ {
+ CDOObject company = CDOUtil.getCDOObject(getModel1Factory().createCompany());
+ assertTransient(company);
+ assertNull(company.cdoLockState());
+
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("r1"));
+ resource.getContents().add(company);
+ assertNew(company, transaction);
+ assertNotNull(company.cdoLockState());
+
+ company.cdoReadLock().lock();
+
+ resource.getContents().remove(company);
+ assertTransient(company);
+ assertNull(company.cdoLockState());
+
+ resource.getContents().add(company);
+ transaction.commit();
+ assertClean(company, transaction);
+ assertNotNull(company.cdoLockState());
+
+ resource.getContents().remove(company);
+ assertTransient(company);
+ assertNull(company.cdoLockState());
+ }
+}
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 02c5991..1a3fec2 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
@@ -105,7 +105,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.WeakHashMap;
/**
* @author Eike Stepper
@@ -128,7 +127,7 @@ public class CDOViewImpl extends AbstractCDOView
private long lastUpdateTime;
- private Map<CDOObject, CDOLockState> lockStates = new WeakHashMap<CDOObject, CDOLockState>();
+ private Map<CDOID, CDOLockState> lockStates = new HashMap<CDOID, CDOLockState>();
private QueueRunner invalidationRunner;
@@ -404,7 +403,7 @@ public class CDOViewImpl extends AbstractCDOView
InternalCDOObject object = getObject(id, false);
if (object != null)
{
- InternalCDOLockState existingLockState = (InternalCDOLockState)lockStates.get(object);
+ InternalCDOLockState existingLockState = (InternalCDOLockState)getLockState(object);
if (existingLockState != null)
{
Object lockTarget = getLockTarget(object);
@@ -412,7 +411,7 @@ public class CDOViewImpl extends AbstractCDOView
}
else
{
- lockStates.put(object, lockState);
+ lockStates.put(object.cdoID(), lockState);
}
}
}
@@ -745,7 +744,7 @@ public class CDOViewImpl extends AbstractCDOView
InternalCDOObject obj = getObject(id, false);
if (obj != null)
{
- lockState = this.lockStates.get(obj);
+ lockState = getLockState(obj);
}
if (lockState != null)
@@ -762,6 +761,7 @@ public class CDOViewImpl extends AbstractCDOView
{
CDOSessionProtocol sessionProtocol = session.getSessionProtocol();
CDOLockState[] loadedLockStates = sessionProtocol.getLockStates(viewID, missing);
+ updateLockStates(loadedLockStates);
for (CDOLockState loadedLockState : loadedLockStates)
{
lockStates.add(loadedLockState);
@@ -773,12 +773,12 @@ public class CDOViewImpl extends AbstractCDOView
protected CDOLockState removeLockState(CDOObject object)
{
- return lockStates.remove(object);
+ return lockStates.remove(object.cdoID());
}
protected CDOLockState getLockState(CDOObject object)
{
- return lockStates.get(object);
+ return lockStates.get(object.cdoID());
}
private CDOBranchPoint getBranchPointForID(CDOID id)