KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > jdo > TransactionImpl


1 package org.apache.ojb.jdo;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import org.apache.ojb.otm.OTMKit;
19 import org.apache.ojb.otm.OTMConnection;
20
21 import javax.jdo.Transaction;
22 import javax.jdo.PersistenceManager;
23 import javax.jdo.JDOUserException;
24 import javax.jdo.JDOUnsupportedOptionException;
25 import javax.transaction.Synchronization JavaDoc;
26
27 /**
28  * @author <a HREF="mailto:mattbaird@yahoo.com">Matthew Baird</a>
29  * @author <a HREF="mailto:brianm@apache.org">Brian McCallister</a>
30  */

31 public class TransactionImpl implements Transaction
32 {
33     private PersistenceManager m_pm;
34     private OTMKit m_kit;
35     private OTMConnection m_conn;
36
37     public TransactionImpl(PersistenceManager pm, OTMKit kit, OTMConnection conn)
38     {
39         m_pm = pm;
40         m_conn = conn;
41         m_kit = kit;
42     }
43
44     public void begin()
45     {
46         if (m_kit.getTransaction(m_conn).isInProgress())
47         {
48             throw new JDOUserException("Transaction already in progress");
49         }
50         m_kit.getTransaction(m_conn).begin();
51     }
52
53     public void commit()
54     {
55         if (!m_kit.getTransaction(m_conn).isInProgress())
56         {
57             throw new JDOUserException("Transaction not in progress");
58         }
59         m_kit.getTransaction(m_conn).commit();
60     }
61
62     public void rollback()
63     {
64         if (!m_kit.getTransaction(m_conn).isInProgress())
65         {
66             throw new JDOUserException("Transaction not in progress");
67         }
68         m_kit.getTransaction(m_conn).rollback();
69     }
70
71     public boolean isActive()
72     {
73         return m_kit.getTransaction(m_conn).isInProgress();
74     }
75
76     public void setNontransactionalRead(boolean b)
77     {
78         throw new javax.jdo.JDOUnsupportedOptionException("Unsupported");
79     }
80
81     public boolean getNontransactionalRead()
82     {
83         return false;
84     }
85
86     public void setNontransactionalWrite(boolean b)
87     {
88         throw new javax.jdo.JDOUnsupportedOptionException("Unsupported");
89     }
90
91     public boolean getNontransactionalWrite()
92     {
93         return false;
94     }
95
96     /**
97      * @todo figure out what to do if someone doesn't want this!
98      */

99     public void setRetainValues(boolean b)
100     {
101         // umh, this is always true.
102
}
103
104     public boolean getRetainValues()
105     {
106         return true;
107     }
108
109     /**
110      * @todo implement
111      */

112     public void setRestoreValues(boolean b)
113     {
114         throw new JDOUnsupportedOptionException("Not Yet Implemented");
115     }
116
117     /**
118      * @todo implement
119      */

120     public boolean getRestoreValues()
121     {
122         return false;
123     }
124
125     /**
126      * @todo implement
127      */

128     public void setOptimistic(boolean b)
129     {
130         throw new JDOUnsupportedOptionException("Not yet implemented");
131     }
132
133     /**
134      * @todo implement
135      */

136     public boolean getOptimistic()
137     {
138         return false;
139     }
140
141     /**
142      * @todo figure out how to implement
143      * @param synchronization
144      */

145     public void setSynchronization(Synchronization JavaDoc synchronization)
146     {
147         throw new JDOUnsupportedOptionException("Not Yet Implemented");
148     }
149
150     /**
151      * @todo figure out how to implement
152      */

153     public Synchronization JavaDoc getSynchronization()
154     {
155         throw new JDOUnsupportedOptionException("Not Yet Implemented");
156     }
157
158     public PersistenceManager getPersistenceManager()
159     {
160         return m_pm;
161     }
162 }
163
Popular Tags