KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > dao > engine > transaction > toplink > ToplinkDaoTransactionManager


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.toplink;
17
18 import java.util.Properties JavaDoc;
19
20 import oracle.toplink.publicinterface.UnitOfWork;
21 import oracle.toplink.threetier.Server;
22 import oracle.toplink.tools.sessionmanagement.SessionManager;
23
24 import com.ibatis.dao.client.DaoException;
25 import com.ibatis.dao.client.DaoTransaction;
26 import com.ibatis.dao.engine.transaction.DaoTransactionManager;
27
28 /**
29  * The <code>ToplinkDaoTransactionManager</code> is used by the Dao framework
30  * to manage transactions for the Toplink DAO implementation.
31  *
32  * @author Wayne Gentile
33  * @version $Revision: 152595 $ $Date: 2004-12-28 09:46:14 -0700 (Tue, 28 Dec 2004) $
34  */

35 public class ToplinkDaoTransactionManager implements DaoTransactionManager {
36
37     //~ Instance fields
38
// --------------------------------------------------------
39

40     private Server server;
41
42     private UnitOfWork uow;
43
44     //~ Methods
45
// ----------------------------------------------------------------
46

47     /**
48      * Commits pending object changes to permanent storage.
49      *
50      * @param transaction
51      * A previously started transaction.
52      *
53      * @throws DaoException
54      * If a data access exception is thrown
55      */

56     public void commitTransaction(DaoTransaction transaction)
57             throws DaoException {
58
59         ((ToplinkDaoTransaction) transaction).commit();
60
61     }
62
63     /**
64      * Called by the DAO framework upon instantiation to set configuration
65      * properties for the manager.
66      *
67      * <p>
68      * Properties are specified in the iBATIS dao.xml file.
69      * </p>
70      *
71      * @param properties
72      * The properties associated with the transaction manager
73      *
74      * @throws DaoException
75      * If a DaoException occurs
76      */

77     public void configure(Properties JavaDoc properties) throws DaoException {
78
79         // Get the name of the session and create it
80
String JavaDoc sessionName = null;
81
82         try {
83
84             SessionManager manager = SessionManager.getManager();
85
86             // Get the name of the session and create it
87
sessionName = properties.getProperty("session.name");
88             server = (Server) manager.getSession(sessionName,
89                     ToplinkDaoTransactionManager.class.getClassLoader());
90
91         } catch (Exception JavaDoc e) {
92
93             throw new DaoException(
94                     "Error configuring Toplink environment for session: "
95                             + sessionName);
96
97         }
98
99     }
100
101     /**
102      * Reverts pending object changes and returns objects to their original
103      * state.
104      *
105      * @param transaction
106      * A previously started transaction.
107      *
108      * @throws DaoException
109      * If a data access exception is thrown
110      */

111     public void rollbackTransaction(DaoTransaction transaction)
112             throws DaoException {
113
114         ((ToplinkDaoTransaction) transaction).rollback();
115
116     }
117
118     /**
119      * Starts a new transaction. Changes to objects will not be committed until
120      * further instructions are executed.
121      *
122      * @return The DaoTransaction that has been started
123      *
124      * @throws DaoException
125      * If a data access exception is thrown
126      */

127     public DaoTransaction startTransaction() throws DaoException {
128
129         ToplinkDaoTransaction trans = new ToplinkDaoTransaction(uow, server);
130
131         return trans;
132
133     }
134
135 }
Popular Tags