001 /**
002 *
003 * Copyright 2004 Hiram Chirino
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018 package org.activemq.service.impl;
019
020 import javax.jms.JMSException;
021 import javax.transaction.xa.XAException;
022
023 import org.activemq.service.Transaction;
024 import org.activemq.service.TransactionTask;
025 import org.activemq.util.JMSExceptionHelper;
026
027 /**
028 * Keeps track of all the actions the need to be done when
029 * a transaction does a commit or rollback.
030 *
031 * @version $Revision: 1.1.1.1 $
032 */
033 public class AutoCommitTransaction implements Transaction {
034
035 static final public AutoCommitTransaction AUTO_COMMIT_TRANSACTION = new AutoCommitTransaction();
036
037 private AutoCommitTransaction() {}
038
039 public void addPostCommitTask(TransactionTask task) throws JMSException {
040 try {
041 task.execute();
042 } catch (Throwable e) {
043 if( e instanceof JMSException ) {
044 throw (JMSException)e;
045 }
046 JMSExceptionHelper.newJMSException("Commit task failed: "+e,e);
047 }
048 }
049
050 public void addPostRollbackTask(TransactionTask task) throws JMSException {
051 // Canot rollback an auto commit transaction.
052 }
053
054 public void commit(boolean onePhase) throws XAException {
055 XAException xae = new XAException("Commit not implemented on Auto Commit Transactions.");
056 xae.errorCode = XAException.XAER_RMERR;
057 throw xae;
058 }
059
060 public void rollback() throws XAException {
061 XAException xae = new XAException("Rollback not implemented on Auto Commit Transactions.");
062 xae.errorCode = XAException.XAER_RMERR;
063 throw xae;
064 }
065
066 public int prepare() throws XAException {
067 XAException xae = new XAException("Prepare not implemented on Auto Commit Transactions.");
068 xae.errorCode = XAException.XAER_RMERR;
069 throw xae;
070 }
071
072 public boolean isXaTransacted() {
073 return false;
074 }
075
076 public Object getTransactionId() {
077 return null;
078 }
079 }