KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > sqlmap > engine > transaction > jta > JtaTransactionConfig


1 /*
2  * Copyright 2004 Clinton Begin
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
24 import javax.naming.NamingException JavaDoc;
25 import javax.sql.DataSource JavaDoc;
26 import javax.transaction.UserTransaction JavaDoc;
27 import java.sql.SQLException JavaDoc;
28 import java.util.Properties JavaDoc;
29
30 public class JtaTransactionConfig extends BaseTransactionConfig {
31
32   private DataSource JavaDoc dataSource;
33   private UserTransaction JavaDoc userTransaction;
34
35   public DataSource JavaDoc getDataSource() {
36     return dataSource;
37   }
38
39   public void setDataSource(DataSource JavaDoc ds) {
40     this.dataSource = ds;
41   }
42
43   public void initialize(Properties JavaDoc props) throws SQLException JavaDoc, TransactionException {
44     String JavaDoc utxName = null;
45     try {
46       utxName = (String JavaDoc) props.get("UserTransaction");
47       InitialContext JavaDoc initCtx = new InitialContext JavaDoc();
48       userTransaction = (UserTransaction JavaDoc) initCtx.lookup(utxName);
49     } catch (NamingException JavaDoc e) {
50       throw new SqlMapException("Error initializing JtaTransactionConfig while looking up UserTransaction (" + utxName + "). Cause: " + e);
51     }
52   }
53
54   public Transaction newTransaction(int transactionIsolation) throws SQLException JavaDoc, TransactionException {
55     return new JtaTransaction(userTransaction, dataSource, transactionIsolation);
56   }
57
58 }
59
60
Popular Tags