summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-11-08 03:14:34 (EST)
committerEike Stepper2007-11-08 03:14:34 (EST)
commit6599c34e3d469134aac4e6365e43c193c230bc6d (patch)
tree09bdb2816feb70714d551065cb733c9b74135eea
parent8b8a446a2b4ce09ec9b158793c87f8602a2a9883 (diff)
downloadcdo-6599c34e3d469134aac4e6365e43c193c230bc6d.zip
cdo-6599c34e3d469134aac4e6365e43c193c230bc6d.tar.gz
cdo-6599c34e3d469134aac4e6365e43c193c230bc6d.tar.bz2
Made CDOView.hasConflict() public
Adde RollbackTest
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java105
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java6
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java21
3 files changed, 123 insertions, 9 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java
new file mode 100644
index 0000000..2f7f404
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java
@@ -0,0 +1,105 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 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.tests.model1.Category;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.tests.model1.Model1Factory;
+import org.eclipse.emf.cdo.tests.model1.Model1Package;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+import org.eclipse.net4j.util.transaction.TransactionException;
+
+/**
+ * @author Eike Stepper
+ */
+public class RollbackTest extends AbstractCDOTest
+{
+ public void testRollbackSameSession() throws Exception
+ {
+ CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
+
+ CDOTransaction transaction1 = session.openTransaction();
+ CDOTransaction transaction2 = session.openTransaction();
+
+ flow1(transaction1, transaction2);
+ }
+
+ public void testRollbackSeparateSession() throws Exception
+ {
+ // Client1
+ CDOSession session1 = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ session1.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
+ CDOTransaction transaction1 = session1.openTransaction();
+
+ // Client2
+ CDOSession session2 = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ session2.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
+ CDOTransaction transaction2 = session2.openTransaction();
+
+ flow1(transaction1, transaction2);
+ }
+
+ protected void flow1(CDOTransaction transaction1, CDOTransaction transaction2)
+ {
+ // Client1
+ CDOResource resource1 = transaction1.createResource("/test1");
+ Company company1 = Model1Factory.eINSTANCE.createCompany();
+ resource1.getContents().add(company1);
+ Category category1 = Model1Factory.eINSTANCE.createCategory();
+ company1.getCategories().add(category1);
+ transaction1.commit();
+
+ // Client2
+ CDOResource resource2 = transaction2.getResource("/test1");
+ Company company2 = (Company)resource2.getContents().get(0);
+ Category category2 = company2.getCategories().get(0);
+ category2.setName("client2");
+
+ // Client1
+ category1.setName("client1");
+ transaction1.commit();
+ sleep(500);
+
+ // Client2
+ assertEquals(true, transaction2.isDirty());
+ assertEquals(true, transaction2.hasConflict());
+
+ try
+ {
+ transaction2.commit();
+ fail("Commit on transaction2 should fail");
+ }
+ catch (TransactionException ex)
+ {
+ transaction2.rollback(true);
+ }
+
+ assertEquals(false, transaction2.isDirty());
+ assertEquals(false, transaction2.hasConflict());
+ assertEquals("client1", category2.getName());
+ category2.setName("client2");
+ transaction2.commit();
+ assertEquals(false, transaction2.isDirty());
+ assertEquals(false, transaction2.hasConflict());
+ assertEquals("client2", category2.getName());
+ sleep(500);
+
+ // Client1
+ assertEquals(false, transaction1.isDirty());
+ assertEquals(false, transaction1.hasConflict());
+ assertEquals("client2", category1.getName());
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
index bd98df4..cd27da3 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
@@ -15,11 +15,11 @@ import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
-import org.eclipse.net4j.util.event.INotifier;
-
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.net4j.util.event.INotifier;
+
/**
* @author Eike Stepper
* @author Simon McDuff
@@ -40,6 +40,8 @@ public interface CDOView extends INotifier
public boolean isDirty();
+ public boolean hasConflict();
+
public boolean isEnableInvalidationNotifications();
public void setEnableInvalidationNotifications(boolean on);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
index 94f3a2c..8e884f2 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
@@ -13,13 +13,6 @@
**************************************************************************/
package org.eclipse.emf.internal.cdo;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.CDOViewEvent;
@@ -39,6 +32,7 @@ import org.eclipse.emf.cdo.protocol.revision.CDORevisionResolver;
import org.eclipse.emf.cdo.protocol.util.TransportException;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.ReadOnlyException;
+
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
@@ -54,10 +48,18 @@ import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.emf.internal.cdo.protocol.ResourcePathRequest;
import org.eclipse.emf.internal.cdo.util.FSMUtil;
import org.eclipse.emf.internal.cdo.util.ModelUtil;
+
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.signal.IFailOverStrategy;
import org.eclipse.net4j.util.ImplementationError;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* @author Eike Stepper
* @author Simon McDuff
@@ -125,6 +127,11 @@ public class CDOViewImpl extends org.eclipse.net4j.internal.util.event.Notifier
return false;
}
+ public boolean hasConflict()
+ {
+ return false;
+ }
+
public boolean isEnableInvalidationNotifications()
{
return enableInvalidationNotifications;