/* JFox, the OpenSource J2EE Application Server
 *
 * Copyright (C) 2002 huihoo.com
 * Distributable under GNU LGPL license
 * See the GNU Lesser General Public License for more details.
 */

package org.jfox.tm;

import javax.transaction.UserTransaction;
import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.RollbackException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.TransactionManager;

/**
 * ServerSideUserTransaction 工作在服务器端,比如用在 ejb 中的 UserTransaction
 *
 * 还有一种 UserTransaction 完全工作在客户端,比如一般应用程序中的 UserTransaction
 * 或者一个 ejb 客户端(非ejb)中使用的UserTransaction 
 *
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class ServerUserTransaction implements UserTransaction {
  private static ServerUserTransaction me = new ServerUserTransaction();
  private static TransactionManager tm = null;

  private ServerUserTransaction() {
    tm = TxManager.getInstance();
  }

  public static UserTransaction getInstance(){
    return me;
  }

  public void begin() throws NotSupportedException, SystemException {
    tm.begin();
  }

  public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {
    tm.commit();
  }

  public void rollback() throws IllegalStateException, SecurityException, SystemException {
    tm.rollback();
  }

  public void setRollbackOnly() throws IllegalStateException, SystemException {
    tm.setRollbackOnly();
  }

  public int getStatus() throws SystemException {
    return tm.getStatus();
  }

  public void setTransactionTimeout(int timeout) throws SystemException {
    tm.setTransactionTimeout(timeout);
  }

  public static void main(String[] args) {

  }
}