01: /*
02: * Copyright 2004 Clinton Begin
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: package com.ibatis.sqlmap.engine.transaction.jta;
17:
18: import com.ibatis.sqlmap.client.SqlMapException;
19: import com.ibatis.sqlmap.engine.transaction.BaseTransactionConfig;
20: import com.ibatis.sqlmap.engine.transaction.Transaction;
21: import com.ibatis.sqlmap.engine.transaction.TransactionException;
22:
23: import javax.naming.InitialContext;
24: import javax.naming.NamingException;
25: import javax.sql.DataSource;
26: import javax.transaction.UserTransaction;
27: import java.sql.SQLException;
28: import java.util.Properties;
29:
30: public class JtaTransactionConfig extends BaseTransactionConfig {
31:
32: private DataSource dataSource;
33: private UserTransaction userTransaction;
34:
35: public DataSource getDataSource() {
36: return dataSource;
37: }
38:
39: public void setDataSource(DataSource ds) {
40: this .dataSource = ds;
41: }
42:
43: public void initialize(Properties props) throws SQLException,
44: TransactionException {
45: String utxName = null;
46: try {
47: utxName = (String) props.get("UserTransaction");
48: InitialContext initCtx = new InitialContext();
49: userTransaction = (UserTransaction) initCtx.lookup(utxName);
50: } catch (NamingException e) {
51: throw new SqlMapException(
52: "Error initializing JtaTransactionConfig while looking up UserTransaction ("
53: + utxName + "). Cause: " + e);
54: }
55: }
56:
57: public Transaction newTransaction(int transactionIsolation)
58: throws SQLException, TransactionException {
59: return new JtaTransaction(userTransaction, dataSource,
60: transactionIsolation);
61: }
62:
63: }
|