[hibernate-commits] Hibernate SVN: r11498 - trunk/Hibernate3/src/org/hibernate/transaction.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed May 9 10:55:16 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-05-09 10:55:16 -0400 (Wed, 09 May 2007)
New Revision: 11498

Modified:
   trunk/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
Log:
HHH-2580 : WAS ExtendedJTATransaction garbage

Modified: trunk/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java	2007-05-09 14:55:01 UTC (rev 11497)
+++ trunk/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java	2007-05-09 14:55:16 UTC (rev 11498)
@@ -7,9 +7,6 @@
 import java.util.Properties;
 
 import javax.naming.NamingException;
-import javax.transaction.HeuristicMixedException;
-import javax.transaction.HeuristicRollbackException;
-import javax.transaction.InvalidTransactionException;
 import javax.transaction.NotSupportedException;
 import javax.transaction.RollbackException;
 import javax.transaction.Status;
@@ -23,16 +20,28 @@
 import org.hibernate.util.NamingHelper;
 
 /**
- * Support for proprietary interfaces for registering synchronizations in WebSphere 6.
- * 
+ * TransactionManagerLookup implementation intended for use with WebSphere
+ * Application Server (WAS).
+ * <p/>
+ * WAS, unlike every other app server on the planet, does not allow direct
+ * access to the JTS TransactionManager.  Instead, for common transaction-
+ * related tasks users must utilize a proprietary API known as
+ * ExtendedJTATransaction.
+ * <p/>
+ * Even more unfortunate, the exact TransactionManagerLookup to use inside of
+ * WAS is highly dependent upon (1) WAS version as well as (2) the WAS
+ * container in which Hibernate will be utilized.
+ * <p/>
+ * WebSphereExtendedJTATransactionLookup is reported to work on WAS version 6
+ * in any of the standard J2EE/JEE component containers.
+ *
  * @author Gavin King
+ * @author <a href="mailto:jesper at udby.com>Jesper Udby</a>
  */
 public class WebSphereExtendedJTATransactionLookup implements TransactionManagerLookup {
-	public static final String E_TRN_JNDI_NAME = "java:comp/websphere/ExtendedJTATransaction";
 
-	public TransactionManager getTransactionManager(Properties props)
-	throws HibernateException {
-		return new TransactionManagerAdapter(props);
+	public TransactionManager getTransactionManager(Properties props) {
+		return new TransactionManagerAdapter( props );
 	}
 
 	public String getUserTransactionName() {
@@ -40,29 +49,29 @@
 	}
 
 	public static class TransactionManagerAdapter implements TransactionManager {
-
 		private final Properties properties;
 		private final Class synchronizationCallbackClass;
 		private final Method registerSynchronizationMethod;
 		private final Method getLocalIdMethod;
+		private Object extendedJTATransaction;
 
-		private TransactionManagerAdapter(Properties props) {
+		private TransactionManagerAdapter(Properties props) throws HibernateException {
 			this.properties = props;
 			try {
-				synchronizationCallbackClass = Class.forName("com.ibm.websphere.jtaextensions.SynchronizationCallback");
-				Class extendedJTATransactionClass = Class.forName("com.ibm.websphere.jtaextensions.ExtendedJTATransaction");
+				synchronizationCallbackClass = Class.forName( "com.ibm.websphere.jtaextensions.SynchronizationCallback" );
+				Class extendedJTATransactionClass = Class.forName( "com.ibm.websphere.jtaextensions.ExtendedJTATransaction" );
 				registerSynchronizationMethod = extendedJTATransactionClass.getMethod(
 						"registerSynchronizationCallbackForCurrentTran",
 						new Class[] { synchronizationCallbackClass }
-					);
+				);
 				getLocalIdMethod = extendedJTATransactionClass.getMethod( "getLocalId", null );
 
 			}
-			catch (ClassNotFoundException cnfe) {
-				throw new HibernateException(cnfe);
+			catch ( ClassNotFoundException cnfe ) {
+				throw new HibernateException( cnfe );
 			}
-			catch (NoSuchMethodException nsme) {
-				throw new HibernateException(nsme);
+			catch ( NoSuchMethodException nsme ) {
+				throw new HibernateException( nsme );
 			}
 		}
 
@@ -70,13 +79,11 @@
 			throw new UnsupportedOperationException();
 		}
 
-		public void commit() throws RollbackException, HeuristicMixedException,
-				HeuristicRollbackException, SecurityException,
-				IllegalStateException, SystemException {
+		public void commit() throws UnsupportedOperationException {
 			throw new UnsupportedOperationException();
 		}
 
-		public int getStatus() throws SystemException {
+		public int getStatus() throws UnsupportedOperationException {
 			throw new UnsupportedOperationException();
 		}
 
@@ -84,36 +91,33 @@
 			return new TransactionAdapter( properties );
 		}
 
-		public void resume(Transaction txn) throws  InvalidTransactionException,
-				IllegalStateException, SystemException {
+		public void resume(Transaction txn) throws UnsupportedOperationException {
 			throw new UnsupportedOperationException();
 		}
 
-		public void rollback() throws IllegalStateException, SecurityException,
-				SystemException {
+		public void rollback() throws UnsupportedOperationException {
 			throw new UnsupportedOperationException();
 		}
 
-		public void setRollbackOnly() throws IllegalStateException,
-				SystemException {
+		public void setRollbackOnly() throws UnsupportedOperationException {
 			throw new UnsupportedOperationException();
 		}
 
-		public void setTransactionTimeout(int i) throws SystemException {
+		public void setTransactionTimeout(int i) throws UnsupportedOperationException {
 			throw new UnsupportedOperationException();
 		}
 
-		public Transaction suspend() throws SystemException {
+		public Transaction suspend() throws UnsupportedOperationException {
 			throw new UnsupportedOperationException();
 		}
 
 		public class TransactionAdapter implements Transaction {
-			private Object extendedJTATransaction;
 
 			private TransactionAdapter(Properties props) {
 				try {
-					if (extendedJTATransaction == null) {
-						extendedJTATransaction = NamingHelper.getInitialContext( props ).lookup( E_TRN_JNDI_NAME );
+					if ( extendedJTATransaction == null ) {
+						extendedJTATransaction = NamingHelper.getInitialContext( props )
+								.lookup( "java:comp/websphere/ExtendedJTATransaction" );
 					}
 				}
 				catch (NamingException ne) {
@@ -173,43 +177,37 @@
 				return getLocalId().equals( that.getLocalId() );
 			}
 
-			private Object getLocalId() {
+			private Object getLocalId() throws HibernateException {
 				try {
-					return getLocalIdMethod.invoke(extendedJTATransaction, null);
+					return getLocalIdMethod.invoke( extendedJTATransaction, null );
 				}
-				catch (Exception e) {
-					throw new HibernateException(e);
+				catch ( Exception e ) {
+					throw new HibernateException( e );
 				}
 			}
 
-			public void commit() throws RollbackException, HeuristicMixedException,
-					HeuristicRollbackException, SecurityException,
-					IllegalStateException, SystemException {
+			public void commit() throws UnsupportedOperationException {
 				throw new UnsupportedOperationException();
 			}
 
-			public boolean delistResource(XAResource resource, int i)
-					throws IllegalStateException, SystemException {
+			public boolean delistResource(XAResource resource, int i) throws UnsupportedOperationException {
 				throw new UnsupportedOperationException();
 			}
 
-			public boolean enlistResource(XAResource resource)
-					throws RollbackException, IllegalStateException,
-					SystemException {
+			public boolean enlistResource(XAResource resource) throws UnsupportedOperationException {
 				throw new UnsupportedOperationException();
 			}
 
-			public int getStatus() throws SystemException {
+			public int getStatus() {
 				return new Integer(0).equals( getLocalId() ) ?
 						Status.STATUS_NO_TRANSACTION : Status.STATUS_ACTIVE;
 			}
 
-			public void rollback() throws IllegalStateException, SystemException {
+			public void rollback() throws UnsupportedOperationException {
 				throw new UnsupportedOperationException();
 			}
 
-			public void setRollbackOnly() throws IllegalStateException,
-					SystemException {
+			public void setRollbackOnly() throws UnsupportedOperationException {
 				throw new UnsupportedOperationException();
 			}
 		}




More information about the hibernate-commits mailing list