diff options
author | Eike Stepper | 2016-10-05 10:10:22 +0000 |
---|---|---|
committer | Eike Stepper | 2016-10-05 10:10:22 +0000 |
commit | de192b0abbde6c721f376da4c747cd74f2a053c9 (patch) | |
tree | 9ffe68af07b3581889a1915ecaccbcd0eead12fd | |
parent | 1f78f3ad6653cf1065861198ada3c81aaf9d41b2 (diff) | |
download | cdo-de192b0abbde6c721f376da4c747cd74f2a053c9.tar.gz cdo-de192b0abbde6c721f376da4c747cd74f2a053c9.tar.xz cdo-de192b0abbde6c721f376da4c747cd74f2a053c9.zip |
[503564] Creation of CDOSetFeatureDeltaImpl in CDOStoreImp mixes EMF-Type and CDO-Type values
https://bugs.eclipse.org/bugs/show_bug.cgi?id=503564
3 files changed, 102 insertions, 5 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_503564_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_503564_Test.java new file mode 100644 index 0000000000..7734f58f9d --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_503564_Test.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2016 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.eresource.CDOResource; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.tests.AbstractCDOTest; +import org.eclipse.emf.cdo.tests.model1.PurchaseOrder; +import org.eclipse.emf.cdo.tests.model1.Supplier; +import org.eclipse.emf.cdo.tests.util.TestAdapter; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.emf.common.notify.Notification; + +/** + * Bug 503564 - Creation of CDOSetFeatureDeltaImpl in CDOStoreImp mixes EMF-Type and CDO-Type values + * + * @author Eike Stepper + */ +public class Bugzilla_503564_Test extends AbstractCDOTest +{ + public void testSetFeatureDelta_String() throws Exception + { + Supplier object = getModel1Factory().createSupplier(); + object.setName("Old Name"); + + CDOSession session = openSession(); + CDOTransaction transaction = session.openTransaction(); + CDOResource resource = transaction.getOrCreateResource(getResourcePath("/test1")); + resource.getContents().add(object); + transaction.commit(); + + CDOView controlView = session.openView(); + Supplier controlObject = controlView.getObject(object); + assertEquals("Old Name", controlObject.getName()); + + TestAdapter adapter = new TestAdapter(); + controlObject.eAdapters().add(adapter); + + object.setName("New Name"); + commitAndSync(transaction, controlView); + + Notification[] notifications = adapter.getNotifications(); + assertEquals(1, notifications.length); + + Object oldValue = notifications[0].getOldValue(); + assertEquals("Old Name", oldValue); + } + + public void testSetFeatureDelta_CDOID() throws Exception + { + Supplier oldSupplier = getModel1Factory().createSupplier(); + PurchaseOrder object = getModel1Factory().createPurchaseOrder(); + object.setSupplier(oldSupplier); + + CDOSession session = openSession(); + CDOTransaction transaction = session.openTransaction(); + CDOResource resource = transaction.getOrCreateResource(getResourcePath("/test1")); + resource.getContents().add(object); + resource.getContents().add(oldSupplier); + transaction.commit(); + + CDOView controlView = session.openView(); + PurchaseOrder controlObject = controlView.getObject(object); + Supplier controlOldSupplier = controlView.getObject(oldSupplier); + assertEquals(controlOldSupplier, controlObject.getSupplier()); + + TestAdapter adapter = new TestAdapter(); + controlObject.eAdapters().add(adapter); + + Supplier newSupplier = getModel1Factory().createSupplier(); + resource.getContents().add(newSupplier); + object.setSupplier(newSupplier); + commitAndSync(transaction, controlView); + + Notification[] notifications = adapter.getNotifications(); + assertEquals(1, notifications.length); + + Object oldValue = notifications[0].getOldValue(); + assertEquals(controlOldSupplier, oldValue); + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java index c670261eb9..2dddf8cd89 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/CDONotificationBuilder.java @@ -155,7 +155,13 @@ public class CDONotificationBuilder extends CDOFeatureDeltaVisitorImpl public void visit(CDOSetFeatureDelta delta) { EStructuralFeature feature = delta.getFeature(); - Object oldValue = getOldValue(feature); + + Object oldValue = delta.getOldValue(); + if (oldValue == null) + { + oldValue = getOldValue(feature); + } + if (oldValue instanceof CDOID) { CDOID oldID = (CDOID)oldValue; diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStoreImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStoreImpl.java index b5e8fb5787..93541dd8da 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStoreImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOStoreImpl.java @@ -247,6 +247,7 @@ public final class CDOStoreImpl implements CDOStore value = convertToEMF(eObject, revision, feature, NO_INDEX, value); Object defaultValue = feature.getDefaultValue(); + return !ObjectUtil.equals(value, defaultValue); } finally @@ -564,12 +565,12 @@ public final class CDOStoreImpl implements CDOStore // TODO: Use writeRevision() result!! InternalCDORevision oldRevision = readRevision(cdoObject); Object oldValue = oldRevision.get(feature, index); - oldValue = convertToEMF(eObject, oldRevision, feature, index, oldValue); + Object resultValue = convertToEMF(eObject, oldRevision, feature, index, oldValue); CDOFeatureDelta delta = new CDOSetFeatureDeltaImpl(feature, index, value, oldValue); writeRevision(cdoObject, delta); - return oldValue; + return resultValue; } finally { @@ -950,8 +951,7 @@ public final class CDOStoreImpl implements CDOStore } Object oldValue = revision.get(feature, index); - oldValue = convertToEMF(eObject, revision, feature, index, oldValue); - return oldValue; + return convertToEMF(eObject, revision, feature, index, oldValue); } private static InternalCDORevision readRevision(InternalCDOObject cdoObject) |