summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-10-07 07:23:34 (EDT)
committerEike Stepper2007-10-07 07:23:34 (EDT)
commit8af81db67ba8decc2607d2ae0f890b95eae1a5f2 (patch)
treecda351ee937768dc18a4dc1597bf5548f1599603
parent5bdad8cc81d0b3c51a3a8620231c2e15489f8923 (diff)
downloadcdo-8af81db67ba8decc2607d2ae0f890b95eae1a5f2.zip
cdo-8af81db67ba8decc2607d2ae0f890b95eae1a5f2.tar.gz
cdo-8af81db67ba8decc2607d2ae0f890b95eae1a5f2.tar.bz2
[205650] Add transaction conflict resolution handling
https://bugs.eclipse.org/bugs/show_bug.cgi?id=205650
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransactionConflictEvent.java21
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java16
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java44
3 files changed, 80 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransactionConflictEvent.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransactionConflictEvent.java
new file mode 100644
index 0000000..759536f
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransactionConflictEvent.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * 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;
+
+/**
+ * @author Eike Stepper
+ */
+public interface CDOTransactionConflictEvent extends CDOViewEvent
+{
+ public CDOObject getConflictingObject();
+
+ public boolean isFirstConflict();
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
index 949b920..5354b4d 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStateMachine.java
@@ -86,7 +86,7 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
init(CDOState.DIRTY, CDOEvent.WRITE, IGNORE);
init(CDOState.DIRTY, CDOEvent.COMMIT, new CommitTransition());
init(CDOState.DIRTY, CDOEvent.ROLLBACK, new RollbackTransition());
- init(CDOState.DIRTY, CDOEvent.INVALIDATE, FAIL);
+ init(CDOState.DIRTY, CDOEvent.INVALIDATE, new ConflictTransition());
init(CDOState.DIRTY, CDOEvent.FINALIZE_ATTACH, FAIL);
init(CDOState.PROXY, CDOEvent.ATTACH, new LoadResourceTransition());
@@ -362,6 +362,20 @@ public final class CDOStateMachine extends FiniteStateMachine<CDOState, CDOEvent
/**
* @author Eike Stepper
*/
+ private final class ConflictTransition implements ITransition<CDOState, CDOEvent, InternalCDOObject, Long>
+ {
+ public void execute(InternalCDOObject object, CDOState state, CDOEvent event, Long timeStamp)
+ {
+ CDOViewImpl view = (CDOViewImpl)object.cdoView();
+ CDOTransactionImpl transaction = view.toTransaction();
+ transaction.setConflict(object);
+ changeState(object, CDOState.CONFLICT);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
private final class LoadTransition implements ITransition<CDOState, CDOEvent, InternalCDOObject, Object>
{
private boolean forWrite;
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
index 70e5aef..e4fb2a8 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.internal.cdo;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOTransaction;
+import org.eclipse.emf.cdo.CDOTransactionConflictEvent;
import org.eclipse.emf.cdo.CDOTransactionFinishedEvent;
import org.eclipse.emf.cdo.CDOTransactionHandler;
import org.eclipse.emf.cdo.CDOTransactionStartedEvent;
@@ -73,6 +74,8 @@ public class CDOTransactionImpl extends CDOViewImpl implements CDOTransaction
private boolean dirty;
+ private boolean conflict;
+
public CDOTransactionImpl(int id, CDOSessionImpl session)
{
super(id, session);
@@ -114,6 +117,18 @@ public class CDOTransactionImpl extends CDOViewImpl implements CDOTransaction
return dirty;
}
+ public boolean hasConflict()
+ {
+ return conflict;
+ }
+
+ public void setConflict(InternalCDOObject object)
+ {
+ ConflictEvent event = new ConflictEvent(object, !conflict);
+ conflict = true;
+ fireEvent(event);
+ }
+
public List<CDOPackage> getNewPackages()
{
return newPackages;
@@ -390,6 +405,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements CDOTransaction
newObjects.clear();
dirtyObjects.clear();
dirty = false;
+ conflict = false;
nextTemporaryID = INITIAL_TEMPORARY_ID;
}
@@ -432,4 +448,32 @@ public class CDOTransactionImpl extends CDOViewImpl implements CDOTransaction
return idMappings;
}
}
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class ConflictEvent extends Event implements CDOTransactionConflictEvent
+ {
+ private static final long serialVersionUID = 1L;
+
+ private InternalCDOObject conflictingObject;
+
+ private boolean firstConflict;
+
+ public ConflictEvent(InternalCDOObject conflictingObject, boolean firstConflict)
+ {
+ this.conflictingObject = conflictingObject;
+ this.firstConflict = firstConflict;
+ }
+
+ public InternalCDOObject getConflictingObject()
+ {
+ return conflictingObject;
+ }
+
+ public boolean isFirstConflict()
+ {
+ return firstConflict;
+ }
+ }
}