KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > dao > engine > transaction > ojb > OjbBrokerDaoTransaction


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.ojb;
17
18 import com.ibatis.dao.client.DaoException;
19 import com.ibatis.dao.client.DaoTransaction;
20 import org.apache.ojb.broker.PersistenceBroker;
21
22 public class OjbBrokerDaoTransaction
23     implements DaoTransaction {
24
25   private PersistenceBroker broker;
26
27   public OjbBrokerDaoTransaction(final PersistenceBroker brk) {
28
29     broker = brk;
30
31     try {
32       broker.beginTransaction();
33     } catch (final Throwable JavaDoc t) {
34       throw new DaoException("Error starting OJB broker transaction. Cause: " + t, t);
35     }
36   }
37
38   public void commit() {
39     try {
40       broker.commitTransaction();
41     } catch (final Throwable JavaDoc t) {
42       throw new DaoException("Error committing OJB broker transaction. Cause: " + t);
43     } finally {
44         if (broker != null) {
45             broker.close();
46         }
47     }
48   }
49
50   public void rollback() {
51     try {
52       broker.abortTransaction();
53     } catch (final Throwable JavaDoc t) {
54       throw new DaoException("Error ending OJB broker transaction. Cause: " + t);
55     } finally {
56         if (broker != null) {
57             broker.close();
58         }
59     }
60   }
61
62   public PersistenceBroker getBroker() {
63     return broker;
64   }
65
66 }
67
Popular Tags