summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2010-05-11 04:55:02 (EDT)
committerCaspar De Groot2010-05-11 04:55:02 (EDT)
commit457df5ebaccf70454a79bda65e2f07500128513d (patch)
tree60254807b5615a561a391036627e74f9da196e53
parent5b7dbbd69b8730e1c96d8cec266e3b70ebfae51a (diff)
downloadcdo-457df5ebaccf70454a79bda65e2f07500128513d.zip
cdo-457df5ebaccf70454a79bda65e2f07500128513d.tar.gz
cdo-457df5ebaccf70454a79bda65e2f07500128513d.tar.bz2
[312205] After detach-reattach-rollback, object is not present in tx
https://bugs.eclipse.org/bugs/show_bug.cgi?id=312205
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_283985_SavePointTest.java33
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java32
2 files changed, 52 insertions, 13 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_283985_SavePointTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_283985_SavePointTest.java
index ef09046..a40ab22 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_283985_SavePointTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_283985_SavePointTest.java
@@ -15,9 +15,11 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
import org.eclipse.emf.cdo.tests.model1.Order;
import org.eclipse.emf.cdo.tests.model1.OrderDetail;
+import org.eclipse.emf.cdo.tests.model1.PurchaseOrder;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.util.CDOUtil;
@@ -140,4 +142,35 @@ public class Bugzilla_283985_SavePointTest extends AbstractCDOTest
assertTrue(order1.getOrderDetails().contains(detail1));
assertEquals(id, CDOUtil.getCDOObject(detail1).cdoID());
}
+
+ public void test4()
+ {
+ CDOSession session = openSession();
+ session.options().setPassiveUpdateEnabled(false);
+
+ CDOTransaction tx = session.openTransaction();
+ CDOResource r1 = tx.createResource("/r2");
+
+ Company company = Model1Factory.eINSTANCE.createCompany();
+ PurchaseOrder purchaseOrder = Model1Factory.eINSTANCE.createPurchaseOrder();
+ company.getPurchaseOrders().add(purchaseOrder);
+ r1.getContents().add(company);
+ tx.commit();
+
+ CDOID id = CDOUtil.getCDOObject(purchaseOrder).cdoID();
+ assertSame(tx.getObject(id), purchaseOrder);
+
+ // Detach
+ company.getPurchaseOrders().remove(purchaseOrder);
+
+ // And re-attach
+ company.getPurchaseOrders().add(purchaseOrder);
+ assertSame(tx.getObject(id), purchaseOrder);
+
+ tx.rollback();
+ assertSame(tx.getObject(id), purchaseOrder);
+
+ tx.close();
+ session.close();
+ }
}
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 2af23e5..5834cc4 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
@@ -130,6 +130,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -966,10 +967,17 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
// Rollback new objects created after the save point
removeObjects(itrSavepoint.getNewObjects().values());
- // Bug 283985 (Re-attachment): Objects that were reattached must
- // also be removed
- Collection<CDOObject> reattachedObjects = itrSavepoint.getReattachedObjects().values();
- removeObjects(reattachedObjects);
+ Set<CDOID> detachedIDs = itrSavepoint.getDetachedObjects().keySet();
+ List<CDOObject> reattachedNotDetachedObjects = new ArrayList<CDOObject>();
+ for (CDOObject reattachedObject : itrSavepoint.getReattachedObjects().values())
+ {
+ if (!detachedIDs.contains(reattachedObject.cdoID()))
+ {
+ reattachedNotDetachedObjects.add(reattachedObject);
+ }
+ }
+
+ removeObjects(reattachedNotDetachedObjects);
Map<CDOID, CDORevisionDelta> revisionDeltas = itrSavepoint.getRevisionDeltas();
if (!revisionDeltas.isEmpty())
@@ -984,10 +992,10 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
}
// Rollback all persisted objects
- Map<CDOID, CDOObject> detachedObjects = itrSavepoint.getDetachedObjects();
- if (!detachedObjects.isEmpty())
+ Map<CDOID, CDOObject> detachedObjectsMap = itrSavepoint.getDetachedObjects();
+ if (!detachedObjectsMap.isEmpty())
{
- for (Entry<CDOID, CDOObject> entryDirty : detachedObjects.entrySet())
+ for (Entry<CDOID, CDOObject> entryDirty : detachedObjectsMap.entrySet())
{
if (entryDirty.getKey().isTemporary())
{
@@ -1008,11 +1016,9 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
{
InternalCDOObject internalDirtyObject = (InternalCDOObject)entryDirtyObject.getValue();
- // Bug 283985 (Re-attachment): Skip objects that were
- // reattached, because
- // they were already reset to TRANSIENT earlier in this
- // method
- if (!reattachedObjects.contains(internalDirtyObject))
+ // Bug 283985 (Re-attachment): Skip objects that were reattached, because
+ // they were already reset to TRANSIENT earlier in this method
+ if (!itrSavepoint.getReattachedObjects().values().contains(internalDirtyObject))
{
CDOStateMachine.INSTANCE.rollback(internalDirtyObject);
}
@@ -1790,7 +1796,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
/**
* Bug 298561: This override removes references to remotely detached objects that are present in any DIRTY or NEW
* objects.
- *
+ *
* @since 3.0
*/
@Override