Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2019-01-02 04:53:03 -0500
committerEike Stepper2019-01-02 04:53:03 -0500
commit3ff7e9362774a011ceb8e5937ab4f20e87fe27b0 (patch)
tree76deacd4a1cc7fdd6fe1baf07087a7be25aedf88
parent1110742e72c69185bfe2ac5c8d7697d460a8af3f (diff)
downloadcdo-3ff7e9362774a011ceb8e5937ab4f20e87fe27b0.tar.gz
cdo-3ff7e9362774a011ceb8e5937ab4f20e87fe27b0.tar.xz
cdo-3ff7e9362774a011ceb8e5937ab4f20e87fe27b0.zip
[543116] Provide a CDOAutoCommitter
https://bugs.eclipse.org/bugs/show_bug.cgi?id=543116
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/transaction/CDOAutoCommitter.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/transaction/CDOAutoCommitter.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/transaction/CDOAutoCommitter.java
new file mode 100644
index 0000000000..fbb4d49cb4
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/transaction/CDOAutoCommitter.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2019 Eike Stepper (Loehne, Germany) and others.
+ * 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.transaction;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.util.CommitException;
+import org.eclipse.emf.cdo.util.ConcurrentAccessException;
+
+import org.eclipse.emf.common.notify.Notification;
+
+/**
+ * @author Eike Stepper
+ * @since 4.7
+ */
+public class CDOAutoCommitter extends CDOPostEventTransactionHandler.Default
+{
+ public CDOAutoCommitter(CDOTransaction transaction)
+ {
+ transaction.addTransactionHandler(this);
+ }
+
+ @Override
+ protected void modifiedObject(CDOTransaction transaction, CDOObject object, Notification msg)
+ {
+ try
+ {
+ transaction.commit();
+ }
+ catch (ConcurrentAccessException ex)
+ {
+ handleConcurrentAccessException(transaction, ex);
+ }
+ catch (CommitException ex)
+ {
+ handleCommitException(transaction, ex);
+ }
+ }
+
+ protected void handleConcurrentAccessException(CDOTransaction transaction, ConcurrentAccessException ex)
+ {
+ handleCommitException(transaction, ex);
+ }
+
+ protected void handleCommitException(CDOTransaction transaction, CommitException ex)
+ {
+ rollbackTransaction(transaction);
+ }
+
+ protected void rollbackTransaction(CDOTransaction transaction)
+ {
+ transaction.rollback();
+ }
+}

Back to the top