Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/service/impl/LocalTransactionCommand.java


1   /**
2    * 
3    * Copyright 2004 Protique Ltd
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  package org.activemq.service.impl;
19  
20  import java.util.Map;
21  
22  import javax.transaction.xa.XAException;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.activemq.store.TransactionStore;
27  
28  /**
29   * @version $Revision: 1.1.1.1 $
30   */
31  public class LocalTransactionCommand extends AbstractTransaction {
32      private static final Log log = LogFactory.getLog(LocalTransactionCommand.class);
33  
34      private Map localTxs;
35      private String txid;
36  
37      private final TransactionStore transactionStore;
38  
39  
40      public LocalTransactionCommand(Map localTxs, String txid, TransactionStore transactionStore) {
41          this.localTxs = localTxs;
42          this.txid = txid;
43          this.transactionStore = transactionStore;
44      }
45  
46      public void commit(boolean onePhase) throws XAException {
47          // Get ready for commit.
48          try {
49              prePrepare();
50          }
51          catch (XAException e) {
52              throw e;
53          }
54          catch (Throwable e) {
55              log.warn("COMMIT FAILED: ", e);
56              rollback();
57              // Let them know we rolled back.
58              XAException xae = new XAException("COMMIT FAILED: Transaction rolled back.");
59              xae.errorCode = XAException.XA_RBOTHER;
60              xae.initCause(e);
61              throw xae;
62          }
63  
64          setState(AbstractTransaction.FINISHED_STATE);
65          localTxs.remove(txid);
66          transactionStore.commit(getTransactionId(), false);
67          
68          try {
69              postCommit();
70          }
71          catch (Throwable e) {
72              // I guess this could happen.  Post commit task failed
73              // to execute properly.
74              log.warn("POST COMMIT FAILED: ", e);
75              XAException xae = new XAException("POST COMMIT FAILED");
76              xae.errorCode = XAException.XAER_RMERR;
77              xae.initCause(e);
78              throw xae;
79          }
80      }
81  
82      public void rollback() throws XAException {
83  
84          setState(AbstractTransaction.FINISHED_STATE);
85          localTxs.remove(txid);
86          transactionStore.rollback(getTransactionId());
87  
88          try {
89              postRollback();
90          }
91          catch (Throwable e) {
92              log.warn("POST ROLLBACK FAILED: ", e);
93              XAException xae = new XAException("POST ROLLBACK FAILED");
94              xae.errorCode = XAException.XAER_RMERR;
95              xae.initCause(e);
96              throw xae;
97          }
98      }
99  
100     public int prepare() throws XAException {
101         XAException xae = new XAException("Prepare not implemented on Local Transactions.");
102         xae.errorCode = XAException.XAER_RMERR;
103         throw xae;
104     }
105 
106     public boolean isXaTransacted() {
107         return false;
108     }
109 
110     public Object getTransactionId() {
111         return txid;
112     }
113 
114 }