01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.transaction.manager;
18:
19: import javax.transaction.TransactionManager;
20:
21: import org.apache.commons.logging.Log;
22: import org.apache.commons.logging.LogFactory;
23: import org.compass.core.config.CompassSettings;
24: import org.compass.core.transaction.TransactionException;
25: import org.compass.core.transaction.TransactionManagerLookup;
26:
27: /**
28: * TransactionManager lookup strategy for WebSphere (versions 4, 5.0 and 5.1)
29: *
30: * @author kimchy
31: */
32: public class WebSphere implements TransactionManagerLookup {
33:
34: private static final Log log = LogFactory.getLog(WebSphere.class);
35:
36: private int version;
37:
38: public TransactionManager getTransactionManager(
39: CompassSettings settings) throws TransactionException {
40: try {
41: Class clazz;
42: try {
43: clazz = Class
44: .forName("com.ibm.ws.Transaction.TransactionManagerFactory");
45: version = 5;
46: log.debug("Found WebSphere 5.1+");
47: } catch (Exception e) {
48: try {
49: clazz = Class
50: .forName("com.ibm.ejs.jts.jta.TransactionManagerFactory");
51: version = 5;
52: log.debug("Found WebSphere 5.0");
53: } catch (Exception e2) {
54: clazz = Class.forName("com.ibm.ejs.jts.jta.JTSXA");
55: version = 4;
56: log.debug("Found WebSphere 4");
57: }
58: }
59:
60: return (TransactionManager) clazz.getMethod(
61: "getTransactionManager").invoke(null);
62: } catch (Exception e) {
63: throw new TransactionException(
64: "Could not obtain WebSphere JTSXA instance", e);
65: }
66: }
67:
68: public String getUserTransactionName() {
69: return version == 5 ? "java:comp/UserTransaction"
70: : "jta/usertransaction";
71: }
72: }
|