Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DbTransaction.java')
-rw-r--r--plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DbTransaction.java93
1 files changed, 32 insertions, 61 deletions
diff --git a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DbTransaction.java b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DbTransaction.java
index 1f60efa5f7e..4c1163d1eb4 100644
--- a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DbTransaction.java
+++ b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DbTransaction.java
@@ -10,23 +10,19 @@
*******************************************************************************/
package org.eclipse.osee.framework.database.core;
-import java.util.logging.Level;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.exception.OseeWrappedException;
-import org.eclipse.osee.framework.database.internal.Activator;
-import org.eclipse.osee.framework.logging.OseeLog;
/**
* This abstract class provides a uniform way of executing database transactions. It handles exceptions ensuring that
* transactions are processed in the correct order and roll-backs are performed whenever errors are detected.
- *
+ *
* @author Roberto E. Escobar
*/
public abstract class DbTransaction {
/**
* Gets the name of this transaction. This is provided mainly for logging purposes.
- *
+ *
* @return String transaction class Name
*/
protected String getTxName() {
@@ -36,64 +32,16 @@ public abstract class DbTransaction {
/**
* This template method calls {@link #handleTxWork} which is provided by child classes. This method handles
* roll-backs and exception handling to prevent transactions from being left in an incorrect state.
- *
- * @throws Exception
+ *
+ * @throws OseeCoreException
*/
public void execute() throws OseeCoreException {
- execute(ConnectionHandler.getConnection());
- }
-
- private void execute(OseeConnection connection) throws OseeCoreException {
- boolean initialAutoCommit = true;
- OseeCoreException saveException = null;
- try {
- OseeLog.log(Activator.class, Level.FINEST, String.format("Start Transaction: [%s]", getTxName()));
-
- initialAutoCommit = connection.getAutoCommit();
- connection.setAutoCommit(false);
- ConnectionHandler.deferConstraintChecking(connection);
- handleTxWork(connection);
-
- connection.commit();
- OseeLog.log(Activator.class, Level.FINEST, String.format("End Transaction: [%s]", getTxName()));
- } catch (Exception ex) {
- if (ex instanceof OseeCoreException) {
- saveException = (OseeCoreException) ex;
- } else {
- saveException = new OseeWrappedException(ex);
- }
- try {
- connection.rollback();
- connection.destroy();
- } finally {
- handleTxException(ex);
- }
- } finally {
- try {
- try {
- if (!connection.isClosed()) {
- connection.setAutoCommit(initialAutoCommit);
- connection.close();
- }
- } finally {
- handleTxFinally();
- }
- } catch (OseeCoreException ex) {
- OseeLog.log(Activator.class, Level.SEVERE, ex);
- if (saveException == null) {
- saveException = ex;
- }
- }
-
- if (saveException != null) {
- throw saveException;
- }
- }
+ DatabaseTransactions.execute(new InternalTransactionWork());
}
/**
* Provides the transaction's work implementation.
- *
+ *
* @param connection
* @throws OseeCoreException
*/
@@ -103,7 +51,7 @@ public abstract class DbTransaction {
* When an exception is detected during transaction processing, the exception is caught and passed to this method.
* This convenience method is provided so child classes have access to the exception. <br/>
* <b>Override to handle transaction exception</b>
- *
+ *
* @param ex
* @throws Exception
*/
@@ -114,10 +62,33 @@ public abstract class DbTransaction {
* This convenience method is provided in case child classes have a portion of code that needs to execute always at
* the end of the transaction, regardless of exceptions. <br/>
* <b>Override to add additional code to finally block</b>
- *
- * @throws Exception
+ *
+ * @throws OseeCoreException
*/
protected void handleTxFinally() throws OseeCoreException {
// override to add additional code to finally
}
+
+ private final class InternalTransactionWork implements IDbTransactionWork {
+
+ @Override
+ public void handleTxException(Exception ex) {
+ DbTransaction.this.handleTxException(ex);
+ }
+
+ @Override
+ public void handleTxFinally() throws OseeCoreException {
+ DbTransaction.this.handleTxFinally();
+ }
+
+ @Override
+ public void handleTxWork(OseeConnection connection) throws OseeCoreException {
+ DbTransaction.this.handleTxWork(connection);
+ }
+
+ @Override
+ public String getName() {
+ return DbTransaction.this.getTxName();
+ }
+ };
} \ No newline at end of file

Back to the top