summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-04-20 02:01:55 (EDT)
committerCaspar De Groot2011-04-20 02:01:55 (EDT)
commite58d1941e700321130ffa8944ebde3eebb582d7e (patch)
tree0456f0754308e77467bc9e7e3f24c0faee19f40a
parent18ad18d6b3bf0f089f8c3ff9f8367652f1cdb1ea (diff)
downloadcdo-e58d1941e700321130ffa8944ebde3eebb582d7e.zip
cdo-e58d1941e700321130ffa8944ebde3eebb582d7e.tar.gz
cdo-e58d1941e700321130ffa8944ebde3eebb582d7e.tar.bz2
[Bug 343332] CDOTransactionHandler1.attachingObject doesn't get called for re-attachments
https://bugs.eclipse.org/bugs/show_bug.cgi?id=343332
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_343332_Test.java93
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java16
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java3
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOTransaction.java5
5 files changed, 111 insertions, 7 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
index ae6ea18..4d8d2b4 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllConfigs.java
@@ -220,5 +220,6 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_341875_Test.class);
testClasses.add(Bugzilla_342130_Test.class);
testClasses.add(Bugzilla_342135_Test.class);
+ testClasses.add(Bugzilla_343332_Test.class);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_343332_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_343332_Test.java
new file mode 100644
index 0000000..6942c69
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_343332_Test.java
@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2004 - 2011 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:
+ * Egidijus Vaisnora - initial API and implementation
+ * Caspar De Groot - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
+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.Category;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.transaction.CDOTransactionHandler1;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CommitException;
+
+import org.eclipse.emf.ecore.util.EcoreUtil;
+
+import org.junit.Assert;
+
+import java.text.MessageFormat;
+
+/**
+ * @author Egidijus Vaisnora, Caspar De Groot
+ */
+public class Bugzilla_343332_Test extends AbstractCDOTest
+{
+ public void test() throws CommitException
+ {
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource(getResourcePath("test"));
+
+ Category category1 = getModel1Factory().createCategory();
+ resource.getContents().add(category1);
+
+ category1.getCategories().add(getModel1Factory().createCategory());
+
+ Category category2 = getModel1Factory().createCategory();
+ resource.getContents().add(category2);
+
+ transaction.commit();
+ session.close();
+ }
+
+ {
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+
+ final CDOObject[] attachedObject = new CDOObject[1];
+ transaction.addTransactionHandler(new CDOTransactionHandler1()
+ {
+ public void modifyingObject(CDOTransaction transaction, CDOObject object, CDOFeatureDelta featureDelta)
+ {
+ }
+
+ public void detachingObject(CDOTransaction transaction, CDOObject object)
+ {
+ }
+
+ public void attachingObject(CDOTransaction transaction, CDOObject object)
+ {
+ attachedObject[0] = object;
+ }
+ });
+
+ CDOResource resource = transaction.getResource(getResourcePath("test"));
+ Category c1 = (Category)resource.getContents().get(0);
+ Category nestedCategory = c1.getCategories().get(0);
+ CDOObject cdoCategory = CDOUtil.getCDOObject(nestedCategory);
+
+ // Detach
+ EcoreUtil.remove(nestedCategory);
+
+ // Re-attach
+ attachedObject[0] = null;
+ ((Category)resource.getContents().get(1)).getCategories().add(nestedCategory);
+
+ Assert.assertNotNull("CDOTransactionHandler1.attachingObject was not called", attachedObject[0]);
+ Assert.assertEquals(MessageFormat.format("Re-attached object was not the expected object {0}", cdoCategory),
+ cdoCategory, attachedObject[0]);
+ }
+ }
+}
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 668e8b2..4b76dbf 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
@@ -566,7 +566,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
object.cdoInternalPostLoad();
registerObject(object);
- registerNew(object);
+ registerAttached(object, true);
result.add(revision);
dirty = true;
}
@@ -1486,14 +1486,17 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
return "CDOTransaction"; //$NON-NLS-1$
}
- public synchronized void registerNew(InternalCDOObject object)
+ public synchronized void registerAttached(InternalCDOObject object, boolean isNew)
{
if (TRACER.isEnabled())
{
TRACER.format("Registering new object {0}", object); //$NON-NLS-1$
}
- registerNewPackage(object.eClass().getEPackage());
+ if (isNew)
+ {
+ registerNewPackage(object.eClass().getEPackage());
+ }
CDOTransactionHandler1[] handlers = getTransactionHandlers1();
if (handlers != null)
@@ -1505,7 +1508,10 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
}
}
- registerNew(lastSavepoint.getNewObjects(), object);
+ if (isNew)
+ {
+ registerNew(lastSavepoint.getNewObjects(), object);
+ }
}
private void registerNewPackage(EPackage ePackage)
@@ -1860,7 +1866,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
{
InternalCDOObject object = newInstance(revision);
registerObject(object);
- registerNew(object);
+ registerAttached(object, true);
}
// Apply deltas
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
index bea9417..ec80f43 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStateMachine.java
@@ -545,9 +545,10 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
// Register object
transaction.registerObject(object);
- transaction.registerNew(object);
}
+ transaction.registerAttached(object, !reattaching);
+
// Prepare content tree
for (Iterator<InternalCDOObject> it = getProperContents(object, transaction); it.hasNext();)
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOTransaction.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOTransaction.java
index 2fa0f70..bfa6213 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOTransaction.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/spi/cdo/InternalCDOTransaction.java
@@ -74,7 +74,10 @@ public interface InternalCDOTransaction extends CDOTransaction, InternalCDOUserT
public CDOIDTemp getNextTemporaryID();
- public void registerNew(InternalCDOObject object);
+ /**
+ * @since 4.0
+ */
+ public void registerAttached(InternalCDOObject object, boolean isNew);
public void registerDirty(InternalCDOObject object, CDOFeatureDelta featureDelta);