KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > transaction > WebSphereTransactionManagerLookup


1 //$Id: WebSphereTransactionManagerLookup.java,v 1.2 2004/06/28 23:58:07 epbernard Exp $
2
package org.hibernate.transaction;
3
4 import java.util.Properties JavaDoc;
5
6 import javax.transaction.TransactionManager JavaDoc;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10
11 import org.hibernate.HibernateException;
12
13 /**
14  * TransactionManager lookup strategy for WebSphere (versions 4, 5.0 and 5.1)
15  * @author Gavin King
16  */

17 public class WebSphereTransactionManagerLookup implements TransactionManagerLookup {
18
19     private static final Log log = LogFactory.getLog(WebSphereTransactionManagerLookup.class);
20     private int version;
21
22     /**
23      * @see org.hibernate.transaction.TransactionManagerLookup#getTransactionManager(Properties)
24      */

25     public TransactionManager JavaDoc getTransactionManager(Properties JavaDoc props) throws HibernateException {
26         try {
27             Class JavaDoc clazz;
28             try {
29                 clazz = Class.forName("com.ibm.ws.Transaction.TransactionManagerFactory");
30                 version = 5;
31                 log.info("WebSphere 5.1");
32             }
33             catch (Exception JavaDoc e) {
34                 try {
35                     clazz = Class.forName("com.ibm.ejs.jts.jta.TransactionManagerFactory");
36                     version = 5;
37                     log.info("WebSphere 5.0");
38                 }
39                 catch (Exception JavaDoc e2) {
40                     clazz = Class.forName("com.ibm.ejs.jts.jta.JTSXA");
41                     version = 4;
42                     log.info("WebSphere 4");
43                 }
44             }
45
46             return (TransactionManager JavaDoc) clazz.getMethod("getTransactionManager", null).invoke(null, null);
47         }
48         catch (Exception JavaDoc e) {
49             throw new HibernateException( "Could not obtain WebSphere JTSXA instance", e );
50         }
51     }
52
53     public String JavaDoc getUserTransactionName() {
54         return version==5 ?
55             "java:comp/UserTransaction":
56             "jta/usertransaction";
57     }
58
59 }
Popular Tags