Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2011-01-23 10:49:20 +0000
committerEike Stepper2011-01-23 10:49:20 +0000
commitddacc4a2f108bf20fca0397a1572174c79b7ae0a (patch)
tree1aca1dd178e10c1b00ece907827700e1ad0eb436
parent6a97fabaccaaa63cccd916f59d848c6121064b39 (diff)
downloadcdo-ddacc4a2f108bf20fca0397a1572174c79b7ae0a.tar.gz
cdo-ddacc4a2f108bf20fca0397a1572174c79b7ae0a.tar.xz
cdo-ddacc4a2f108bf20fca0397a1572174c79b7ae0a.zip
[335105] Make it easier to create XA transactions
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335105
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java82
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties2
2 files changed, 67 insertions, 17 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
index d0f12f5352..af77c3f192 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
@@ -28,6 +28,7 @@ import org.eclipse.emf.cdo.view.CDOStaleObject;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.cdo.view.CDOViewSet;
+import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.emf.internal.cdo.messages.Messages;
import org.eclipse.emf.internal.cdo.object.CDOFactoryImpl;
import org.eclipse.emf.internal.cdo.object.CDOObjectWrapper;
@@ -43,6 +44,7 @@ import org.eclipse.net4j.util.om.OMPlatform;
import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
@@ -187,14 +189,27 @@ public final class CDOUtil
}
/**
- * @since 2.0
+ * @since 4.0
*/
- public static CDOXATransaction createXATransaction(CDOViewSet viewSet)
+ public static CDOXATransaction createXATransaction(Notifier... notifiers)
{
- CDOXATransaction xaTransaction = createXATransaction();
- if (viewSet != null)
+ CDOXATransaction xaTransaction = new CDOXATransactionImpl();
+ for (Notifier notifier : notifiers)
{
- xaTransaction.add(viewSet);
+ CDOViewSet viewSet = getViewSet(notifier);
+ if (viewSet == null)
+ {
+ throw new IllegalArgumentException("Notifier is not associated with a CDOViewSet: " + notifier);
+ }
+
+ try
+ {
+ xaTransaction.add(viewSet);
+ }
+ catch (IllegalArgumentException ex)
+ {
+ OM.LOG.warn(ex);
+ }
}
return xaTransaction;
@@ -203,14 +218,6 @@ public final class CDOUtil
/**
* @since 2.0
*/
- public static CDOXATransaction createXATransaction()
- {
- return new CDOXATransactionImpl();
- }
-
- /**
- * @since 2.0
- */
public static CDOXATransaction getXATransaction(CDOViewSet viewSet)
{
EList<Adapter> adapters = viewSet.eAdapters();
@@ -226,11 +233,16 @@ public final class CDOUtil
}
/**
- * @since 2.0
+ * @since 4.0
*/
- public static CDOViewSet getViewSet(ResourceSet resourceSet)
+ public static CDOViewSet getViewSet(Notifier notifier)
{
- EList<Adapter> adapters = resourceSet.eAdapters();
+ if (notifier instanceof CDOViewSet)
+ {
+ return (CDOViewSet)notifier;
+ }
+
+ EList<Adapter> adapters = notifier.eAdapters();
for (Adapter adapter : adapters)
{
if (adapter instanceof CDOViewSet)
@@ -239,6 +251,44 @@ public final class CDOUtil
}
}
+ if (notifier instanceof InternalEObject)
+ {
+ InternalEObject object = (InternalEObject)notifier;
+ EObject container = object.eContainer();
+ if (container != null)
+ {
+ CDOViewSet viewSet = getViewSet(container);
+ if (viewSet != null)
+ {
+ return viewSet;
+ }
+ }
+
+ Resource.Internal resource = object.eDirectResource();
+ if (resource != null)
+ {
+ CDOViewSet viewSet = getViewSet(resource);
+ if (viewSet != null)
+ {
+ return viewSet;
+ }
+ }
+ }
+
+ if (notifier instanceof Resource)
+ {
+ Resource resource = (Resource)notifier;
+ ResourceSet resourceSet = resource.getResourceSet();
+ if (resourceSet != null)
+ {
+ CDOViewSet viewSet = getViewSet(resourceSet);
+ if (viewSet != null)
+ {
+ return viewSet;
+ }
+ }
+ }
+
return null;
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties
index 34d409fef4..f0805c3500 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/messages/messages.properties
@@ -64,7 +64,7 @@ CDOViewSetImpl.2=Only one view per repository can be open for the same resource
CDOViewSetImpl.3=Unsupported target: {0}
CDOViewSetImpl.4=Cannot associate more than 1 resource set with this view set
CDOXACommitContextImpl.0=Object should be an EObject: {0}
-CDOXATransactionImpl.0=XATransaction is already attached to this viewSet
+CDOXATransactionImpl.0=ViewSet is already attached to this XATransaction
CDOXATransactionImpl.1=ViewSet is not attached to this XATransaction
CDOXATransactionImpl.4=Committing XA transaction
CDOXATransactionImpl.7=Save point is not valid: {0}

Back to the top