FileDocCategorySizeDatePackage
PooledStatement.javaAPI DocExample25064Mon Mar 31 23:10:16 BST 2003org.dasein.persist

PooledStatement

public class PooledStatement extends Object implements PreparedStatement
A logical statement handed to applications as an abstraction of the underlying pooled prepared statement.
Last modified $Date$
version
$Revision$
author
George Reese

Fields Summary
private Connection
connection
The logical connection responsible for this statement.
private ArrayList
listeners
The list of listeners interested in closings of this statement.
private String
sql
The SQL behind this prepared statement.
private PreparedStatement
statement
The underlying physical statement.
Constructors Summary
public PooledStatement(Connection conn, String sql, PreparedStatement stmt)
Constructs a new pooled statement tied to the specified logical connection and prepared statement.

param
conn the logical database connection
param
sql the SQL this statemment represents
param
stmt the physical prepared statement


                                          
        
                             
        super();
        this.sql = sql;
        statement = stmt;
    
Methods Summary
public voidaddBatch()
Delegates to the underlying prepared statement.

throws
java.sql.SQLException a database error occurred

        validate();
        statement.addBatch();
    
public voidaddBatch(java.lang.String sql)
Delegates to the underlying prepared statement.

param
sql unused
throws
java.sql.SQLException a database error occurred

        validate();
        statement.addBatch(sql);
    
public voidaddStatementEventListener(StatementEventListener lstnr)
Adds a listener to this statement's list of listeners.

param
lstnr the listener to add

        synchronized( listeners ) {
            listeners.add(lstnr);
        }
    
public voidcancel()
Delegates to the underlying prepared statement.

throws
java.sql.SQLException a database error occurred

        validate();
        statement.cancel();
    
public voidclearBatch()
Delegates to the underlying prepared statement.

throws
java.sql.SQLException a database error occurred

        validate();
        statement.clearBatch();
    
public voidclearParameters()
Delegates to the underlying prepared statement.

throws
java.sql.SQLException a database error occurred

        validate();
        statement.clearParameters();
    
public voidclearWarnings()
Delegates to the underlying prepared statement.

throws
java.sql.SQLException a database error occurred

        validate();
        statement.clearWarnings();
    
public voidclose()
Closes this logical statementand notifies all listeners of the closure so that the physical statement can return to the pool. All parameters and warnings associated with the statement are cleared.

throws
java.sql.SQLException a database error occurred

        validate();
        statement.clearParameters();
        statement.clearWarnings();
        statement = null;
        synchronized( listeners ) {
            Iterator it = listeners.iterator();

            while( it.hasNext() ) {
                StatementEventListener lstnr;

                lstnr = (StatementEventListener)it.next();
                lstnr.statementClosed(new StatementEvent(sql, statement));
            }
        }
    
public booleanexecute()
Delegates to the underlying prepared statement.

return
true if the execution generated results
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.execute();
    
public booleanexecute(java.lang.String sql)
Delegates to the underlying prepared statement.

param
sql necessary from the Statement interface
return
true if the execution generated results
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.execute(sql);
    
public int[]executeBatch()
Delegates to the underlying prepared statement.

return
an array of update counts
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.executeBatch();
    
public java.sql.ResultSetexecuteQuery()
Delegates to the underlying prepared statement.

return
the query results
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.executeQuery();
    
public java.sql.ResultSetexecuteQuery(java.lang.String sql)
Delegates to the underlying prepared statement.

param
sql nonsense
return
the query results
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.executeQuery(sql);
    
public intexecuteUpdate()
Delegates to the underlying prepared statement.

return
the number of updated rows
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.executeUpdate();
    
public intexecuteUpdate(java.lang.String sql)
Delegates to the underlying prepared statement.

param
sql nonsense
return
the number of updated rows
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.executeUpdate(sql);
    
public java.sql.ConnectiongetConnection()
Provides the logical connection associated with this statement

