01: //$Id: WebSphereTransactionManagerLookup.java 8469 2005-10-26 22:03:03Z oneovthafew $
02: package org.hibernate.transaction;
03:
04: import java.util.Properties;
05:
06: import javax.transaction.TransactionManager;
07:
08: import org.apache.commons.logging.Log;
09: 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
18: TransactionManagerLookup {
19:
20: private static final Log log = LogFactory
21: .getLog(WebSphereTransactionManagerLookup.class);
22: private final int wsVersion;
23: private final Class tmfClass;
24:
25: public WebSphereTransactionManagerLookup() {
26: try {
27: Class clazz;
28: int version;
29: try {
30: clazz = Class
31: .forName("com.ibm.ws.Transaction.TransactionManagerFactory");
32: version = 5;
33: log.info("WebSphere 5.1");
34: } catch (Exception e) {
35: try {
36: clazz = Class
37: .forName("com.ibm.ejs.jts.jta.TransactionManagerFactory");
38: version = 5;
39: log.info("WebSphere 5.0");
40: } catch (Exception e2) {
41: clazz = Class.forName("com.ibm.ejs.jts.jta.JTSXA");
42: version = 4;
43: log.info("WebSphere 4");
44: }
45: }
46:
47: tmfClass = clazz;
48: wsVersion = version;
49: } catch (Exception e) {
50: throw new HibernateException(
51: "Could not obtain WebSphere TransactionManagerFactory instance",
52: e);
53: }
54: }
55:
56: public TransactionManager getTransactionManager(Properties props)
57: throws HibernateException {
58: try {
59: return (TransactionManager) tmfClass.getMethod(
60: "getTransactionManager", null).invoke(null, null);
61: } catch (Exception e) {
62: throw new HibernateException(
63: "Could not obtain WebSphere TransactionManager", e);
64: }
65: }
66:
67: public String getUserTransactionName() {
68: return wsVersion == 5 ? "java:comp/UserTransaction"
69: : "jta/usertransaction";
70: }
71:
72: }
|