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

CachedPreparedStatement

public class CachedPreparedStatement extends Object implements PreparedStatement
Wrapper class for cached PreparedStatements. Keeps a refcount. When this refcount reaches 0, it will close ps.
author
Bill Burke
author
Adrian Brock
version
$Revision: 57189 $

Fields Summary
private PreparedStatement
ps
private EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean
cached
private EDU.oswego.cs.dl.util.concurrent.SynchronizedInt
inUse
private int
defaultMaxFieldSize
private int
defaultMaxRows
private int
defaultQueryTimeout
private int
defaultFetchDirection
private int
defaultFetchSize
private int
currentMaxFieldSize
private int
currentMaxRows
private int
currentQueryTimeout
private int
currentFetchDirection
private int
currentFetchSize
Constructors Summary
public CachedPreparedStatement(PreparedStatement ps)


       
   
      this.ps = ps;

      // Remember the defaults
      defaultMaxFieldSize = ps.getMaxFieldSize();
      defaultMaxRows = ps.getMaxRows();
      defaultQueryTimeout = ps.getQueryTimeout();
      defaultFetchDirection = ps.getFetchDirection();
      defaultFetchSize = ps.getFetchSize();
      currentMaxFieldSize = defaultMaxFieldSize;
      currentMaxRows = defaultMaxRows;
      currentQueryTimeout = defaultQueryTimeout;
      currentFetchDirection = defaultFetchDirection;
      currentFetchSize = defaultFetchSize;
   
Methods Summary
public voidaddBatch()

      ps.addBatch();
   
public voidaddBatch(java.lang.String sql)

      ps.addBatch(sql);
   
public voidagedOut()

      cached.set(false);
      if (inUse.get() == 0)
         ps.close();
   
public voidcancel()

      ps.cancel();
   
public voidclearBatch()

      ps.clearBatch();
   
public voidclearParameters()

      ps.clearParameters();
   
public voidclearWarnings()

      ps.clearWarnings();
   
public voidclose()

      inUse.decrement();
      if (inUse.get() == 0)
      {
         if (cached.get() == false)
            ps.close();
         else
         {
            // Reset the defaults
            if (defaultMaxFieldSize != currentMaxFieldSize)
            {
               ps.setMaxFieldSize(defaultMaxFieldSize);
               currentMaxFieldSize = defaultMaxFieldSize;
            }
            if (defaultMaxRows != currentMaxRows)
            {
               ps.setMaxRows(defaultMaxRows);
               currentMaxRows = defaultMaxRows;
            }
            if (defaultQueryTimeout != currentQueryTimeout)
            {
               ps.setQueryTimeout(defaultQueryTimeout);
               currentQueryTimeout = defaultQueryTimeout;
            }
            if (defaultFetchDirection != currentFetchDirection)
            {
               ps.setFetchDirection(defaultFetchDirection);
               currentFetchDirection = defaultFetchDirection;
            }
            if (defaultFetchSize != currentFetchSize)
            {
               ps.setFetchSize(defaultFetchSize);
               currentFetchSize = defaultFetchSize;
            }
         }
      }
   
public booleanexecute()

      return ps.execute();
   
public booleanexecute(java.lang.String sql)

      return ps.execute(sql);
   
public booleanexecute(java.lang.String sql, int autoGeneratedKeys)

      return ps.execute(sql, autoGeneratedKeys);
   
public booleanexecute(java.lang.String sql, int[] columnIndexes)

      return ps.execute(sql, columnIndexes);
   
public booleanexecute(java.lang.String sql, java.lang.String[] columnNames)

      return ps.execute(sql, columnNames);
   
public int[]executeBatch()

      return ps.executeBatch();
   
public java.sql.ResultSetexecuteQuery()

      return ps.executeQuery();
   
public java.sql.ResultSetexecuteQuery(java.lang.String sql)

      return ps.executeQuery(sql);
   
public intexecuteUpdate()

      return ps.executeUpdate();
   
public intexecuteUpdate(java.lang.String sql)

      return ps.executeUpdate(sql);
   
public intexecuteUpdate(java.lang.String sql, int autoGeneratedKeys)

      return ps.executeUpdate(sql, autoGeneratedKeys);
   
public intexecuteUpdate(java.lang.String sql, int[] columnIndexes)

      return ps.executeUpdate(sql, columnIndexes);
   
public intexecuteUpdate(java.lang.String sql, java.lang.String[] columnNames)

      return ps.executeUpdate(sql, columnNames);
   
public java.sql.ConnectiongetConnection()

      return ps.getConnection();
   
public intgetFetchDirection()

      return ps.getFetchDirection();
   
public intgetFetchSize()

      return ps.getFetchSize();
   
public java.sql.ResultSetgetGeneratedKeys()

      return ps.getGeneratedKeys();
   
public intgetMaxFieldSize()

      return ps.getMaxFieldSize();
   
public intgetMaxRows()

      return ps.getMaxRows();
   
public java.sql.ResultSetMetaDatagetMetaData()

      return ps.getMetaData();
   
public booleangetMoreResults()

      return ps.getMoreResults();
   
public booleangetMoreResults(int current)

      return ps.getMoreResults(current);
   
public java.sql.ParameterMetaDatagetParameterMetaData()

      return ps.getParameterMetaData();
   