return
the statement's connection
throws
java.sql.SQLException a database error occurred

        validate();
        return connection;
    
public intgetFetchDirection()
Delegates to the underlying prepared statement.

return
the fetch direction
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getFetchDirection();
    
public intgetFetchSize()
Delegates to the underlying prepared statement.

return
the fetch size
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getFetchSize();
    
public intgetMaxFieldSize()
Delegates to the underlying prepared statement.

return
the maximum field size
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getMaxFieldSize();
    
public intgetMaxRows()
Delegates to the underlying prepared statement.

return
the maximum number of rows
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getMaxRows();
    
public java.sql.ResultSetMetaDatagetMetaData()
Delegates to the underlying prepared statement.

return
the result set meta-data
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getMetaData();
    
public booleangetMoreResults()
Delegates to the underlying prepared statement.

return
more results!
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getMoreResults();
    
public intgetQueryTimeout()
Delegates to the underlying prepared statement.

return
the query timeout
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getQueryTimeout();
    
public java.sql.ResultSetgetResultSet()
Delegates to the underlying prepared statement.

return
the lastt result set
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getResultSet();
    
public intgetResultSetConcurrency()
Delegates to the underlying prepared statement.

return
the concurrency for result sets
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getResultSetConcurrency();
    
public intgetResultSetType()
Delegates to the underlying prepared statement.

return
the type for result sets
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getResultSetType();
    
public intgetUpdateCount()
Delegates to the underlying prepared statement.

return
the number of rows updated
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getUpdateCount();
    
public java.sql.SQLWarninggetWarnings()
Delegates to the underlying prepared statement.

return
any warnings
throws
java.sql.SQLException a database error occurred

        validate();
        return statement.getWarnings();
    
public booleanisClosed()

return
true if no statement exists

        return (statement == null);
    
public voidremoveStatementEventListener(StatementEventListener lstnr)
Removes a listener from the stable of listeners.

param
lstnr the listener to remove

        synchronized( listeners ) {
            listeners.remove(lstnr);
        }
    
public voidsetArray(int idx, java.sql.Array arr)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
arr an array value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setArray(idx, arr);
    
public voidsetAsciiStream(int idx, java.io.InputStream is, int len)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
is the input stream
param
len the length of the stream
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setAsciiStream(idx, is, len);
    
public voidsetBigDecimal(int idx, java.math.BigDecimal d)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
d the big decimal value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setBigDecimal(idx, d);
    
public voidsetBinaryStream(int idx, java.io.InputStream is, int len)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
is the input stream
param
len the lenth of the input stream
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setBinaryStream(idx, is, len);
    
public voidsetBlob(int idx, java.sql.Blob b)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
bthe blob value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setBlob(idx, b);
    
public voidsetBoolean(int idx, boolean b)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
b the boolean value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setBoolean(idx, b);
    
public voidsetByte(int idx, byte b)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
b the byte value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setByte(idx, b);
    
public voidsetBytes(int idx, byte[] data)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
data the binary data
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setBytes(idx, data);
    
public voidsetCharacterStream(int idx, java.io.Reader rdr, int len)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
rdr the reader from which the value should be read
param
len the length of the stream
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setCharacterStream(idx, rdr, len);
    
public voidsetClob(int idx, java.sql.Clob c)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
c the character large object value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setClob(idx, c);
    
public voidsetCursorName(java.lang.String name)
Delegates to the underlying prepared statement.

param
name the name of the cursor
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setCursorName(name);
    
public voidsetDate(int idx, java.sql.Date d)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
d the date value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setDate(idx, d);
    
public voidsetDate(int idx, java.sql.Date d, java.util.Calendar cal)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
d the date value
param
cal the calendar of the date
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setDate(idx, d, cal);
    
public voidsetDouble(int idx, double d)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
d the double value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setDouble(idx, d);
    
public voidsetEscapeProcessing(boolean en)
Delegates to the underlying prepared statement.

