KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > dao > engine > transaction > sqlmap > SqlMapDaoTransaction


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.dao.engine.transaction.sqlmap;
17
18 import com.ibatis.dao.client.DaoException;
19 import com.ibatis.dao.engine.transaction.ConnectionDaoTransaction;
20 import com.ibatis.sqlmap.client.SqlMapClient;
21
22 import java.sql.Connection JavaDoc;
23 import java.sql.SQLException JavaDoc;
24
25 public class SqlMapDaoTransaction implements ConnectionDaoTransaction {
26
27   private SqlMapClient client;
28
29   public SqlMapDaoTransaction(SqlMapClient client) {
30     try {
31       client.startTransaction();
32       this.client = client;
33     } catch (SQLException JavaDoc e) {
34       throw new DaoException("Error starting SQL Map transaction. Cause: " + e, e);
35     }
36   }
37
38   public void commit() {
39     try {
40       client.commitTransaction();
41       client.endTransaction();
42     } catch (SQLException JavaDoc e) {
43       throw new DaoException("Error committing SQL Map transaction. Cause: " + e, e);
44     }
45   }
46
47   public void rollback() {
48     try {
49       client.endTransaction();
50     } catch (SQLException JavaDoc e) {
51       throw new DaoException("Error ending SQL Map transaction. Cause: " + e, e);
52     }
53   }
54
55   public SqlMapClient getSqlMap() {
56     return client;
57   }
58
59   public Connection JavaDoc getConnection() {
60     try {
61       return client.getCurrentConnection();
62     } catch (SQLException JavaDoc e) {
63       throw new DaoException("Error getting connection from SQL Map Client. Cause: " + e, e);
64     }
65   }
66
67 }
68
Popular Tags