001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.embedded;
023:
024: import java.io.IOException;
025: import java.io.ObjectInput;
026: import java.io.ObjectOutput;
027: import javax.transaction.HeuristicMixedException;
028: import javax.transaction.HeuristicRollbackException;
029: import javax.transaction.NotSupportedException;
030: import javax.transaction.RollbackException;
031: import javax.transaction.SystemException;
032: import javax.transaction.Transaction;
033: import javax.transaction.TransactionManager;
034: import javax.transaction.UserTransaction;
035: import org.jboss.logging.Logger;
036: import org.jboss.ejb3.tx.TxUtil;
037:
038: /**
039: * Comment
040: *
041: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
042: * @version $Revision: 60233 $
043: */
044: public final class UserTransactionImpl implements UserTransaction,
045: java.io.Externalizable {
046: protected static Logger log = Logger
047: .getLogger(UserTransactionImpl.class);
048:
049: /**
050: * Timeout value in seconds for new transactions started
051: * by this bean instance.
052: */
053: private TransactionManager tm;
054:
055: public UserTransactionImpl() {
056: }
057:
058: public void start() {
059: if (log.isDebugEnabled())
060: log.debug("new UserTx: " + this );
061: this .tm = TxUtil.getTransactionManager();
062: }
063:
064: public void stop() {
065: this .tm = null;
066: }
067:
068: public void begin() throws NotSupportedException, SystemException {
069: // Start the transaction
070: tm.begin();
071:
072: Transaction tx = tm.getTransaction();
073: if (log.isDebugEnabled())
074: log.debug("UserTx begin: " + tx);
075:
076: }
077:
078: public void commit() throws RollbackException,
079: HeuristicMixedException, HeuristicRollbackException,
080: SecurityException, IllegalStateException, SystemException {
081: Transaction tx = tm.getTransaction();
082: if (log.isDebugEnabled())
083: log.debug("UserTx commit: " + tx);
084:
085: tm.commit();
086: }
087:
088: public void rollback() throws IllegalStateException,
089: SecurityException, SystemException {
090: Transaction tx = tm.getTransaction();
091: if (log.isDebugEnabled())
092: log.debug("UserTx rollback: " + tx);
093: tm.rollback();
094: }
095:
096: public void setRollbackOnly() throws IllegalStateException,
097: SystemException {
098: Transaction tx = tm.getTransaction();
099: if (log.isDebugEnabled())
100: log.debug("UserTx setRollbackOnly: " + tx);
101:
102: tm.setRollbackOnly();
103: }
104:
105: public int getStatus() throws SystemException {
106: return tm.getStatus();
107: }
108:
109: /**
110: * Set the transaction timeout value for new transactions
111: * started by this instance.
112: */
113: public void setTransactionTimeout(int seconds)
114: throws SystemException {
115: tm.setTransactionTimeout(seconds);
116: }
117:
118: public void writeExternal(ObjectOutput out) throws IOException {
119: //To change body of implemented methods use File | Settings | File Templates.
120: }
121:
122: public void readExternal(ObjectInput in) throws IOException,
123: ClassNotFoundException {
124: this.tm = TxUtil.getTransactionManager();
125: }
126:
127: }
|