param
en whether to enable escape processing
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setEscapeProcessing(en);
    
public voidsetFetchDirection(int dir)
Delegates to the underlying prepared statement.

param
idx dir the fetch direction
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setFetchDirection(dir);
    
public voidsetFetchSize(int sz)
Delegates to the underlying prepared statement.

param
sz the fetch size
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setFetchSize(sz);
    
public voidsetFloat(int idx, float f)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
f the float value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setFloat(idx, f);
    
public voidsetInt(int idx, int x)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
x the integer value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setInt(idx, x);
    
public voidsetLong(int idx, long l)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
l the long value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setLong(idx, l);
    
public voidsetMaxFieldSize(int max)
Delegates to the underlying prepared statement.

param
max the maximum field size
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setMaxFieldSize(max);
    
public voidsetMaxRows(int max)
Delegates to the underlying prepared statement.

param
max the maximum number of rows
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setMaxRows(max);
    
public voidsetNull(int idx, int type)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
type the type from java.sql.Types
throws
java.sql.SQLException a database error occurred
see
java.sql.Types

        validate();
        statement.setNull(idx, type);
    
public voidsetNull(int idx, int type, java.lang.String name)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
type the type from java.sql.Types
param
name the user defined type name
throws
java.sql.SQLException a database error occurred
see
java.sql.Types

        validate();
        statement.setNull(idx, type, name);
    
public voidsetObject(int idx, java.lang.Object ob)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
ob the object value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setObject(idx, ob);
    
public voidsetObject(int idx, java.lang.Object ob, int type)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
ob the object value
param
type the type from java.sql.Types
throws
java.sql.SQLException a database error occurred
see
java.sql.Types

        validate();
        statement.setObject(idx, ob, type);
    
public voidsetObject(int idx, java.lang.Object ob, int type, int scale)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
ob the object value
param
type the type from java.sql.Types
param
scale the scale of the value
throws
java.sql.SQLException a database error occurred
see
java.sql.Types

        validate();
        statement.setObject(idx, ob, type, scale);
    
public voidsetQueryTimeout(int sec)
Delegates to the underlying prepared statement.

param
sec the query timeout in seconds
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setQueryTimeout(sec);
    
public voidsetRef(int idx, java.sql.Ref ref)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
ref the reference value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setRef(idx, ref);
    
public voidsetShort(int idx, short s)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
s the short value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setShort(idx, s);
    
public voidsetString(int idx, java.lang.String str)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
str the string value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setString(idx, str);
    
public voidsetTime(int idx, java.sql.Time t)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
t the time value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setTime(idx, t);
    
public voidsetTime(int idx, java.sql.Time t, java.util.Calendar cal)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
t the time value
param
cal the calendar for the time value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setTime(idx, t, cal);
    
public voidsetTimestamp(int idx, java.sql.Timestamp ts)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
ts the timestamp value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setTimestamp(idx, ts);
    
public voidsetTimestamp(int idx, java.sql.Timestamp ts, java.util.Calendar cal)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
ts the timestamp value
param
cal the calendar for the tiemstamp value
throws
java.sql.SQLException a database error occurred

        validate();
        statement.setTimestamp(idx, ts, cal);
    
public voidsetUnicodeStream(int idx, java.io.InputStream is, int len)
Delegates to the underlying prepared statement.

param
idx the index to assign a value for
param
is the input stream
param
len the length of the input stream
throws
java.sql.SQLException a database error occurred
deprecated
use setCharacterStream()

        validate();
        statement.setUnicodeStream(idx, is, len);
    
public java.lang.StringtoString()

        if( statement != null ) {
            return super.toString() + " [" + statement.toString() + "]";
        }
        else {
            return super.toString();
        }
    
private voidvalidate()
Verifies that this statement is still valid.

throws
java.sql.SQLException the statement is no longer valid

        if( isClosed() ) {
            throw new SQLException("Illegal attempt to access statement.");
        }