summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-01-05 15:19:10 (EST)
committerEike Stepper2008-01-05 15:19:10 (EST)
commitc82f6a98dcad0356f5d6a25e3ff2da0adec6b0bd (patch)
treedd716da7da2b5d6759a93520ad71806d1347d85c
parente29db8e84118d0fc318aa6260b55e7c9fa9689a1 (diff)
downloadcdo-c82f6a98dcad0356f5d6a25e3ff2da0adec6b0bd.zip
cdo-c82f6a98dcad0356f5d6a25e3ff2da0adec6b0bd.tar.gz
cdo-c82f6a98dcad0356f5d6a25e3ff2da0adec6b0bd.tar.bz2
[214374] Sending deltas doesn't adjust CDOIDs
https://bugs.eclipse.org/bugs/show_bug.cgi?id=214374
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTests.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BugzillasTest.java63
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/IndexReconstructionTest.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionDeltaTest.java40
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/CommitTransactionRequest.java6
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/RevisionAdjuster.java83
6 files changed, 132 insertions, 65 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTests.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTests.java
index a99c646..e9bd142 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTests.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTests.java
@@ -34,6 +34,7 @@ public class AllTests
suite.addTestSuite(TransactionDeadLockTest.class);
suite.addTestSuite(PackageRegistryTest.class);
suite.addTestSuite(RevisionDeltaTest.class);
+ suite.addTestSuite(IndexReconstructionTest.class);
// TODO suite.addTestSuite(GeneratedEcoreTest.class);
// $JUnit-END$
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BugzillasTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BugzillasTest.java
deleted file mode 100644
index 2dba7aa..0000000
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/BugzillasTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * 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;
-
-import org.eclipse.emf.cdo.CDOSession;
-import org.eclipse.emf.cdo.CDOTransaction;
-import org.eclipse.emf.cdo.eresource.CDOResource;
-import org.eclipse.emf.cdo.protocol.CDOID;
-import org.eclipse.emf.cdo.protocol.model.CDOFeature;
-import org.eclipse.emf.cdo.protocol.revision.CDORevision;
-import org.eclipse.emf.cdo.tests.model1.Customer;
-import org.eclipse.emf.cdo.tests.model1.Model1Factory;
-import org.eclipse.emf.cdo.tests.model1.Model1Package;
-import org.eclipse.emf.cdo.tests.model1.SalesOrder;
-
-import junit.framework.Assert;
-
-/**
- * @author Eike Stepper
- */
-public class BugzillasTest extends AbstractCDOTest
-{
- /**
- * Sending deltas doesn't adjust CDOIDs
- *
- * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=214374
- */
- public void test214374() throws Exception
- {
- CDOSession session = openModel1Session();
- CDOTransaction transaction = session.openTransaction();
- CDOResource resource = transaction.createResource("/test1");
-
- SalesOrder salesOrder = Model1Factory.eINSTANCE.createSalesOrder();
- resource.getContents().add(salesOrder);
- transaction.commit();
-
- Customer customer = Model1Factory.eINSTANCE.createCustomer();
- salesOrder.setCustomer(customer);
-
- resource.getContents().add(customer);
- transaction.commit();
- transaction.close();
-
- CDOTransaction transaction2 = session.openTransaction();
- SalesOrder salesOrder2 = (SalesOrder)transaction2.getObject(salesOrder.cdoID(), true);
- CDORevision salesRevision = salesOrder2.cdoRevision();
- CDOFeature customerFeature = session.getPackageManager().convert(Model1Package.eINSTANCE.getSalesOrder_Customer());
-
- Object value = salesRevision.getData().get(customerFeature, 0);
- Assert.assertEquals(true, value instanceof CDOID);
- transaction2.close();
- session.close();
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/IndexReconstructionTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/IndexReconstructionTest.java
index bbfe0c8..cb23f10 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/IndexReconstructionTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/IndexReconstructionTest.java
@@ -430,7 +430,7 @@ public class IndexReconstructionTest extends AbstractCDOTest
{
if (featureDelta instanceof CDOListFeatureDeltaImpl)
{
- int[] indices = ((CDOListFeatureDeltaImpl)featureDelta).reconstructAddedIndices(null);
+ int[] indices = ((CDOListFeatureDeltaImpl)featureDelta).reconstructAddedIndices();
if (indices[0] != 0)
{
System.out.print(revisionDelta.getID());
@@ -471,7 +471,7 @@ public class IndexReconstructionTest extends AbstractCDOTest
{
if (featureDelta instanceof CDOListFeatureDeltaImpl)
{
- int[] indices = ((CDOListFeatureDeltaImpl)featureDelta).reconstructAddedIndices(null);
+ int[] indices = ((CDOListFeatureDeltaImpl)featureDelta).reconstructAddedIndices();
for (int i = 1; i <= indices[0]; i++)
{
ReconstructedIndex expectedIndex = new ReconstructedIndex(revisionDelta.getID(), featureDelta.getFeature(),
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionDeltaTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionDeltaTest.java
index 6c56f3b..8cc6b30 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionDeltaTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionDeltaTest.java
@@ -16,18 +16,25 @@ import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
import org.eclipse.emf.cdo.internal.protocol.revision.delta.CDOListFeatureDeltaImpl;
+import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+import org.eclipse.emf.cdo.protocol.revision.CDORevision;
import org.eclipse.emf.cdo.protocol.revision.delta.CDOAddFeatureDelta;
import org.eclipse.emf.cdo.protocol.revision.delta.CDOClearFeatureDelta;
import org.eclipse.emf.cdo.protocol.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.protocol.revision.delta.CDOSetFeatureDelta;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.tests.model1.Customer;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
import org.eclipse.emf.cdo.tests.model1.Model1Package;
+import org.eclipse.emf.cdo.tests.model1.SalesOrder;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.internal.cdo.InternalCDOObject;
+import junit.framework.Assert;
+
/**
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=201266
* @author Simon McDuff
@@ -91,6 +98,39 @@ public class RevisionDeltaTest extends AbstractCDOTest
session.close();
}
+ /**
+ * Sending deltas doesn't adjust CDOIDs
+ *
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=214374
+ */
+ public void testBugzilla214374() throws Exception
+ {
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource("/test1");
+
+ SalesOrder salesOrder = Model1Factory.eINSTANCE.createSalesOrder();
+ resource.getContents().add(salesOrder);
+ transaction.commit();
+
+ Customer customer = Model1Factory.eINSTANCE.createCustomer();
+ salesOrder.setCustomer(customer);
+
+ resource.getContents().add(customer);
+ transaction.commit();
+ transaction.close();
+
+ CDOTransaction transaction2 = session.openTransaction();
+ SalesOrder salesOrder2 = (SalesOrder)transaction2.getObject(salesOrder.cdoID(), true);
+ CDORevision salesRevision = salesOrder2.cdoRevision();
+ CDOFeature customerFeature = session.getPackageManager().convert(Model1Package.eINSTANCE.getSalesOrder_Customer());
+
+ Object value = salesRevision.getData().get(customerFeature, 0);
+ Assert.assertEquals(true, value instanceof CDOID);
+ transaction2.close();
+ session.close();
+ }
+
private CDORevisionImpl getCopyCDORevision(Object object)
{
return new CDORevisionImpl((CDORevisionImpl)((InternalCDOObject)object).cdoRevision());
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/CommitTransactionRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/CommitTransactionRequest.java
index efb0d71..bdacebd 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/CommitTransactionRequest.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/CommitTransactionRequest.java
@@ -28,6 +28,7 @@ import org.eclipse.emf.cdo.protocol.revision.delta.CDORevisionDelta;
import org.eclipse.emf.internal.cdo.CDOTransactionImpl;
import org.eclipse.emf.internal.cdo.InternalCDOObject;
import org.eclipse.emf.internal.cdo.bundle.OM;
+import org.eclipse.emf.internal.cdo.util.RevisionAdjuster;
import org.eclipse.net4j.channel.IChannel;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
@@ -171,10 +172,15 @@ public class CommitTransactionRequest extends CDOClientRequest<CommitTransaction
PROTOCOL.format("Writing {0} revision deltas", revisionDeltas.size());
}
+ RevisionAdjuster revisionAdjuster = new RevisionAdjuster(transaction);
out.writeInt(revisionDeltas.size());
for (CDORevisionDelta revisionDelta : revisionDeltas)
{
((CDORevisionDeltaImpl)revisionDelta).write(out, transaction);
+ // CDORevisionImpl revision = transaction.getRevision(revisionDelta.getID());
+ CDOObject object = transaction.getDirtyObjects().get(revisionDelta.getID());
+ CDORevisionImpl revision = (CDORevisionImpl)object.cdoRevision();
+ revisionAdjuster.adjustRevision(revision, revisionDelta);
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/RevisionAdjuster.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/RevisionAdjuster.java
new file mode 100644
index 0000000..462104c
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/RevisionAdjuster.java
@@ -0,0 +1,83 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+
+package org.eclipse.emf.internal.cdo.util;
+
+import org.eclipse.emf.cdo.internal.protocol.revision.CDOIDProvider;
+import org.eclipse.emf.cdo.internal.protocol.revision.CDORevisionImpl;
+import org.eclipse.emf.cdo.internal.protocol.revision.delta.CDOFeatureDeltaVisitorImpl;
+import org.eclipse.emf.cdo.internal.protocol.revision.delta.CDOListFeatureDeltaImpl;
+import org.eclipse.emf.cdo.protocol.model.CDOFeature;
+import org.eclipse.emf.cdo.protocol.revision.CDOReferenceProxy;
+import org.eclipse.emf.cdo.protocol.revision.delta.CDOAddFeatureDelta;
+import org.eclipse.emf.cdo.protocol.revision.delta.CDOListFeatureDelta;
+import org.eclipse.emf.cdo.protocol.revision.delta.CDORevisionDelta;
+import org.eclipse.emf.cdo.protocol.revision.delta.CDOSetFeatureDelta;
+
+import java.util.List;
+
+/**
+ * @author Simon McDuff
+ */
+public class RevisionAdjuster extends CDOFeatureDeltaVisitorImpl
+{
+ private CDOIDProvider idProvider;
+
+ private CDORevisionImpl revision;
+
+ public RevisionAdjuster(CDOIDProvider idProvider)
+ {
+ this.idProvider = idProvider;
+ }
+
+ public void adjustRevision(CDORevisionImpl revision, CDORevisionDelta revisionDelta)
+ {
+ this.revision = revision;
+ revisionDelta.accept(this);
+ }
+
+ @Override
+ public void visit(CDOAddFeatureDelta delta)
+ {
+ // Delta value must have been adjusted before!
+ revision.setValue(delta.getFeature(), delta.getValue());
+ }
+
+ @Override
+ public void visit(CDOSetFeatureDelta delta)
+ {
+ CDOFeature feature = delta.getFeature();
+ Object value = delta.getValue();
+ if (value != null && feature.isReference() && !(value instanceof CDOReferenceProxy))
+ {
+ revision.setValue(feature, idProvider.provideCDOID(value));
+ }
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void visit(CDOListFeatureDelta deltas)
+ {
+ CDOFeature feature = deltas.getFeature();
+ List<Object> list = (List<Object>)revision.getValue(feature);
+ int[] indices = ((CDOListFeatureDeltaImpl)deltas).reconstructAddedIndices();
+ for (int i = 1; i <= indices[0]; i++)
+ {
+ int index = indices[i];
+ Object value = list.get(index);
+ if (value != null && feature.isReference() && !(value instanceof CDOReferenceProxy))
+ {
+ value = idProvider.provideCDOID(value);
+ list.set(index, value);
+ }
+ }
+ }
+}