KickJava   Java API By Example, From Geeks To Geeks.

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


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.common.resources.Resources;
19 import com.ibatis.dao.client.DaoException;
20 import com.ibatis.dao.client.DaoTransaction;
21 import com.ibatis.dao.engine.transaction.DaoTransactionManager;
22 import com.ibatis.sqlmap.client.SqlMapClient;
23 import com.ibatis.sqlmap.client.SqlMapClientBuilder;
24
25 import java.io.IOException JavaDoc;
26 import java.io.Reader JavaDoc;
27 import java.util.Properties JavaDoc;
28
29 /**
30  * @see com.ibatis.dao.engine.transaction.DaoTransactionManager
31  */

32 public class SqlMapDaoTransactionManager implements DaoTransactionManager {
33
34   private SqlMapClient client;
35
36   /**
37    * Required by interface
38    *
39    * @param properties required by interface
40    * @see com.ibatis.dao.engine.transaction.DaoTransactionManager
41    */

42   public void configure(Properties JavaDoc properties) {
43     try {
44       Reader JavaDoc reader = null;
45       if (properties.containsKey("SqlMapConfigURL")) {
46         reader = Resources.getUrlAsReader((String JavaDoc) properties.get("SqlMapConfigURL"));
47       } else if (properties.containsKey("SqlMapConfigResource")) {
48         reader = Resources.getResourceAsReader((String JavaDoc) properties.get("SqlMapConfigResource"));
49       } else {
50         throw new DaoException("SQLMAP transaction manager requires either 'SqlMapConfigURL' or 'SqlMapConfigResource' to be specified as a property.");
51       }
52       client = SqlMapClientBuilder.buildSqlMapClient(reader, properties);
53     } catch (IOException JavaDoc e) {
54       throw new DaoException("Error configuring SQL Map. Cause: " + e);
55     }
56   }
57
58   /**
59    * Required by interface
60    *
61    * @return A new Transaction
62    * @see com.ibatis.dao.engine.transaction.DaoTransactionManager
63    */

64   public DaoTransaction startTransaction() {
65     return new SqlMapDaoTransaction(client);
66   }
67
68   /**
69    * Required by interface
70    *
71    * @param trans Required by interface
72    * @see com.ibatis.dao.engine.transaction.DaoTransactionManager
73    */

74   public void commitTransaction(DaoTransaction trans) {
75     ((SqlMapDaoTransaction) trans).commit();
76   }
77
78   /**
79    * Required by interface
80    *
81    * @param trans Required by interface
82    * @see com.ibatis.dao.engine.transaction.DaoTransactionManager
83    */

84   public void rollbackTransaction(DaoTransaction trans) {
85     ((SqlMapDaoTransaction) trans).rollback();
86   }
87
88 }
89
Popular Tags