diff options
author | Eike Stepper | 2008-09-14 08:35:51 +0000 |
---|---|---|
committer | Eike Stepper | 2008-09-14 08:35:51 +0000 |
commit | aa99f9da75d255f23a6ab39ef7a391c96b5ea0ce (patch) | |
tree | c2188587ea25bcfa6a76b3f00b15a1465259bb67 /plugins/org.eclipse.emf.cdo/src/org/eclipse/emf | |
parent | 3bfea46a9d980073f4d7c32a067e78174e0eef1c (diff) | |
download | cdo-aa99f9da75d255f23a6ab39ef7a391c96b5ea0ce.tar.gz cdo-aa99f9da75d255f23a6ab39ef7a391c96b5ea0ce.tar.xz cdo-aa99f9da75d255f23a6ab39ef7a391c96b5ea0ce.zip |
[247143] Add detach object handling to CDOTransactionHandler
https://bugs.eclipse.org/bugs/show_bug.cgi?id=247143
Diffstat (limited to 'plugins/org.eclipse.emf.cdo/src/org/eclipse/emf')
5 files changed, 101 insertions, 18 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransactionHandler.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransactionHandler.java index 550756ec60..224d70fb16 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransactionHandler.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOTransactionHandler.java @@ -9,6 +9,7 @@ * Eike Stepper - initial API and implementation * Simon McDuff - http://bugs.eclipse.org/201266 * Simon McDuff - http://bugs.eclipse.org/233314 + * Simon McDuff - http://bugs.eclipse.org/247143 **************************************************************************/ package org.eclipse.emf.cdo; @@ -22,8 +23,18 @@ public interface CDOTransactionHandler /** * Called by a <code>CDOTransaction</code> <b>before</b> an object is added. The implementor of this method is allowed * to throw an unchecked exception that will propagate up to the operation that is about to add the object. + * + * @since 2.0 + */ + public void attachingObject(CDOTransaction transaction, CDOObject object); + + /** + * Called by a <code>CDOTransaction</code> <b>before</b> an object is detached. The implementor of this method is + * allowed to throw an unchecked exception that will propagate up to the operation that is about to remove the object. + * + * @since 2.0 */ - public void addingObject(CDOTransaction transaction, CDOObject object); + public void detachingObject(CDOTransaction transaction, CDOObject object); /** * Called by a <code>CDOTransaction</code> <b>before</b> an object is modified. The implementor of this method is diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOAutoAttacher.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOAutoAttacher.java index 984936a0c0..9ad6e110d4 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOAutoAttacher.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOAutoAttacher.java @@ -13,7 +13,6 @@ package org.eclipse.emf.cdo.util; import org.eclipse.emf.cdo.CDOObject; import org.eclipse.emf.cdo.CDOTransaction; -import org.eclipse.emf.cdo.CDOTransactionHandler; import org.eclipse.emf.cdo.common.revision.delta.CDOAddFeatureDelta; import org.eclipse.emf.cdo.common.revision.delta.CDOClearFeatureDelta; import org.eclipse.emf.cdo.common.revision.delta.CDOContainerFeatureDelta; @@ -38,7 +37,7 @@ import java.util.List; * @author Simon McDuff * @since 2.0 */ -public class CDOAutoAttacher implements CDOTransactionHandler +public class CDOAutoAttacher extends CDOTransactionHandlerImpl { private CDOTransaction transaction; @@ -53,7 +52,8 @@ public class CDOAutoAttacher implements CDOTransactionHandler return transaction; } - public void addingObject(CDOTransaction transaction, CDOObject object) + @Override + public void attachingObject(CDOTransaction transaction, CDOObject object) { if (object instanceof CDOResource) { @@ -64,6 +64,7 @@ public class CDOAutoAttacher implements CDOTransactionHandler handle(object, object); } + @Override public void modifyingObject(CDOTransaction transaction, CDOObject object, CDOFeatureDelta featureChange) { if (object instanceof CDOResource) @@ -78,16 +79,6 @@ public class CDOAutoAttacher implements CDOTransactionHandler } } - public void committingTransaction(CDOTransaction transaction) - { - // Do nothing - } - - public void rolledBackTransaction(CDOTransaction transaction) - { - // Do nothing - } - protected void persist(EObject res, Object object) { if (!(object instanceof CDOResource) && object instanceof InternalCDOObject) diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOTransactionHandlerImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOTransactionHandlerImpl.java new file mode 100644 index 0000000000..55788b43a7 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOTransactionHandlerImpl.java @@ -0,0 +1,67 @@ +/*************************************************************************** + * 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.util; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.CDOTransaction; +import org.eclipse.emf.cdo.CDOTransactionHandler; +import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public abstract class CDOTransactionHandlerImpl implements CDOTransactionHandler +{ + protected CDOTransactionHandlerImpl() + { + } + + /** + * This implementation does nothing. Clients may override to provide specialized behaviour. + */ + public void attachingObject(CDOTransaction transaction, CDOObject object) + { + // Do nothing + } + + /** + * This implementation does nothing. Clients may override to provide specialized behaviour. + */ + public void detachingObject(CDOTransaction transaction, CDOObject object) + { + // Do nothing + } + + /** + * This implementation does nothing. Clients may override to provide specialized behaviour. + */ + public void modifyingObject(CDOTransaction transaction, CDOObject object, CDOFeatureDelta featureChange) + { + // Do nothing + } + + /** + * This implementation does nothing. Clients may override to provide specialized behaviour. + */ + public void committingTransaction(CDOTransaction transaction) + { + // Do nothing + } + + /** + * This implementation does nothing. Clients may override to provide specialized behaviour. + */ + public void rolledBackTransaction(CDOTransaction transaction) + { + // Do nothing + } +} 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 50543e1e73..434592b23f 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 @@ -13,6 +13,7 @@ * Simon McDuff - http://bugs.eclipse.org/233490 * Simon McDuff - http://bugs.eclipse.org/213402 * Simon McDuff - http://bugs.eclipse.org/246620 + * Simon McDuff - http://bugs.eclipse.org/247143 **************************************************************************/ package org.eclipse.emf.internal.cdo; @@ -109,7 +110,10 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa { synchronized (handlers) { - handlers.add(handler); + if (!handlers.contains(handler)) + { + handlers.add(handler); + } } } @@ -480,6 +484,11 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa */ public void detachObject(InternalCDOObject object) { + for (CDOTransactionHandler handler : getHandlers()) + { + handler.detachingObject(this, object); + } + if (object.cdoState() == CDOState.NEW) { Map<CDOID, ? extends CDOObject> map = object instanceof CDOResource ? getLastSavepoint().getNewResources() @@ -502,6 +511,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa { getLastSavepoint().getDetachedObjects().add(object.cdoID()); } + } /** @@ -621,7 +631,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa for (CDOTransactionHandler handler : getHandlers()) { - handler.addingObject(this, object); + handler.attachingObject(this, object); } if (object instanceof CDOResourceImpl) diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java index 8fbce7b458..a22b994153 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java @@ -302,7 +302,7 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP } } - public void addingObject(CDOTransaction transaction, CDOObject object) + public void attachingObject(CDOTransaction transaction, CDOObject object) { } @@ -317,6 +317,10 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP public void rolledBackTransaction(CDOTransaction transaction) { } + + public void detachingObject(CDOTransaction transaction, CDOObject object) + { + } } /** @@ -393,7 +397,7 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP } @Override - public void addingObject(CDOTransaction transaction, CDOObject object) + public void attachingObject(CDOTransaction transaction, CDOObject object) { EClass usedClass = object.eClass(); addAllEPackages(usedClass); |