KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > connector > outbound > transactionlog > LogXAResource


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 package org.apache.geronimo.connector.outbound.transactionlog;
19
20 import javax.resource.ResourceException JavaDoc;
21 import javax.resource.spi.LocalTransaction JavaDoc;
22 import javax.transaction.xa.XAException JavaDoc;
23 import javax.transaction.xa.XAResource JavaDoc;
24 import javax.transaction.xa.Xid JavaDoc;
25
26 import org.apache.geronimo.transaction.manager.NamedXAResource;
27
28 /**
29  * Works with JDBCLog to provide last resource optimization for a single 1-pc database.
30  * The database work is committed when the log writes its prepare record, not here.
31  *
32  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
33  *
34  * */

35 public class LogXAResource implements NamedXAResource {
36
37     final String JavaDoc name;
38     final LocalTransaction JavaDoc localTransaction;
39     private Xid JavaDoc xid;
40
41     public LogXAResource(LocalTransaction JavaDoc localTransaction, String JavaDoc name) {
42         this.localTransaction = localTransaction;
43         this.name = name;
44     }
45     public void commit(Xid JavaDoc xid, boolean onePhase) throws XAException JavaDoc {
46     }
47
48     public void end(Xid JavaDoc xid, int flags) throws XAException JavaDoc {
49     }
50
51     public void forget(Xid JavaDoc xid) throws XAException JavaDoc {
52     }
53
54     public int getTransactionTimeout() throws XAException JavaDoc {
55         return 0;
56     }
57
58     public boolean isSameRM(XAResource JavaDoc xaResource) throws XAException JavaDoc {
59         return this == xaResource;
60     }
61
62     public int prepare(Xid JavaDoc xid) throws XAException JavaDoc {
63         return 0;
64     }
65
66     public Xid JavaDoc[] recover(int flag) throws XAException JavaDoc {
67         return new Xid JavaDoc[0];
68     }
69
70     public void rollback(Xid JavaDoc xid) throws XAException JavaDoc {
71         if (this.xid == null || !this.xid.equals(xid)) {
72             throw new XAException JavaDoc();
73         }
74         try {
75             localTransaction.rollback();
76         } catch (ResourceException JavaDoc e) {
77             throw (XAException JavaDoc)new XAException JavaDoc().initCause(e);
78         } finally {
79             this.xid = null;
80         }
81     }
82
83     public boolean setTransactionTimeout(int seconds) throws XAException JavaDoc {
84         return false;
85     }
86
87     public void start(Xid JavaDoc xid, int flag) throws XAException JavaDoc {
88         if (flag == XAResource.TMNOFLAGS) {
89             // first time in this transaction
90
if (this.xid != null) {
91                 throw new XAException JavaDoc("already enlisted");
92             }
93             this.xid = xid;
94             try {
95                 localTransaction.begin();
96             } catch (ResourceException JavaDoc e) {
97                 throw (XAException JavaDoc) new XAException JavaDoc("could not start local tx").initCause(e);
98             }
99         } else if (flag == XAResource.TMRESUME) {
100             if (xid != this.xid) {
101                 throw new XAException JavaDoc("attempting to resume in different transaction");
102             }
103         } else {
104             throw new XAException JavaDoc("unknown state");
105         }
106      }
107
108     public String JavaDoc getName() {
109         return name;
110     }
111 }
112
Popular Tags