Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2019-02-01 19:40:11 +0000
committerEike Stepper2019-02-01 19:40:11 +0000
commit7217380110c2353c2a6df073614f3a046135952f (patch)
tree4862bb91ffc69669cf3a8f96e59094cbce278e69 /plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo
parentddbf0ebab3920ef12645400a1b929d8accd97831 (diff)
downloadcdo-7217380110c2353c2a6df073614f3a046135952f.tar.gz
cdo-7217380110c2353c2a6df073614f3a046135952f.tar.xz
cdo-7217380110c2353c2a6df073614f3a046135952f.zip
[544050] Provide commit template methods in CDOTransaction
https://bugs.eclipse.org/bugs/show_bug.cgi?id=544050
Diffstat (limited to 'plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java112
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXATransactionImpl.java10
2 files changed, 115 insertions, 7 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
index 5311d463c4..9532476c2a 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
@@ -115,6 +115,7 @@ import org.eclipse.emf.cdo.transaction.CDOUserSavepoint;
import org.eclipse.emf.cdo.util.CDOURIUtil;
import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.CommitException;
+import org.eclipse.emf.cdo.util.ConcurrentAccessException;
import org.eclipse.emf.cdo.util.DanglingIntegrityException;
import org.eclipse.emf.cdo.util.DanglingReferenceException;
import org.eclipse.emf.cdo.util.LocalCommitConflictException;
@@ -137,6 +138,7 @@ import org.eclipse.emf.internal.cdo.view.CDOViewImpl;
import org.eclipse.net4j.util.CheckUtil;
import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.Predicate;
import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.collection.AbstractCloseableIterator;
import org.eclipse.net4j.util.collection.ByteArrayWrapper;
@@ -186,6 +188,7 @@ import org.eclipse.emf.spi.cdo.InternalCDOViewSet;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubMonitor;
import java.io.IOException;
import java.io.InputStream;
@@ -1555,7 +1558,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
/**
* @since 2.0
*/
- public CDOCommitInfo commit(IProgressMonitor progressMonitor) throws CommitException
+ public CDOCommitInfo commit(IProgressMonitor monitor) throws CommitException
{
CDOConflictResolver[] conflictResolvers = options().getConflictResolvers();
if (conflictResolvers.length != 0)
@@ -1582,7 +1585,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
}
}
- CDOCommitInfo info = commitSynced(progressMonitor);
+ CDOCommitInfo info = commitSynced(monitor);
if (info != null)
{
long timeStamp = info.getTimeStamp();
@@ -1693,6 +1696,90 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
}
}
+ public <T> CommitResult<T> commit(final Callable<T> callable, Predicate<Long> retry, IProgressMonitor monitor)
+ throws ConcurrentAccessException, CommitException, Exception
+ {
+ final Object[] result = { null };
+ final Exception[] exception = { null };
+
+ Runnable runnable = new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ result[0] = callable.call();
+ }
+ catch (Exception ex)
+ {
+ exception[0] = ex;
+ }
+ }
+ };
+
+ CDOCommitInfo info = commit(runnable, retry, monitor);
+ if (exception[0] != null)
+ {
+ throw exception[0];
+ }
+
+ if (info == null)
+ {
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ T r = (T)result[0];
+ return new CommitResult<T>(r, info);
+ }
+
+ public <T> CommitResult<T> commit(Callable<T> callable, int attempts, IProgressMonitor monitor) throws ConcurrentAccessException, CommitException, Exception
+ {
+ return commit(callable, new CountedRetryPredicate(attempts), monitor);
+ }
+
+ public CDOCommitInfo commit(Runnable runnable, Predicate<Long> retry, IProgressMonitor monitor) throws ConcurrentAccessException, CommitException
+ {
+ long start = System.currentTimeMillis();
+ SubMonitor subMonitor = SubMonitor.convert(monitor);
+
+ for (;;)
+ {
+ subMonitor.setWorkRemaining(100);
+
+ synchronized (getViewMonitor())
+ {
+ lockView();
+
+ runnable.run();
+
+ try
+ {
+ return commit(subMonitor.split(1));
+ }
+ catch (ConcurrentAccessException ex)
+ {
+ if (retry.apply(System.currentTimeMillis() - start))
+ {
+ rollback();
+ continue;
+ }
+
+ throw ex;
+ }
+ finally
+ {
+ unlockView();
+ }
+ }
+ }
+ }
+
+ public CDOCommitInfo commit(Runnable runnable, int attempts, IProgressMonitor monitor) throws ConcurrentAccessException, CommitException
+ {
+ return commit(runnable, new CountedRetryPredicate(attempts), monitor);
+ }
+
public CommitToken getCommitToken()
{
return commitToken;
@@ -3118,6 +3205,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
return new AbstractCloseableIterator<CDOResourceNode>()
{
+
private Iterator<Object> listIterator = finalList == null ? null : finalList.iterator();
@Override
@@ -4768,6 +4856,26 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
/**
* @author Eike Stepper
+ */
+ private static final class CountedRetryPredicate implements Predicate<Long>
+ {
+ private final int attempts;
+
+ private int attempt;
+
+ private CountedRetryPredicate(int attempts)
+ {
+ this.attempts = attempts;
+ }
+
+ public boolean apply(Long startMillis)
+ {
+ return ++attempt < attempts;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
* @since 2.0
*/
protected final class OptionsImpl extends CDOViewImpl.OptionsImpl implements CDOTransaction.Options
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXATransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXATransactionImpl.java
index dbc3cb9965..84355c0150 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXATransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOXATransactionImpl.java
@@ -298,9 +298,9 @@ public class CDOXATransactionImpl implements InternalCDOXATransaction
return commit(null);
}
- public CDOCommitInfo commit(IProgressMonitor progressMonitor) throws CommitException
+ public CDOCommitInfo commit(IProgressMonitor monitor) throws CommitException
{
- commitPrepare(progressMonitor);
+ commitPrepare(monitor);
int phase = 0;
try
@@ -308,17 +308,17 @@ public class CDOXATransactionImpl implements InternalCDOXATransaction
// We need to complete 3 phases
while (phase <= 2)
{
- commitPhase(progressMonitor);
+ commitPhase(monitor);
++phase;
}
}
catch (Exception ex)
{
- commitException(progressMonitor, phase, ex);
+ commitException(monitor, phase, ex);
}
finally
{
- commitFinally(progressMonitor);
+ commitFinally(monitor);
}
return null;

Back to the top