KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > xa > XAUserTransaction


1 package org.enhydra.dods.xa;
2
3 import java.sql.SQLException JavaDoc;
4 import java.util.Vector JavaDoc;
5
6 import javax.naming.InitialContext JavaDoc;
7 import javax.transaction.HeuristicMixedException JavaDoc;
8 import javax.transaction.HeuristicRollbackException JavaDoc;
9 import javax.transaction.RollbackException JavaDoc;
10 import javax.transaction.SystemException JavaDoc;
11 import javax.transaction.UserTransaction JavaDoc;
12
13 import org.enhydra.dods.cache.DOCache;
14
15 import com.lutris.appserver.server.sql.CachedDBTransaction;
16 import com.lutris.appserver.server.sql.CoreDO;
17 import com.lutris.appserver.server.sql.DBConnection;
18 import com.lutris.appserver.server.sql.DBQuery;
19 import com.lutris.appserver.server.sql.DBTransaction;
20 import com.lutris.appserver.server.sql.Transaction;
21
22 /**
23  *
24  */

25 public class XAUserTransaction implements CachedDBTransaction {
26
27     UserTransaction JavaDoc utInternal = null;
28
29     CachedDBTransaction dbtInternal = null;
30
31     XAUserTransactionFactory factory = null;
32
33     protected XAUserTransaction(DBConnection conn, String JavaDoc utln, int defaultTimeout, XAUserTransactionFactory factory,
34                     XATransactionFactory xaTnFactory) throws DodsJtaException {
35         try {
36             this.factory = factory;
37             InitialContext JavaDoc ictx = new InitialContext JavaDoc();
38             utInternal = (UserTransaction JavaDoc) ictx.lookup(utln);
39             this.factory.makeDodsJtaThreadContext(this);
40             utInternal.setTransactionTimeout(defaultTimeout);
41             utInternal.begin();
42             dbtInternal = (CachedDBTransaction) (xaTnFactory.getTransaction(conn));
43         } catch (Exception JavaDoc e) {
44             e.printStackTrace();
45             throw new DodsJtaException("Error during XAUserTransaction creation");
46         }
47     }
48
49     /*
50      * (non-Javadoc)
51      *
52      * @see com.lutris.appserver.server.sql.CachedDBTransaction#isReleased()
53      */

54     public boolean isReleased() {
55         return dbtInternal.isReleased();
56     }
57
58     /*
59      * (non-Javadoc)
60      *
61      * @see com.lutris.appserver.server.sql.CachedDBTransaction#getDOs()
62      */

63     public CoreDO[] getDOs() {
64         return dbtInternal.getDOs();
65     }
66
67     /*
68      * (non-Javadoc)
69      *
70      * @see com.lutris.appserver.server.sql.CachedDBTransaction#saveDirtyDOs()
71      */

72     public void saveDirtyDOs() {
73         dbtInternal.saveDirtyDOs();
74     }
75
76     /*
77      * (non-Javadoc)
78      *
79      * @see com.lutris.appserver.server.sql.CachedDBTransaction#getTransactionCache()
80      */

81     public DOCache getTransactionCache() {
82         return dbtInternal.getTransactionCache();
83     }
84
85     /*
86      * (non-Javadoc)
87      *
88      * @see com.lutris.appserver.server.sql.CachedDBTransaction#getDeletedDOs()
89      */

90     public Vector JavaDoc getDeletedDOs() {
91         return dbtInternal.getDeletedDOs();
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see com.lutris.appserver.server.sql.CachedDBTransaction#addDeletedDO(com.lutris.appserver.server.sql.CoreDO)
98      */

99     public void addDeletedDO(CoreDO DO) {
100         dbtInternal.addDeletedDO(DO);
101
102     }
103
104     /*
105      * (non-Javadoc)
106      *
107      * @see com.lutris.appserver.server.sql.CachedDBTransaction#resetDeletedDOs()
108      */

109     public void resetDeletedDOs() {
110         dbtInternal.resetDeletedDOs();
111     }
112
113     /*
114      * (non-Javadoc)
115      *
116      * @see com.lutris.appserver.server.sql.CachedDBTransaction#dontAggregateDOModifications()
117      */

118     public void dontAggregateDOModifications() {
119         dbtInternal.dontAggregateDOModifications();
120
121     }
122
123     /*
124      * (non-Javadoc)
125      *
126      * @see com.lutris.appserver.server.sql.CachedDBTransaction#getAutoWrite()
127      */

128     public boolean getAutoWrite() {
129         return dbtInternal.getAutoWrite();
130     }
131
132     /*
133      * (non-Javadoc)
134      *
135      * @see com.lutris.appserver.server.sql.CachedDBTransaction#isFirstWrite()
136      */

137     public boolean isFirstWrite() {
138         return dbtInternal.isFirstWrite();
139     }
140
141     /*
142      * (non-Javadoc)
143      *
144      * @see com.lutris.appserver.server.sql.CachedDBTransaction#setFirstWrite(boolean)
145      */

146     public void setFirstWrite(boolean newfw) {
147         dbtInternal.setFirstWrite(newfw);
148     }
149
150     /*
151      * (non-Javadoc)
152      *
153      * @see com.lutris.appserver.server.sql.CachedDBTransaction#wasReadOnly()
154      */

155     public boolean wasReadOnly() {
156         return dbtInternal.wasReadOnly();
157     }
158
159     /*
160      * (non-Javadoc)
161      *
162      * @see com.lutris.appserver.server.sql.DBTransaction#update(com.lutris.appserver.server.sql.Transaction)
163      */

164     public void update(Transaction JavaDoc transaction) {
165         dbtInternal.update(transaction);
166     }
167
168     /*
169      * (non-Javadoc)
170      *
171      * @see com.lutris.appserver.server.sql.DBTransaction#delete(com.lutris.appserver.server.sql.Transaction)
172      */

173     public void delete(Transaction JavaDoc transaction) {
174         dbtInternal.delete(transaction);
175     }
176
177     /*
178      * (non-Javadoc)
179      *
180      * @see com.lutris.appserver.server.sql.DBTransaction#insert(com.lutris.appserver.server.sql.Transaction)
181      */

182     public void insert(Transaction JavaDoc transaction) {
183         dbtInternal.insert(transaction);
184     }
185
186     /*
187      * (non-Javadoc)
188      *
189      * @see com.lutris.appserver.server.sql.DBTransaction#commit()
190      */

191     public void commit() throws SQLException JavaDoc {
192         try {
193             utInternal.commit();
194         } catch (SecurityException JavaDoc e) {
195             e.printStackTrace();
196             throw new SQLException JavaDoc("SecurityException in commit:" + e.getMessage());
197         } catch (IllegalStateException JavaDoc e) {
198             e.printStackTrace();
199             throw new SQLException JavaDoc("IllegalStateException in commit:" + e.getMessage());
200         } catch (RollbackException JavaDoc e) {
201             e.printStackTrace();
202             throw new SQLException JavaDoc("RollbackException in commit:" + e.getMessage());
203         } catch (HeuristicMixedException JavaDoc e) {
204             e.printStackTrace();
205             throw new SQLException JavaDoc("HeuristicMixedException in commit:" + e.getMessage());
206         } catch (HeuristicRollbackException JavaDoc e) {
207             e.printStackTrace();
208             throw new SQLException JavaDoc("HeuristicRollbackException in commit:" + e.getMessage());
209         } catch (SystemException JavaDoc e) {
210             e.printStackTrace();
211             throw new SQLException JavaDoc("SystemException in commit:" + e.getMessage());
212         } finally {
213             this.factory.closeDodsJtaThreadContext(this);
214         }
215     }
216
217     /*
218      * (non-Javadoc)
219      *
220      * @see com.lutris.appserver.server.sql.DBTransaction#rollback()
221      */

222     public void rollback() throws SQLException JavaDoc {
223         try {
224             utInternal.rollback();
225         } catch (IllegalStateException JavaDoc e) {
226             e.printStackTrace();
227             throw new SQLException JavaDoc("IllegalStateException in rollback:" + e.getMessage());
228         } catch (SecurityException JavaDoc e) {
229             e.printStackTrace();
230             throw new SQLException JavaDoc("SecurityException in rollback:" + e.getMessage());
231         } catch (SystemException JavaDoc e) {
232             e.printStackTrace();
233             throw new SQLException JavaDoc("SystemException in rollback:" + e.getMessage());
234         } finally {
235             this.factory.closeDodsJtaThreadContext(this);
236         }
237
238     }
239
240     /*
241      * (non-Javadoc)
242      *
243      * @see com.lutris.appserver.server.sql.DBTransaction#release()
244      */

245     public void release() {
246         dbtInternal.release();
247     }
248
249     /*
250      * (non-Javadoc)
251      *
252      * @see com.lutris.appserver.server.sql.DBTransaction#handleException(java.sql.SQLException)
253      */

254     public boolean handleException(SQLException JavaDoc e) {
255         return dbtInternal.handleException(e);
256     }
257
258     /*
259      * (non-Javadoc)
260      *
261      * @see com.lutris.appserver.server.sql.DBTransaction#getDO(com.lutris.appserver.server.sql.Transaction)
262      */

263     public Transaction JavaDoc getDO(Transaction JavaDoc transaction) {
264         return dbtInternal.getDO(transaction);
265     }
266
267     /*
268      * (non-Javadoc)
269      *
270      * @see com.lutris.appserver.server.sql.DBTransaction#getDO(com.lutris.appserver.server.sql.Transaction,
271      * int)
272      */

273     public Transaction JavaDoc getDO(Transaction JavaDoc transaction, int action) {
274         return dbtInternal.getDO(transaction, action);
275     }
276
277     /*
278      * (non-Javadoc)
279      *
280      * @see com.lutris.appserver.server.sql.DBTransaction#getDatabaseName()
281      */

282     public String JavaDoc getDatabaseName() {
283         return dbtInternal.getDatabaseName();
284     }
285
286     /*
287      * (non-Javadoc)
288      *
289      * @see com.lutris.appserver.server.sql.DBTransaction#setDatabaseName(java.lang.String)
290      */

291     public void setDatabaseName(String JavaDoc dbName) {
292         dbtInternal.setDatabaseName(dbName);
293     }
294
295     /*
296      * (non-Javadoc)
297      *
298      * @see com.lutris.appserver.server.sql.DBTransaction#write()
299      */

300     public void write() throws SQLException JavaDoc {
301         dbtInternal.write();
302     }
303
304     /*
305      * (non-Javadoc)
306      *
307      * @see com.lutris.appserver.server.sql.DBTransaction#lockDO(com.lutris.appserver.server.sql.Transaction)
308      */

309     public void lockDO(Transaction JavaDoc cdo) throws SQLException JavaDoc {
310         dbtInternal.lockDO(cdo);
311     }
312
313     /*
314      * (non-Javadoc)
315      *
316      * @see com.lutris.appserver.server.sql.DBTransaction#createQuery()
317      */

318     public DBQuery createQuery() throws SQLException JavaDoc {
319         return dbtInternal.createQuery();
320     }
321
322     /*
323      * (non-Javadoc)
324      *
325      * @see com.lutris.appserver.server.sql.DBTransaction#preventCacheQueries()
326      */

327     public boolean preventCacheQueries() {
328         return dbtInternal.preventCacheQueries();
329     }
330
331     public boolean equals(Object JavaDoc trans) {
332         if (trans instanceof XAUserTransaction) {
333             XAUserTransaction xaUserTrans = (XAUserTransaction) trans;
334             return trans == this;
335         } else if (trans instanceof XATransaction) {
336             XATransaction xaTrans = (XATransaction) trans;
337             return dbtInternal.equals(xaTrans.current);
338         } else if (trans instanceof DBTransaction) {
339             DBTransaction dbTrans = (DBTransaction) trans;
340             return dbtInternal.equals(dbTrans);
341         }
342         return false;
343     }
344 }
345
Popular Tags