All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.atomikos.icatch.jta.J2eeTransactionManager Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
/**
 * Copyright (C) 2000-2019 Atomikos 
 *
 * LICENSE CONDITIONS
 *
 * See http://www.atomikos.com/Main/WhichLicenseApplies for details.
 */

package com.atomikos.icatch.jta;

import java.io.Serializable;

import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.InvalidTransactionException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;

import com.atomikos.util.SerializableObjectFactory;

/**
 * An implementation of TransactionManager that should be used by J2EE
 * applications. Instances can be bound in JNDI if the application server allows
 * this.
 */
public class J2eeTransactionManager
implements TransactionManager, Serializable, Referenceable, UserTransaction
{

	private static final long serialVersionUID = 8584376600562353607L;

	private transient TransactionManagerImp tm;

    private void checkSetup() throws SystemException
    {
        tm = (TransactionManagerImp) TransactionManagerImp.getTransactionManager ();
        if (tm == null) {
            throw new RuntimeException("Transaction Service not running?");
        }
    }

    /**
     * @see javax.transaction.TransactionManager#begin()
     */
    public void begin() throws NotSupportedException, SystemException
    {
        checkSetup();
        tm.begin();

    }

    /**
     * @see javax.transaction.TransactionManager#commit()
     */
    public void commit() throws RollbackException, HeuristicMixedException,
            HeuristicRollbackException, SecurityException,
            IllegalStateException, SystemException
    {
        checkSetup();
        tm.commit();

    }

    /**
     * @see javax.transaction.TransactionManager#getStatus()
     */
    public int getStatus() throws SystemException
    {
        checkSetup();
        return tm.getStatus();
    }

    /**
     * @see javax.transaction.TransactionManager#getTransaction()
     */
    public Transaction getTransaction() throws SystemException
    {
        checkSetup();
        return tm.getTransaction();
    }

    /**
     * @see javax.transaction.TransactionManager#resume(javax.transaction.Transaction)
     */
    public void resume(Transaction tx) throws InvalidTransactionException,
            IllegalStateException, SystemException
    {
        checkSetup();
        tm.resume(tx);

    }

    /**
     * @see javax.transaction.TransactionManager#rollback()
     */
    public void rollback() throws IllegalStateException, SecurityException,
            SystemException
    {
        checkSetup();
        tm.rollback();

    }

    /**
     * @see javax.transaction.TransactionManager#setRollbackOnly()
     */
    public void setRollbackOnly() throws IllegalStateException,
            SystemException
    {
        checkSetup();
        tm.setRollbackOnly();

    }

    /**
     * @see javax.transaction.TransactionManager#setTransactionTimeout(int)
     */
    public void setTransactionTimeout(int secs) throws SystemException
    {
        checkSetup();
        tm.setTransactionTimeout(secs);

    }

    /**
     * @see javax.transaction.TransactionManager#suspend()
     */
    public Transaction suspend() throws SystemException
    {
        checkSetup();
        return tm.suspend();
    }

    public Reference getReference() throws NamingException
    {
        return SerializableObjectFactory.createReference(this);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy