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

Quick Search    Search Deep

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


1   /** 
2    * 
3    * Copyright 2004 Hiram Chirino
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 javax.jms.JMSException;
21  import javax.transaction.xa.XAException;
22  
23  import org.activemq.service.Transaction;
24  import org.activemq.service.TransactionTask;
25  import org.activemq.util.JMSExceptionHelper;
26  
27  /**
28   * Keeps track of all the actions the need to be done when
29   * a transaction does a commit or rollback.
30   *
31   * @version $Revision: 1.1.1.1 $
32   */
33  public class AutoCommitTransaction implements Transaction {
34  
35      static final public AutoCommitTransaction AUTO_COMMIT_TRANSACTION = new AutoCommitTransaction();
36      
37      private AutoCommitTransaction() {}
38      
39      public void addPostCommitTask(TransactionTask task) throws JMSException {
40          try {
41              task.execute();
42          } catch (Throwable e) {
43              if( e instanceof JMSException ) {
44                  throw (JMSException)e;
45              }
46              JMSExceptionHelper.newJMSException("Commit task failed: "+e,e);
47          }
48      }
49  
50      public void addPostRollbackTask(TransactionTask task) throws JMSException {
51          // Canot rollback an auto commit transaction.
52      }
53  
54      public void commit(boolean onePhase) throws XAException {
55          XAException xae = new XAException("Commit not implemented on Auto Commit Transactions.");
56          xae.errorCode = XAException.XAER_RMERR;
57          throw xae;
58      }
59  
60      public void rollback() throws XAException {
61          XAException xae = new XAException("Rollback not implemented on Auto Commit Transactions.");
62          xae.errorCode = XAException.XAER_RMERR;
63          throw xae;
64      }
65  
66      public int prepare() throws XAException {
67          XAException xae = new XAException("Prepare not implemented on Auto Commit Transactions.");
68          xae.errorCode = XAException.XAER_RMERR;
69          throw xae;
70      }
71  
72      public boolean isXaTransacted() {
73          return false;
74      }
75  
76      public Object getTransactionId() {
77          return null;
78      }
79  }