package org.jboss.resource.adapter.jdbc.local;
import org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import org.jboss.resource.JBossResourceException;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionEvent;
import javax.resource.spi.ConnectionEventListener;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.LocalTransaction;
import javax.resource.spi.LocalTransaction;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ManagedConnectionMetaData;
import javax.resource.spi.security.PasswordCredential;
import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;
public class LocalManagedConnection
extends BaseWrapperManagedConnection
implements LocalTransaction
{
public LocalManagedConnection (final LocalManagedConnectionFactory mcf,
final Connection con,
final Properties props,
final int transactionIsolation,
final int psCacheSize)
throws SQLException
{
super(mcf, con, props, transactionIsolation, psCacheSize);
}
public LocalTransaction getLocalTransaction() throws ResourceException
{
return this;
}
public XAResource getXAResource() throws ResourceException
{
throw new JBossResourceException("Local tx only!");
}
public void commit() throws ResourceException
{
synchronized (stateLock)
{
if (inManagedTransaction)
inManagedTransaction = false;
else
throw new JBossResourceException("Trying to commit outside of a local tx");
}
try
{
con.commit();
}
catch (SQLException e)
{
checkException(e);
}
}
public void rollback() throws ResourceException
{
synchronized (stateLock)
{
if (inManagedTransaction)
inManagedTransaction = false;
else
throw new JBossResourceException("Trying to rollback outside of a local tx");
}
try
{
con.rollback();
}
catch (SQLException e)
{
try
{
checkException(e);
}
catch (Exception e2) {}
}
}
public void begin() throws ResourceException
{
synchronized (stateLock)
{
if (inManagedTransaction == false)
{
try
{
if (underlyingAutoCommit)
{
underlyingAutoCommit = false;
con.setAutoCommit(false);
}
checkState();
inManagedTransaction = true;
}
catch (SQLException e)
{
checkException(e);
}
}
else
throw new JBossResourceException("Trying to begin a nested local tx");
}
}
Properties getProps()
{
return props;
}
}