KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > db > dao > jdbc > SqlMap2DaoTransactionPool


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.db.dao.jdbc;
17
18 import com.ibatis.common.exception.NestedRuntimeException;
19 import com.ibatis.common.resources.Resources;
20 import com.ibatis.db.dao.DaoException;
21 import com.ibatis.db.dao.DaoTransaction;
22 import com.ibatis.db.dao.DaoTransactionPool;
23 import com.ibatis.sqlmap.client.SqlMapClient;
24 import com.ibatis.sqlmap.client.SqlMapClientBuilder;
25
26 import java.io.Reader JavaDoc;
27 import java.sql.SQLException JavaDoc;
28 import java.util.Map JavaDoc;
29
30 public class SqlMap2DaoTransactionPool implements DaoTransactionPool {
31
32   private SqlMapClient sqlMap;
33
34   public void configure(Map JavaDoc properties)
35       throws DaoException {
36
37     try {
38       String JavaDoc xmlConfig = (String JavaDoc) properties.get("sql-map-config-file");
39
40       Reader JavaDoc reader = Resources.getResourceAsReader(xmlConfig);
41       sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
42     } catch (Exception JavaDoc e) {
43       throw new NestedRuntimeException("Error configuring SqlMapClientDaoTransactionPool. Cause: " + e, e);
44     }
45
46   }
47
48   public DaoTransaction getTransaction()
49       throws DaoException {
50     try {
51       sqlMap.startTransaction();
52       return new SqlMap2DaoTransaction(sqlMap);
53     } catch (SQLException JavaDoc e) {
54       throw new DaoException("Error getting transaction. Cause: " + e, e);
55     }
56   }
57
58   public void releaseTransaction(DaoTransaction trans)
59       throws DaoException {
60     // No implementation required.
61
}
62
63   public SqlMapClient getSqlMapClient() {
64     return sqlMap;
65   }
66
67
68 }
69
Popular Tags