diff options
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 0000000000..759536ff19 --- /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 949b92070d..5354b4dabe 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 70e5aef96e..e4fb2a8ac8 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; + } + } } |