public intgetQueryTimeout()

      return ps.getQueryTimeout();
   
public java.sql.ResultSetgetResultSet()

      return ps.getResultSet();
   
public intgetResultSetConcurrency()

      return ps.getResultSetConcurrency();
   
public intgetResultSetHoldability()

      return ps.getResultSetHoldability();
   
public intgetResultSetType()

      return ps.getResultSetType();
   
public java.sql.PreparedStatementgetUnderlyingPreparedStatement()

      return ps;
   
public intgetUpdateCount()

      return ps.getUpdateCount();
   
public java.sql.SQLWarninggetWarnings()

      return ps.getWarnings();
   
public voidinUse()

      inUse.increment();
   
public booleanisInUse()

      return inUse.get() > 0;
   
public voidsetArray(int i, java.sql.Array x)

      ps.setArray(i, x);
   
public voidsetAsciiStream(int parameterIndex, java.io.InputStream x, int length)

      ps.setAsciiStream(parameterIndex, x, length);
   
public voidsetBigDecimal(int parameterIndex, java.math.BigDecimal x)

      ps.setBigDecimal(parameterIndex, x);
   
public voidsetBinaryStream(int parameterIndex, java.io.InputStream x, int length)

      ps.setBinaryStream(parameterIndex, x, length);
   
public voidsetBlob(int i, java.sql.Blob x)

      ps.setBlob(i, x);
   
public voidsetBoolean(int parameterIndex, boolean x)

      ps.setBoolean(parameterIndex, x);
   
public voidsetByte(int parameterIndex, byte x)

      ps.setByte(parameterIndex, x);
   
public voidsetBytes(int parameterIndex, byte[] x)

      ps.setBytes(parameterIndex, x);
   
public voidsetCharacterStream(int parameterIndex, java.io.Reader reader, int length)

      ps.setCharacterStream(parameterIndex, reader, length);
   
public voidsetClob(int i, java.sql.Clob x)

      ps.setClob(i, x);
   
public voidsetCursorName(java.lang.String name)

      ps.setCursorName(name);
   
public voidsetDate(int parameterIndex, java.sql.Date x)

      ps.setDate(parameterIndex, x);
   
public voidsetDate(int parameterIndex, java.sql.Date x, java.util.Calendar cal)

      ps.setDate(parameterIndex, x, cal);
   
public voidsetDouble(int parameterIndex, double x)

      ps.setDouble(parameterIndex, x);
   
public voidsetEscapeProcessing(boolean enable)

      ps.setEscapeProcessing(enable);
   
public voidsetFetchDirection(int direction)

      ps.setFetchDirection(direction);
      currentFetchDirection = direction;
   
public voidsetFetchSize(int rows)

      ps.setFetchSize(rows);
      currentFetchSize = rows;
   
public voidsetFloat(int parameterIndex, float x)

      ps.setFloat(parameterIndex, x);
   
public voidsetInt(int parameterIndex, int x)

      ps.setInt(parameterIndex, x);
   
public voidsetLong(int parameterIndex, long x)

      ps.setLong(parameterIndex, x);
   
public voidsetMaxFieldSize(int max)

      ps.setMaxFieldSize(max);
      currentMaxFieldSize = max;
   
public voidsetMaxRows(int max)

      ps.setMaxRows(max);
      currentMaxRows = max;
   
public voidsetNull(int paramIndex, int sqlType, java.lang.String typeName)

      ps.setNull(paramIndex, sqlType, typeName);
   
public voidsetNull(int parameterIndex, int sqlType)

      ps.setNull(parameterIndex, sqlType);
   
public voidsetObject(int parameterIndex, java.lang.Object x, int targetSqlType, int scale)

      ps.setObject(parameterIndex, x, targetSqlType, scale);
   
public voidsetObject(int parameterIndex, java.lang.Object x, int targetSqlType)

      ps.setObject(parameterIndex, x, targetSqlType);
   
public voidsetObject(int parameterIndex, java.lang.Object x)

      ps.setObject(parameterIndex, x);
   
public voidsetQueryTimeout(int seconds)

      ps.setQueryTimeout(seconds);
      currentQueryTimeout = seconds;
   
public voidsetRef(int i, java.sql.Ref x)

      ps.setRef(i, x);
   
public voidsetShort(int parameterIndex, short x)

      ps.setShort(parameterIndex, x);
   
public voidsetString(int parameterIndex, java.lang.String x)

      ps.setString(parameterIndex, x);
   
public voidsetTime(int parameterIndex, java.sql.Time x)

      ps.setTime(parameterIndex, x);
   
public voidsetTime(int parameterIndex, java.sql.Time x, java.util.Calendar cal)

      ps.setTime(parameterIndex, x, cal);
   
public voidsetTimestamp(int parameterIndex, java.sql.Timestamp x)

      ps.setTimestamp(parameterIndex, x);
   
public voidsetTimestamp(int parameterIndex, java.sql.Timestamp x, java.util.Calendar cal)

      ps.setTimestamp(parameterIndex, x, cal);
   
public voidsetURL(int parameterIndex, java.net.URL x)

      ps.setURL(parameterIndex, x);
   
public voidsetUnicodeStream(int parameterIndex, java.io.InputStream x, int length)

deprecated

      ps.setUnicodeStream(parameterIndex, x, length);