FileDocCategorySizeDatePackage
WrappedConnection.javaAPI DocJBoss 4.2.115606Fri Jul 13 21:01:14 BST 2007org.jboss.resource.adapter.jdbc

WrappedConnection

public class WrappedConnection extends Object implements Connection
A wrapper for a connection.
author
David Jencks
author
Adrian Brock
version
$Revision: 57189 $

Fields Summary
private static final Logger
log
private BaseWrapperManagedConnection
mc
private WrapperDataSource
dataSource
private HashMap
statements
private boolean
closed
private int
trackStatements
Constructors Summary
public WrappedConnection(BaseWrapperManagedConnection mc)

   
      
   
      this.mc = mc;
      if (mc != null)
         trackStatements = mc.getTrackStatements();
   
Methods Summary
voidcheckConfiguredQueryTimeout(WrappedStatement ws)

      if (mc == null || dataSource == null)
         return;

      int timeout = 0; 
      
      // Use the transaction timeout
      if (mc.isTransactionQueryTimeout())
         timeout = dataSource.getTimeLeftBeforeTransactionTimeout();
      
      // Look for a configured value
      if (timeout <= 0)
         timeout = mc.getQueryTimeout();
      
      if (timeout > 0)
         ws.setQueryTimeout(timeout);
   
protected java.sql.SQLExceptioncheckException(java.lang.Throwable t)
The base checkException method rethrows the supplied exception, informing the ManagedConnection of the error. Subclasses may override this to filter exceptions based on their severity.

param
e a SQLException value
exception
Exception if an error occurs

      if (mc != null)
         mc.connectionError(t);
      if (t instanceof SQLException)
         throw (SQLException) t;
      else
         throw new NestedSQLException("Error", t);
   
protected voidcheckStatus()
The checkStatus method checks that the handle has not been closed and that it is associated with a managed connection.

exception
SQLException if an error occurs

      if (closed)
         throw new SQLException("Connection handle has been closed and is unusable");
      if (mc == null)
         throw new SQLException("Connection handle is not currently associated with a ManagedConnection");
   
voidcheckTransaction()

      checkStatus();
      mc.checkTransaction();
   
