Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjphillips2010-06-23 14:50:43 -0400
committerjphillips2010-06-23 14:50:43 -0400
commitfcfef933daaaf771adc60aff5bd56d8adc2ccf8d (patch)
tree332867c4cd46432809f34fd58495de9a755f8f74 /plugins/org.eclipse.osee.framework.database
parenta036ded9b8f854c8f8cd43269cd76f309a04cdc4 (diff)
downloadorg.eclipse.osee-fcfef933daaaf771adc60aff5bd56d8adc2ccf8d.tar.gz
org.eclipse.osee-fcfef933daaaf771adc60aff5bd56d8adc2ccf8d.tar.xz
org.eclipse.osee-fcfef933daaaf771adc60aff5bd56d8adc2ccf8d.zip
Commit lifecycle implementation with skynetTransaction
Diffstat (limited to 'plugins/org.eclipse.osee.framework.database')
-rw-r--r--plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DatabaseTransactions.java71
-rw-r--r--plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DbTransaction.java93
-rw-r--r--plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/IDbTransactionWork.java49
3 files changed, 152 insertions, 61 deletions
diff --git a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DatabaseTransactions.java b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DatabaseTransactions.java
new file mode 100644
index 0000000000..6642e1e3d3
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/DatabaseTransactions.java
@@ -0,0 +1,71 @@
+/*
+ * Created on Jun 22, 2010
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+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;
+
+public final class DatabaseTransactions {
+
+ private DatabaseTransactions() {
+ }
+
+ public static void execute(IDbTransactionWork dbWork) throws OseeCoreException {
+ execute(ConnectionHandler.getConnection(), dbWork);
+ }
+
+ public static void execute(OseeConnection connection, IDbTransactionWork dbWork) throws OseeCoreException {
+ boolean initialAutoCommit = true;
+ OseeCoreException saveException = null;
+ try {
+ OseeLog.log(Activator.class, Level.FINEST, String.format("Start Transaction: [%s]", dbWork.getName()));
+
+ initialAutoCommit = connection.getAutoCommit();
+ connection.setAutoCommit(false);
+ ConnectionHandler.deferConstraintChecking(connection);
+ dbWork.handleTxWork(connection);
+
+ connection.commit();
+ OseeLog.log(Activator.class, Level.FINEST, String.format("End Transaction: [%s]", dbWork.getName()));
+ } catch (Exception ex) {
+ if (ex instanceof OseeCoreException) {
+ saveException = (OseeCoreException) ex;
+ } else {
+ saveException = new OseeWrappedException(ex);
+ }
+ try {
+ connection.rollback();
+ connection.destroy();
+ } finally {
+ dbWork.handleTxException(ex);
+ }
+ } finally {
+ try {
+ try {
+ if (!connection.isClosed()) {
+ connection.setAutoCommit(initialAutoCommit);
+ connection.close();
+ }
+ } finally {
+ dbWork.handleTxFinally();
+ }
+ } catch (OseeCoreException ex) {
+ OseeLog.log(Activator.class, Level.SEVERE, ex);
+ if (saveException == null) {
+ saveException = ex;
+ }
+ }
+
+ if (saveException != null) {
+ throw saveException;
+ }
+ }
+ }
+
+}
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 1f60efa5f7..4c1163d1eb 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
diff --git a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/IDbTransactionWork.java b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/IDbTransactionWork.java
new file mode 100644
index 0000000000..2c1b46f4a0
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/IDbTransactionWork.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.osee.framework.database.core;
+
+import org.eclipse.osee.framework.core.data.Named;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+/**
+ * @author Roberto E. Escobar
+ * @author Jeff C. Phillips
+ */
+public interface IDbTransactionWork extends Named {
+
+ /**
+ * Provides the transaction's work implementation.
+ *
+ * @param connection
+ * @throws OseeCoreException
+ */
+ void handleTxWork(OseeConnection connection) throws OseeCoreException;
+
+ /**
+ * 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
+ */
+ void handleTxException(Exception ex);
+
+ /**
+ * 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 OseeCoreException
+ */
+ void handleTxFinally() throws OseeCoreException;
+} \ No newline at end of file

Back to the top