|
From: <hib...@li...> - 2006-06-06 18:38:06
|
Author: ste...@jb...
Date: 2006-06-06 14:08:00 -0400 (Tue, 06 Jun 2006)
New Revision: 9990
Modified:
trunk/Hibernate3/src/org/hibernate/engine/transaction/Isolater.java
Log:
temporary ddl operations and transactions
Modified: trunk/Hibernate3/src/org/hibernate/engine/transaction/Isolater.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/engine/transaction/Isolater.java 2006-06-06 17:21:38 UTC (rev 9989)
+++ trunk/Hibernate3/src/org/hibernate/engine/transaction/Isolater.java 2006-06-06 18:08:00 UTC (rev 9990)
@@ -13,7 +13,12 @@
/**
* Class which provides the isolation semantics required by
- * an {@link IsolatedWork}.
+ * an {@link IsolatedWork}. Processing comes in two flavors:<ul>
+ * <li>{@link #doIsolatedWork} : makes sure the work to be done is
+ * performed in a seperate, distinct transaction</li>
+ * <li>{@link #doNonTransactedWork} : makes sure the work to be
+ * done is performed outside the scope of any transaction</li>
+ * </ul>
*
* @author Steve Ebersole
*/
@@ -22,8 +27,8 @@
private static final Log log = LogFactory.getLog( Isolater.class );
/**
- * The exposed service of this class. Ensures that all work actually
- * performed by the given work will occur on a seperate transaction.
+ * Ensures that all processing actually performed by the given work will
+ * occur on a seperate transaction.
*
* @param work The work to be performed.
* @param session The session from which this request is originating.
@@ -32,19 +37,37 @@
public static void doIsolatedWork(IsolatedWork work, SessionImplementor session) throws HibernateException {
boolean isJta = session.getFactory().getTransactionManager() != null;
if ( isJta ) {
- new JtaDelegate( session ).delegateWork( work );
+ new JtaDelegate( session ).delegateWork( work, true );
}
else {
- new JdbcDelegate( session ).delegateWork( work );
+ new JdbcDelegate( session ).delegateWork( work, true );
}
}
+ /**
+ * Ensures that all processing actually performed by the given work will
+ * occur outside of a transaction.
+ *
+ * @param work The work to be performed.
+ * @param session The session from which this request is originating.
+ * @throws HibernateException
+ */
+ public static void doNonTransactedWork(IsolatedWork work, SessionImplementor session) throws HibernateException {
+ boolean isJta = session.getFactory().getTransactionManager() != null;
+ if ( isJta ) {
+ new JtaDelegate( session ).delegateWork( work, false );
+ }
+ else {
+ new JdbcDelegate( session ).delegateWork( work, false );
+ }
+ }
+
// should be ok performance-wise to generate new delegate instances for each
// request since these are locally stack-scoped. Besides, it makes the code
// much easier to read than the old TransactionHelper stuff...
private static interface Delegate {
- public void delegateWork(IsolatedWork work) throws HibernateException;
+ public void delegateWork(IsolatedWork work, boolean transacted) throws HibernateException;
}
/**
@@ -59,7 +82,7 @@
this.session = session;
}
- public void delegateWork(IsolatedWork work) throws HibernateException {
+ public void delegateWork(IsolatedWork work, boolean transacted) throws HibernateException {
TransactionManager transactionManager = session.getFactory().getTransactionManager();
Transaction surroundingTransaction = null;
Connection connection = null;
@@ -72,7 +95,11 @@
if ( log.isDebugEnabled() ) {
log.debug( "surrounding JTA transaction suspended [" + surroundingTransaction + "]" );
}
- transactionManager.begin();
+
+ if ( transacted ) {
+ transactionManager.begin();
+ }
+
connection = session.getBatcher().openConnection();
// perform the actual work
@@ -81,7 +108,10 @@
// if everything went ok, commit the transaction and close the obtained
// connection handle...
session.getBatcher().closeConnection( connection );
- transactionManager.commit();
+
+ if ( transacted ) {
+ transactionManager.commit();
+ }
}
catch( Throwable t ) {
// at some point the processing went bad, so we need to:
@@ -96,13 +126,14 @@
catch( Throwable ignore ) {
log.trace( "unable to release connection on exception [" + ignore + "]" );
}
- try {
- transactionManager.rollback();
+ if ( transacted ) {
+ try {
+ transactionManager.rollback();
+ }
+ catch( Throwable ignore ) {
+ log.trace( "unable to rollback new transaction on exception [" + ignore + "]" );
+ }
}
- catch( Throwable ignore ) {
- log.trace( "unable to rollback new transaction on exception [" + ignore + "]" );
- }
-
// finally handle the exception
if ( t instanceof HibernateException ) {
throw ( HibernateException ) t;
@@ -140,23 +171,28 @@
this.session = session;
}
- public void delegateWork(IsolatedWork work) throws HibernateException {
+ public void delegateWork(IsolatedWork work, boolean transacted) throws HibernateException {
Connection connection = null;
boolean wasAutoCommit = false;
try {
connection = session.getBatcher().openConnection();
- if ( connection.getAutoCommit() ) {
- wasAutoCommit = true;
- connection.setAutoCommit( false );
+
+ if ( transacted ) {
+ if ( connection.getAutoCommit() ) {
+ wasAutoCommit = true;
+ connection.setAutoCommit( false );
+ }
}
work.doWork( connection );
- connection.commit();
+ if ( transacted ) {
+ connection.commit();
+ }
}
catch( Throwable t ) {
try {
- if ( connection!= null && !connection.isClosed() ) {
+ if ( transacted && connection != null && !connection.isClosed() ) {
connection.rollback();
}
}
@@ -179,7 +215,7 @@
}
}
finally {
- if ( wasAutoCommit ) {
+ if ( transacted && wasAutoCommit ) {
try {
connection.setAutoCommit( true );
}
|