Author: stliu
Date: 2011-10-19 13:33:58 -0400 (Wed, 19 Oct 2011)
New Revision: 20984
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/transaction/JBossTransactionManagerLookup.java
Log:
JBPAPP-7385 Hibernate 3 does not provide a LookupManager for EAP/AS7
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/transaction/JBossTransactionManagerLookup.java
===================================================================
---
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/transaction/JBossTransactionManagerLookup.java 2011-10-17
12:37:29 UTC (rev 20983)
+++
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/transaction/JBossTransactionManagerLookup.java 2011-10-19
17:33:58 UTC (rev 20984)
@@ -24,19 +24,42 @@
*/
package org.hibernate.transaction;
+import java.util.Properties;
+import javax.naming.NamingException;
+import javax.transaction.TransactionManager;
+
+import org.hibernate.HibernateException;
+import org.hibernate.util.NamingHelper;
+
/**
* A {@link TransactionManagerLookup} lookup strategy for JBoss AS.
*
* @author Gavin King
*/
public final class JBossTransactionManagerLookup extends JNDITransactionManagerLookup {
+ public static final String AS4_TM_NAME = "java:/TransactionManager";
+ public static final String AS7_TM_NAME = "java:jboss/TransactionManager";
- protected String getName() {
- return "java:/TransactionManager";
- }
+ protected String getName() {
+ return AS4_TM_NAME;
+ }
- public String getUserTransactionName() {
- return "UserTransaction";
- }
+ public String getUserTransactionName() {
+ return "UserTransaction";
+ }
+ @Override
+ public TransactionManager getTransactionManager(Properties props) throws
HibernateException {
+ try {
+ return (TransactionManager) NamingHelper.getInitialContext( props ).lookup(
getName() );
+ }
+ catch ( NamingException ne ) {
+ try {
+ return (TransactionManager) NamingHelper.getInitialContext( props
).lookup( AS7_TM_NAME );
+ }
+ catch ( NamingException ne2 ) {
+ throw new HibernateException( "Could not locate
TransactionManager", ne2 );
+ }
+ }
+ }
}
Show replies by date