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

WrappedStatement

public class WrappedStatement extends Object implements StatementAccess, Statement, org.jboss.ejb.plugins.cmp.jdbc.WrappedStatement
A wrapper for a statement.
todo
remove the org.jboss.ejb.plugins.cmp.jdbc.WrappedStatement dependency
author
David Jencks
author
Adrian Brock
author
Weston Price
version
$Revision: 57189 $

Fields Summary
private final WrappedConnection
lc
private final Statement
s
private HashMap
resultSets
The result sets
private boolean
closed
Whether we are closed
private Object
lock
The state lock
Constructors Summary
public WrappedStatement(WrappedConnection lc, Statement s)


        
   
      this.lc = lc;
      this.s = s;
      lc.registerStatement(this);
   
Methods Summary
public voidaddBatch(java.lang.String sql)

      checkState();
      try
      {
         s.addBatch(sql);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidcancel()

      checkState();
      try
      {
         s.cancel();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
protected voidcheckConfiguredQueryTimeout()

      lc.checkConfiguredQueryTimeout(this);
   
protected java.sql.SQLExceptioncheckException(java.lang.Throwable t)

      throw lc.checkException(t);
   
voidcheckState()

      synchronized (lock)
      {
         if (closed)
            throw new SQLException("The statement is closed.");
      }
   
protected voidcheckTransaction()

      checkState();
      lc.checkTransaction();
   
public voidclearBatch()

      checkState();
      try
      {
         s.clearBatch();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidclearWarnings()

      checkState();
      try
      {
         s.clearWarnings();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidclose()

      synchronized (lock)
      {
         if (closed)
            return;
         
         closed = true;
      }
      lc.unregisterStatement(this);
      internalClose();
   
protected voidcloseResultSets()

      if (lc.getTrackStatements() == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_FALSE_INT)
         return;

      synchronized (this)
      {
         if (resultSets == null)
            return;
         for (Iterator i = resultSets.entrySet().iterator(); i.hasNext();)
         {
            Map.Entry entry = (Map.Entry) i.next();
            WrappedResultSet resultSet = (WrappedResultSet) entry.getKey();
            if (lc.getTrackStatements() == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_TRUE_INT)
            {
               Throwable stackTrace = (Throwable) entry.getValue();
               lc.getLogger().warn("Closing a result set you left open! Please close it yourself.", stackTrace);
            }
            try
            {
               resultSet.internalClose();
            }
            catch (Throwable t)
            {
               lc.getLogger().warn("Error closing a result set you left open! Please close it yourself.", t);
            }
         }
         resultSets.clear();
      }
   
public booleanexecute(java.lang.String sql)

      checkTransaction();
      try
      {
         checkConfiguredQueryTimeout();
         return s.execute(sql);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public booleanexecute(java.lang.String sql, int autoGeneratedKeys)

      checkTransaction();
      try
      {
         checkConfiguredQueryTimeout();
         return s.execute(sql, autoGeneratedKeys);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public booleanexecute(java.lang.String sql, int[] columnIndexes)

      checkTransaction();
      try
      {
         checkConfiguredQueryTimeout();
         return s.execute(sql, columnIndexes);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public booleanexecute(java.lang.String sql, java.lang.String[] columnNames)

      checkTransaction();
      try
      {
         checkConfiguredQueryTimeout();
         return s.execute(sql, columnNames);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public int[]executeBatch()

      checkState();
      try
      {
         checkConfiguredQueryTimeout();
         return s.executeBatch();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.ResultSetexecuteQuery(java.lang.String sql)

      checkTransaction();
      try
      {
         checkConfiguredQueryTimeout();
         ResultSet result = s.executeQuery(sql);
         return registerResultSet(result);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public intexecuteUpdate(java.lang.String sql)

      checkTransaction();
      try
      {
         checkConfiguredQueryTimeout();
         return s.executeUpdate(sql);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public intexecuteUpdate(java.lang.String sql, int autoGeneratedKeys)

      checkTransaction();
      try
      {
         checkConfiguredQueryTimeout();
         return s.executeUpdate(sql, autoGeneratedKeys);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public intexecuteUpdate(java.lang.String sql, int[] columnIndexes)

      checkTransaction();
      try
      {
         checkConfiguredQueryTimeout();
         return s.executeUpdate(sql, columnIndexes);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public intexecuteUpdate(java.lang.String sql, java.lang.String[] columnNames)

      checkTransaction();
      try
      {
         checkConfiguredQueryTimeout();
         return s.executeUpdate(sql, columnNames);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.ConnectiongetConnection()

      return lc;
   
public intgetFetchDirection()

      checkState();
      try
      {
         return s.getFetchDirection();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public intgetFetchSize()

      checkState();
      try
      {
         return s.getFetchSize();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.ResultSetgetGeneratedKeys()

      checkState();
      try
      {
         ResultSet resultSet = s.getGeneratedKeys();
         return registerResultSet(resultSet);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public intgetMaxFieldSize()

      checkState();
      try
      {
         return s.getMaxFieldSize();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public intgetMaxRows()

      checkState();
      try
      {
         return s.getMaxRows();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public booleangetMoreResults()

      checkState();
      try
      {
         return s.getMoreResults();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public booleangetMoreResults(int current)

      checkState();
      try
      {
         return s.getMoreResults(current);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public intgetQueryTimeout()

      checkState();
      try
      {
         return s.getQueryTimeout();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.ResultSetgetResultSet()

      checkState();
      try
      {
         ResultSet result = s.getResultSet();
         if (result == null)
            return null;
         else
            return registerResultSet(result);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public intgetResultSetConcurrency()

      checkState();
      try
      {
         return s.getResultSetConcurrency();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public intgetResultSetHoldability()

      checkState();
      try
      {
         return s.getResultSetHoldability();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public intgetResultSetType()

      checkState();
      try
      {
         return s.getResultSetType();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.StatementgetUnderlyingStatement()

      checkState();
      return s;
   
public intgetUpdateCount()

      checkState();
      try
      {
         return s.getUpdateCount();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public java.sql.SQLWarninggetWarnings()

      checkState();
      try
      {
         return s.getWarnings();
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
protected voidinternalClose()

      synchronized (lock)
      {
         closed = true;
      }
      try
      {
         closeResultSets();
      }
      finally
      {
         s.close();
      }
   
protected java.sql.ResultSetregisterResultSet(java.sql.ResultSet resultSet)

      if (resultSet != null)
         resultSet = new WrappedResultSet(this, resultSet);
      
      if (lc.getTrackStatements() == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_FALSE_INT)
         return resultSet;

      synchronized (this)
      {
         if (resultSets == null)
            resultSets = new HashMap();
         
         if (lc.getTrackStatements() == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_TRUE_INT)
            resultSets.put(resultSet, new Throwable("STACKTRACE"));
         else
            resultSets.put(resultSet, null);
      }
      return resultSet;
   
public voidsetCursorName(java.lang.String name)

      checkState();
      try
      {
         s.setCursorName(name);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidsetEscapeProcessing(boolean enable)

      checkState();
      try
      {
         s.setEscapeProcessing(enable);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidsetFetchDirection(int direction)

      checkState();
      try
      {
         s.setFetchDirection(direction);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidsetFetchSize(int rows)

      checkState();
      try
      {
         s.setFetchSize(rows);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidsetMaxFieldSize(int max)

      checkState();
      try
      {
         s.setMaxFieldSize(max);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidsetMaxRows(int max)

      checkState();
      try
      {
         s.setMaxRows(max);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
public voidsetQueryTimeout(int timeout)

      checkState();
      try
      {
         s.setQueryTimeout(timeout);
      }
      catch (Throwable t)
      {
         throw checkException(t);
      }
   
protected voidunregisterResultSet(WrappedResultSet resultSet)

      if (lc.getTrackStatements() == BaseWrapperManagedConnectionFactory.TRACK_STATEMENTS_FALSE_INT)
         return;

      synchronized (this)
      {
         if (resultSets != null)
            resultSets.remove(resultSet);
      }