[hibernate-commits] Hibernate SVN: r11480 - branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Tue May 8 06:50:24 EDT 2007
Author: steve.ebersole at jboss.com
Date: 2007-05-08 06:50:24 -0400 (Tue, 08 May 2007)
New Revision: 11480
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
Log:
HHH-2580 : WebSphereExtendedJTATransactionLookup patch
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java
===================================================================
--- branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java 2007-05-08 01:16:39 UTC (rev 11479)
+++ branches/Branch_3_2/Hibernate3/src/org/hibernate/transaction/WebSphereExtendedJTATransactionLookup.java 2007-05-08 10:50:24 UTC (rev 11480)
@@ -24,10 +24,12 @@
/**
* Support for proprietary interfaces for registering synchronizations in WebSphere 6.
+ *
* @author Gavin King
*/
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);
@@ -36,25 +38,25 @@
public String getUserTransactionName() {
return "java:comp/UserTransaction";
}
-
+
public static class TransactionManagerAdapter implements TransactionManager {
private final Properties properties;
private final Class synchronizationCallbackClass;
private final Method registerSynchronizationMethod;
private final Method getLocalIdMethod;
-
+
private TransactionManagerAdapter(Properties props) {
this.properties = props;
try {
synchronizationCallbackClass = Class.forName("com.ibm.websphere.jtaextensions.SynchronizationCallback");
Class extendedJTATransactionClass = Class.forName("com.ibm.websphere.jtaextensions.ExtendedJTATransaction");
- registerSynchronizationMethod = extendedJTATransactionClass.getMethod(
- "registerSynchronizationCallbackForCurrentTran",
- new Class[] { synchronizationCallbackClass }
+ registerSynchronizationMethod = extendedJTATransactionClass.getMethod(
+ "registerSynchronizationCallbackForCurrentTran",
+ new Class[] { synchronizationCallbackClass }
);
getLocalIdMethod = extendedJTATransactionClass.getMethod( "getLocalId", null );
-
+
}
catch (ClassNotFoundException cnfe) {
throw new HibernateException(cnfe);
@@ -63,7 +65,7 @@
throw new HibernateException(nsme);
}
}
-
+
public void begin() throws NotSupportedException, SystemException {
throw new UnsupportedOperationException();
}
@@ -79,10 +81,10 @@
}
public Transaction getTransaction() throws SystemException {
- return new TransactionAdapter(properties);
+ return new TransactionAdapter( properties );
}
- public void resume(Transaction txn) throws InvalidTransactionException,
+ public void resume(Transaction txn) throws InvalidTransactionException,
IllegalStateException, SystemException {
throw new UnsupportedOperationException();
}
@@ -106,13 +108,13 @@
}
public class TransactionAdapter implements Transaction {
-
- private final Object extendedJTATransaction;
-
+ private Object extendedJTATransaction;
+
private TransactionAdapter(Properties props) {
try {
- extendedJTATransaction = NamingHelper.getInitialContext(props)
- .lookup("java:comp/websphere/ExtendedJTATransaction");
+ if (extendedJTATransaction == null) {
+ extendedJTATransaction = NamingHelper.getInitialContext( props ).lookup( E_TRN_JNDI_NAME );
+ }
}
catch (NamingException ne) {
throw new HibernateException(ne);
@@ -122,13 +124,13 @@
public void registerSynchronization(final Synchronization synchronization)
throws RollbackException, IllegalStateException,
SystemException {
-
+
final InvocationHandler ih = new InvocationHandler() {
-
+
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ( "afterCompletion".equals( method.getName() ) ) {
- int status = args[2].equals(Boolean.TRUE) ?
- Status.STATUS_COMMITTED :
+ int status = args[2].equals(Boolean.TRUE) ?
+ Status.STATUS_COMMITTED :
Status.STATUS_UNKNOWN;
synchronization.afterCompletion(status);
}
@@ -140,31 +142,31 @@
}
return null;
}
-
+
};
-
- final Object synchronizationCallback = Proxy.newProxyInstance(
- getClass().getClassLoader(),
- new Class[] { synchronizationCallbackClass },
- ih
+
+ final Object synchronizationCallback = Proxy.newProxyInstance(
+ getClass().getClassLoader(),
+ new Class[] { synchronizationCallbackClass },
+ ih
+ );
+
+ try {
+ registerSynchronizationMethod.invoke(
+ extendedJTATransaction,
+ new Object[] { synchronizationCallback }
);
-
- try {
- registerSynchronizationMethod.invoke(
- extendedJTATransaction,
- new Object[] { synchronizationCallback }
- );
}
catch (Exception e) {
throw new HibernateException(e);
}
}
-
+
public int hashCode() {
return getLocalId().hashCode();
}
-
+
public boolean equals(Object other) {
if ( !(other instanceof TransactionAdapter) ) return false;
TransactionAdapter that = (TransactionAdapter) other;
@@ -185,20 +187,20 @@
IllegalStateException, SystemException {
throw new UnsupportedOperationException();
}
-
+
public boolean delistResource(XAResource resource, int i)
throws IllegalStateException, SystemException {
throw new UnsupportedOperationException();
}
-
+
public boolean enlistResource(XAResource resource)
throws RollbackException, IllegalStateException,
SystemException {
throw new UnsupportedOperationException();
}
-
+
public int getStatus() throws SystemException {
- return new Integer(0).equals( getLocalId() ) ?
+ return new Integer(0).equals( getLocalId() ) ?
Status.STATUS_NO_TRANSACTION : Status.STATUS_ACTIVE;
}
@@ -211,7 +213,7 @@
throw new UnsupportedOperationException();
}
}
-
+
}
-
+
}
More information about the hibernate-commits
mailing list