summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEgidijus Vaishnora2011-09-19 04:14:00 (EDT)
committerEgidijus Vaishnora2011-09-19 04:14:00 (EDT)
commit5429686a393775048194827da329c3de9a77db6d (patch)
tree8396eaddf72e00f4b52997f68b2b7c87b36bc507
parent410124d25df48bd6d0d58901d990c23ae73f8030 (diff)
downloadcdo-5429686a393775048194827da329c3de9a77db6d.zip
cdo-5429686a393775048194827da329c3de9a77db6d.tar.gz
cdo-5429686a393775048194827da329c3de9a77db6d.tar.bz2
352832: CommitIntegrityCheck doesn't treat CDOIDNull as Java NULL value with CDOSetFeatureDelta
https://bugs.eclipse.org/bugs/show_bug.cgi?id=352832
-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_352832_Test.java108
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java16
3 files changed, 117 insertions, 8 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 c098ddc..092daf8 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
@@ -239,6 +239,7 @@ public abstract class AllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_351393_Test.class);
testClasses.add(Bugzilla_351921_Test.class);
testClasses.add(Bugzilla_352303_Test.class);
+ testClasses.add(Bugzilla_352832_Test.class);
testClasses.add(Bugzilla_354395_Test.class);
testClasses.add(Bugzilla_355915_Test.class);
testClasses.add(Bugzilla_357441_Test.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_352832_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_352832_Test.java
new file mode 100644
index 0000000..87d9936
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_352832_Test.java
@@ -0,0 +1,108 @@
+/**
+ * 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+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.model4.RefSingleNonContained;
+import org.eclipse.emf.cdo.tests.model4.SingleNonContainedElement;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.util.CommitException;
+import org.eclipse.emf.cdo.util.CommitIntegrityException;
+
+import org.eclipse.emf.internal.cdo.util.CommitIntegrityCheck;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.spi.cdo.CDOStore;
+import org.eclipse.emf.spi.cdo.InternalCDOTransaction;
+import org.eclipse.emf.spi.cdo.InternalCDOTransaction.InternalCDOCommitContext;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * @author Eike Stepper
+ */
+public class Bugzilla_352832_Test extends AbstractCDOTest
+{
+
+ public void testNewSingle() throws CommitException
+ {
+ CDOSession session1 = openSession();
+ CDOTransaction transaction1 = session1.openTransaction();
+ CDOResource resource = transaction1.createResource(getResourcePath("test"));
+ SingleNonContainedElement singleNonContainedElement = getModel4Factory().createSingleNonContainedElement();
+ RefSingleNonContained refSingleNonContained = getModel4Factory().createRefSingleNonContained();
+ resource.getContents().add(singleNonContainedElement);
+ resource.getContents().add(refSingleNonContained);
+ transaction1.commit();
+
+ // STEP 1 Setting parent feature to point REF
+ CDORevision cdoRevision = CDOUtil.getCDOObject(singleNonContainedElement).cdoRevision();
+ // here is real Java NULL
+ assertEquals(null,
+ cdoRevision.data().get(getModel4Package().getSingleNonContainedElement_Parent(), CDOStore.NO_INDEX));
+ singleNonContainedElement.setParent(refSingleNonContained);
+ transaction1.setCommittables(new HashSet<EObject>(Arrays.asList(new EObject[] { singleNonContainedElement,
+ refSingleNonContained })));
+ checkPartialCommitIntegrity((InternalCDOTransaction)transaction1);
+ transaction1.commit();
+
+ // STEP 2 Setting parent feature to point NULL
+ CDOSession session2 = openSession();
+ InternalCDOTransaction transaction2 = (InternalCDOTransaction)session2.openTransaction();
+ SingleNonContainedElement singleNonContainedElement2 = (SingleNonContainedElement)CDOUtil.getEObject(transaction2
+ .getObject(CDOUtil.getCDOObject(singleNonContainedElement).cdoID()));
+ RefSingleNonContained refSingleNonContained2 = singleNonContainedElement2.getParent();
+ singleNonContainedElement2.setParent(null);
+ cdoRevision = CDOUtil.getCDOObject(singleNonContainedElement2).cdoRevision();
+ // here is real Java NULL after setting
+ assertEquals(null,
+ cdoRevision.data().get(getModel4Package().getSingleNonContainedElement_Parent(), CDOStore.NO_INDEX));
+ transaction2.setCommittables(new HashSet<EObject>(Arrays.asList(new EObject[] { singleNonContainedElement2,
+ refSingleNonContained2 })));
+ checkPartialCommitIntegrity(transaction2);
+ transaction2.commit();
+ session2.close();
+
+ // STEP 3 Setting parent feature to point REF
+ session2 = openSession();
+ transaction2 = (InternalCDOTransaction)session2.openTransaction();
+ singleNonContainedElement2 = (SingleNonContainedElement)CDOUtil.getEObject(transaction2.getObject(CDOUtil
+ .getCDOObject(singleNonContainedElement).cdoID()));
+ refSingleNonContained2 = (RefSingleNonContained)CDOUtil.getEObject(transaction2.getObject(CDOUtil.getCDOObject(
+ refSingleNonContained).cdoID()));
+
+ cdoRevision = CDOUtil.getCDOObject(singleNonContainedElement2).cdoRevision();
+ // from server loaded revision has CDO NULL ID, which has meaning of the same Java NULL. Identical situation when in
+ // STEP 1
+ assertEquals(CDOID.NULL,
+ cdoRevision.data().get(getModel4Package().getSingleNonContainedElement_Parent(), CDOStore.NO_INDEX));
+ singleNonContainedElement2.setParent(refSingleNonContained2);
+ transaction2.setCommittables(new HashSet<EObject>(Arrays.asList(new EObject[] { singleNonContainedElement2,
+ refSingleNonContained2 })));
+ checkPartialCommitIntegrity(transaction2);
+ transaction2.commit();
+
+ session2.close();
+ }
+
+ private void checkPartialCommitIntegrity(InternalCDOTransaction tx) throws CommitIntegrityException
+ {
+ InternalCDOCommitContext ctx = tx.createCommitContext();
+ new CommitIntegrityCheck(ctx, CommitIntegrityCheck.Style.EXCEPTION_FAST).check();
+
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java
index dfa281f..bf41020 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CommitIntegrityCheck.java
@@ -238,30 +238,30 @@ public class CommitIntegrityCheck
Object idOrObject = ((CDOAddFeatureDelta)featureDelta).getValue();
if (containmentOrWithOpposite || isNew(idOrObject))
{
- checkIncluded(idOrObject, "added child/refTarget of", dirtyObject);
+ checkIncluded(idOrObject, "added child / refTarget of", dirtyObject);
}
}
else if (featureDelta instanceof CDOSetFeatureDelta)
{
- Object newIDOrObject = ((CDOSetFeatureDelta)featureDelta).getValue();
Object oldIDOrObject = ((CDOSetFeatureDelta)featureDelta).getOldValue();
CDOID oldID = (CDOID)transaction.convertObjectToID(oldIDOrObject);
- if (oldIDOrObject != null)
+ if (!CDOIDUtil.isNull(oldID))
{
// Old child must be included if it's the container or has an eOpposite
if (containmentOrWithOpposite)
{
- checkIncluded(oldID, "removed/former child/refTarget of", dirtyObject);
+ checkIncluded(oldID, "removed / former child / refTarget of", dirtyObject);
}
}
+ Object newIDOrObject = ((CDOSetFeatureDelta)featureDelta).getValue();
if (newIDOrObject != null)
{
// New child must be included
newIDOrObject = transaction.convertObjectToID(newIDOrObject);
if (containmentOrWithOpposite || isNew(newIDOrObject))
{
- checkIncluded(newIDOrObject, "new child/refTarget of", dirtyObject);
+ checkIncluded(newIDOrObject, "new child / refTarget of", dirtyObject);
}
}
}
@@ -271,7 +271,7 @@ public class CommitIntegrityCheck
{
Object idOrObject = ((CDORemoveFeatureDelta)featureDelta).getValue();
CDOID id = (CDOID)transaction.convertObjectToID(idOrObject);
- checkIncluded(id, "removed child/refTarget of", dirtyObject);
+ checkIncluded(id, "removed child / refTarget of", dirtyObject);
}
else if (featureDelta instanceof CDOClearFeatureDelta)
{
@@ -282,7 +282,7 @@ public class CommitIntegrityCheck
{
Object idOrObject = cleanRev.get(feat, i);
CDOID id = (CDOID)transaction.convertObjectToID(idOrObject);
- checkIncluded(id, "removed child/refTarget of", dirtyObject);
+ checkIncluded(id, "removed child / refTarget of", dirtyObject);
}
}
else if (featureDelta instanceof CDOUnsetFeatureDelta)
@@ -291,7 +291,7 @@ public class CommitIntegrityCheck
InternalCDORevision cleanRev = transaction.getCleanRevisions().get(dirtyObject);
Object idOrObject = cleanRev.getValue(feat);
CDOID id = (CDOID)transaction.convertObjectToID(idOrObject);
- checkIncluded(id, "removed child/refTarget of", dirtyObject);
+ checkIncluded(id, "removed child / refTarget of", dirtyObject);
}
else if (featureDelta instanceof CDOMoveFeatureDelta)
{