public voidclearWarnings()

      checkTransaction();
      try
      {
         mc.getConnection().clearWarnings();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidclose()

      closed = true;
      if (mc != null)
      {
         if (trackStatements != BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_FALSE_INT)
         {
            synchronized (this)
            {
               if (statements != null)
               {
                  for (Iterator i = statements.entrySet().iterator(); i.hasNext(); )
                  {
                     Map.Entry entry = (Map.Entry) i.next();
                     WrappedStatement ws = (WrappedStatement) entry.getKey();
                     if (trackStatements == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_TRUE_INT)
                     {
                        Throwable stackTrace = (Throwable) entry.getValue();
                        log.warn("Closing a statement you left open, please do your own housekeeping", stackTrace);
                     }
                     try
                     {
                        ws.internalClose();
                     }
                     catch (Throwable t)
                     {
                        log.warn("Exception trying to close statement:", t);
                     }
                  }
               }
            }
         }
         mc.closeHandle(this);
      }
      mc = null;
      dataSource = null;
   
public voidcommit()

      checkTransaction();
      mc.jdbcCommit();
   
public java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency)

      checkTransaction();
      try
      {
         return new WrappedStatement(this, mc.getConnection().createStatement(resultSetType, resultSetConcurrency));
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.StatementcreateStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)


      checkTransaction();
      try
      {
         return new WrappedStatement(this, mc.getConnection()
               .createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.StatementcreateStatement()

      checkTransaction();
      try
      {
         return new WrappedStatement(this, mc.getConnection().createStatement());
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public booleangetAutoCommit()

      checkStatus();
      return mc.isJdbcAutoCommit();
   
public java.lang.StringgetCatalog()

      checkTransaction();
      try
      {
         return mc.getConnection().getCatalog();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public WrapperDataSourcegetDataSource()

      return dataSource;
   
public intgetHoldability()

      checkTransaction();
      try
      {
         return mc.getConnection().getHoldability();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
org.jboss.logging.LoggergetLogger()

      return log;
   
public java.sql.DatabaseMetaDatagetMetaData()

      checkTransaction();
      try
      {
         return mc.getConnection().getMetaData();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
intgetTrackStatements()

      return trackStatements;
   
public intgetTransactionIsolation()

      checkStatus();
      return mc.getJdbcTransactionIsolation();
   
public java.util.MapgetTypeMap()

      checkTransaction();
      try
      {
         return mc.getConnection().getTypeMap();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.ConnectiongetUnderlyingConnection()

      checkTransaction();
      return mc.getConnection();
   
public java.sql.SQLWarninggetWarnings()

      checkTransaction();
      try
      {
         return mc.getConnection().getWarnings();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public booleanisClosed()

      return closed;
   
public booleanisReadOnly()

      checkStatus();
      return mc.isJdbcReadOnly();
   
public java.lang.StringnativeSQL(java.lang.String sql)

      checkTransaction();
      try
      {
         return mc.getConnection().nativeSQL(sql);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.CallableStatementprepareCall(java.lang.String sql)

      checkTransaction();
      try
      {
         return new WrappedCallableStatement(this, mc.prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)

      checkTransaction();
      try
      {
         return new WrappedCallableStatement(this, mc.prepareCall(sql, resultSetType, resultSetConcurrency));
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.CallableStatementprepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)


      checkTransaction();
      try
      {
         return new WrappedCallableStatement(this, mc.getConnection()
               .prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.PreparedStatementprepareStatement(java.lang.String sql)

      checkTransaction();
      try
      {
         return new WrappedPreparedStatement(this, mc.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)

      checkTransaction();
      try
      {
         return new WrappedPreparedStatement(this, mc.prepareStatement(sql, resultSetType, resultSetConcurrency));
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)

      checkTransaction();
      try
      {
         return new WrappedPreparedStatement(this, mc.getConnection()
               .prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int autoGeneratedKeys)

      checkTransaction();
      try
      {
         return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, autoGeneratedKeys));
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, int[] columnIndexes)

      checkTransaction();
      try
      {
         return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, columnIndexes));
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.PreparedStatementprepareStatement(java.lang.String sql, java.lang.String[] columnNames)


      checkTransaction();
      try
      {
         return new WrappedPreparedStatement(this, mc.getConnection().prepareStatement(sql, columnNames));
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
voidregisterStatement(WrappedStatement ws)

      if (trackStatements == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_FALSE_INT)
         return;
      
      synchronized (this)
      {
         if (statements == null)
            statements = new HashMap();
         
         if (trackStatements == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_TRUE_INT)
            statements.put(ws, new Throwable("STACKTRACE"));
         else
            statements.put(ws, null);
      }
   
public voidreleaseSavepoint(java.sql.Savepoint savepoint)

      checkTransaction();
      try
      {
         mc.getConnection().releaseSavepoint(savepoint);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidrollback()

      checkTransaction();
      mc.jdbcRollback();
   
public voidrollback(java.sql.Savepoint savepoint)

      checkTransaction();
      mc.jdbcRollback(savepoint);
   
public voidsetAutoCommit(boolean autocommit)

      checkStatus();
      mc.setJdbcAutoCommit(autocommit);
   
public voidsetCatalog(java.lang.String catalog)

      checkTransaction();
      try
      {
         mc.getConnection().setCatalog(catalog);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
protected voidsetDataSource(WrapperDataSource dataSource)

      this.dataSource = dataSource;
   
public voidsetHoldability(int holdability)

      checkTransaction();
      try
      {
         mc.getConnection().setHoldability(holdability);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
voidsetManagedConnection(BaseWrapperManagedConnection mc)

      this.mc = mc;
      if (mc != null)
         trackStatements = mc.getTrackStatements();
   
public voidsetReadOnly(boolean readOnly)

      checkStatus();
      mc.setJdbcReadOnly(readOnly);
   
public java.sql.SavepointsetSavepoint()

      checkTransaction();
      try
      {
         return mc.getConnection().setSavepoint();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.SavepointsetSavepoint(java.lang.String name)

      checkTransaction();
      try
      {
         return mc.getConnection().setSavepoint(name);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidsetTransactionIsolation(int isolationLevel)

      checkStatus();
      mc.setJdbcTransactionIsolation(isolationLevel);
   
public voidsetTypeMap(java.util.Map typeMap)

      checkTransaction();
      try
      {
         mc.getConnection().setTypeMap(typeMap);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
voidunregisterStatement(WrappedStatement ws)

      if (trackStatements == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_FALSE_INT)
         return;
      synchronized (this)
      {
         if (statements != null)
            statements.remove(ws);
      }