org.mmbase.module.database
Class MultiStatement

java.lang.Object
  extended by org.mmbase.module.database.MultiStatement
All Implemented Interfaces:
Statement, Wrapper

public class MultiStatement
extends Object
implements Statement

MultiStatement is a wrapper class for a callable Statement obtained by a MultiConnection object. The sole function of this class is to log the sql statement passed to it using the MultiConnection that called it - all calls are then passed to the Statement object passed to the constructor.

Version:
$Id: MultiStatement.java 34900 2009-05-01 16:29:42Z michiel $
Author:
vpro, Pierre van Rooden
Sql:
It would possibly be better to pass the logging of the sql query to the code that calls the statement, rather than place it in the statement itself, as it's implementation leads to conflicts between various JDBC versions.

Field Summary
(package private)  MultiConnection parent
          The connection that created this statement.
 
Fields inherited from interface java.sql.Statement
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO
 
Constructor Summary
MultiStatement(MultiConnection parent, Statement s)
           
 
Method Summary
 void addBatch(String sql)
           
 void cancel()
           
protected  Statement checkAfterException()
          Tries to fix the parent connection, if it proves to be broken.
 void clearBatch()
           
 void clearWarnings()
           
 void close()
           
 boolean execute(String sql)
           
 boolean execute(String sql, int autoGeneratedKeys)
          Executes the given SQL statement, which may return multiple results, and signals the driver that any auto-generated keys should be made available for retrieval.
 boolean execute(String sql, int[] columnIndexes)
          Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.
 boolean execute(String sql, String[] columnNames)
          Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.
 int[] executeBatch()
           
 ResultSet executeQuery(String sql)
           
 int executeUpdate(String sql)
           
 int executeUpdate(String sql, int autoGeneratedKeys)
          Executes the given SQL statement and signals the driver with the given flag about whether the auto-generated keys produced by this Statement object should be made available for retrieval.
 int executeUpdate(String sql, int[] columnIndexes)
          Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.
 int executeUpdate(String sql, String[] columnNames)
          Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.
 Connection getConnection()
           
 int getFetchDirection()
           
 int getFetchSize()
           
 ResultSet getGeneratedKeys()
          Retrieves any auto-generated keys created as a result of executing this Statement object.
 int getMaxFieldSize()
           
 int getMaxRows()
           
 boolean getMoreResults()
           
 boolean getMoreResults(int current)
          Moves to this Statement object's next result, deals with any current ResultSet object(s) according to the instructions specified by the given flag, and returns true if the next result is a ResultSet object.
 int getQueryTimeout()
           
 ResultSet getResultSet()
           
 int getResultSetConcurrency()
           
 int getResultSetHoldability()
          Retrieves the result set holdability for ResultSet objects generated by this Statement object.
 int getResultSetType()
           
 int getUpdateCount()
           
 SQLWarning getWarnings()
           
 boolean isClosed()
           
 boolean isPoolable()
           
 boolean isWrapperFor(Class<?> iface)
           
 void setCursorName(String name)
           
 void setEscapeProcessing(boolean enable)
           
 void setFetchDirection(int dir)
           
 void setFetchSize(int i)
           
 void setMaxFieldSize(int max)
           
 void setMaxRows(int max)
           
 void setPoolable(boolean p)
           
 void setQueryTimeout(int seconds)
           
<T> T
unwrap(Class<T> iface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

MultiConnection parent
The connection that created this statement.

Constructor Detail

MultiStatement

MultiStatement(MultiConnection parent,
               Statement s)
Javadoc:
Method Detail

executeUpdate

public int executeUpdate(String sql)
                  throws SQLException
Specified by:
executeUpdate in interface Statement
Throws:
SQLException
Javadoc:

close

public void close()
           throws SQLException
Specified by:
close in interface Statement
Throws:
SQLException
Javadoc:

getMaxFieldSize

public int getMaxFieldSize()
                    throws SQLException
Specified by:
getMaxFieldSize in interface Statement
Throws:
SQLException
Javadoc:

setMaxFieldSize

public void setMaxFieldSize(int max)
                     throws SQLException
Specified by:
setMaxFieldSize in interface Statement
Throws:
SQLException
Javadoc:

getMaxRows

public int getMaxRows()
               throws SQLException
Specified by:
getMaxRows in interface Statement
Throws:
SQLException
Javadoc:

setMaxRows

public void setMaxRows(int max)
                throws SQLException
Specified by:
setMaxRows in interface Statement
Throws:
SQLException
Javadoc:

setEscapeProcessing

public void setEscapeProcessing(boolean enable)
                         throws SQLException
Specified by:
setEscapeProcessing in interface Statement
Throws:
SQLException
Javadoc:

getQueryTimeout

public int getQueryTimeout()
                    throws SQLException
Specified by:
getQueryTimeout in interface Statement
Throws:
SQLException
Javadoc:

setQueryTimeout

public void setQueryTimeout(int seconds)
                     throws SQLException
Specified by:
setQueryTimeout in interface Statement
Throws:
SQLException
Javadoc:

cancel

public void cancel()
            throws SQLException
Specified by:
cancel in interface Statement
Throws:
SQLException
Javadoc:

getWarnings

public SQLWarning getWarnings()
                       throws SQLException
Specified by:
getWarnings in interface Statement
Throws:
SQLException
Javadoc:

clearWarnings

public void clearWarnings()
                   throws SQLException
Specified by:
clearWarnings in interface Statement
Throws:
SQLException
Javadoc:

execute

public boolean execute(String sql)
                throws SQLException
Specified by:
execute in interface Statement
Throws:
SQLException
Javadoc:

getResultSet

public ResultSet getResultSet()
                       throws SQLException
Specified by:
getResultSet in interface Statement
Throws:
SQLException
Javadoc:

getUpdateCount

public int getUpdateCount()
                   throws SQLException
Specified by:
getUpdateCount in interface Statement
Throws:
SQLException
Javadoc:

getMoreResults

public boolean getMoreResults()
                       throws SQLException
Specified by:
getMoreResults in interface Statement
Throws:
SQLException
Javadoc:

setCursorName

public void setCursorName(String name)
                   throws SQLException
Specified by:
setCursorName in interface Statement
Throws:
SQLException
Javadoc:

checkAfterException

protected Statement checkAfterException()
                                 throws SQLException
Tries to fix the parent connection, if it proves to be broken. It is supposed to be broken if the query "SELECT 1 FROM WHERE 1 = 0" does yield an exception. This method is meant to be called in the catch after trying to exceute a statement.

Returns:
A new Statement object if a new Connection was successfully obtained. Or null, if 'SELECT 1' did succeed.
Throws:
SQLException - if SELECT 1 did fail an no new Connection could be obtained.
Since:
MMBase-1.7.1

executeQuery

public ResultSet executeQuery(String sql)
                       throws SQLException
Specified by:
executeQuery in interface Statement
Throws:
SQLException
Javadoc:

executeBatch

public int[] executeBatch()
                   throws SQLException
Specified by:
executeBatch in interface Statement
Throws:
SQLException
Javadoc:

setFetchDirection

public void setFetchDirection(int dir)
                       throws SQLException
Specified by:
setFetchDirection in interface Statement
Throws:
SQLException
Javadoc:

getFetchDirection

public int getFetchDirection()
                      throws SQLException
Specified by:
getFetchDirection in interface Statement
Throws:
SQLException
Javadoc:

getResultSetConcurrency

public int getResultSetConcurrency()
                            throws SQLException
Specified by:
getResultSetConcurrency in interface Statement
Throws:
SQLException
Javadoc:

getResultSetType

public int getResultSetType()
                     throws SQLException
Specified by:
getResultSetType in interface Statement
Throws:
SQLException
Javadoc:

addBatch

public void addBatch(String sql)
              throws SQLException
Specified by:
addBatch in interface Statement
Throws:
SQLException
Javadoc:

clearBatch

public void clearBatch()
                throws SQLException
Specified by:
clearBatch in interface Statement
Throws:
SQLException
Javadoc:

getConnection

public Connection getConnection()
                         throws SQLException
Specified by:
getConnection in interface Statement
Throws:
SQLException
Javadoc:

getFetchSize

public int getFetchSize()
                 throws SQLException
Specified by:
getFetchSize in interface Statement
Throws:
SQLException
Javadoc:

setFetchSize

public void setFetchSize(int i)
                  throws SQLException
Specified by:
setFetchSize in interface Statement
Throws:
SQLException
Javadoc:

getMoreResults

public boolean getMoreResults(int current)
                       throws SQLException
Moves to this Statement object's next result, deals with any current ResultSet object(s) according to the instructions specified by the given flag, and returns true if the next result is a ResultSet object.

Specified by:
getMoreResults in interface Statement
Parameters:
current - one of CLOSE_CURRENT_RESULT, KEEP_CURRENT_RESULT, or CLOSE_ALL_RESULTS
Returns:
true if the next result is a ResultSet object; false if it is an update count or there are no more results
Throws:
SQLException
Since:
MMBase 1.5, JDBC 1.4

getGeneratedKeys

public ResultSet getGeneratedKeys()
                           throws SQLException
Retrieves any auto-generated keys created as a result of executing this Statement object.

Specified by:
getGeneratedKeys in interface Statement
Returns:
a ResultSet object containing the auto-generated key(s) generated by the execution of this Statement object
Throws:
SQLException
Since:
MMBase 1.5, JDBC 1.4

executeUpdate

public int executeUpdate(String sql,
                         int autoGeneratedKeys)
                  throws SQLException
Executes the given SQL statement and signals the driver with the given flag about whether the auto-generated keys produced by this Statement object should be made available for retrieval.

Specified by:
executeUpdate in interface Statement
Parameters:
sql - must be an SQL INSERT, UPDATE or DELETE statement or an SQL statement that returns nothing
autoGeneratedKeys - a flag indicating whether auto-generated keys should be made available for retrieval
Returns:
either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
Throws:
SQLException
Since:
MMBase 1.5, JDBC 1.4

executeUpdate

public int executeUpdate(String sql,
                         int[] columnIndexes)
                  throws SQLException
Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

Specified by:
executeUpdate in interface Statement
Parameters:
sql - must be an SQL INSERT, UPDATE or DELETE statement or an SQL statement that returns nothing
columnIndexes - an array of column indexes indicating the columns that should be returned from the inserted row
Returns:
either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
Throws:
SQLException
Since:
MMBase 1.5, JDBC 1.4

executeUpdate

public int executeUpdate(String sql,
                         String[] columnNames)
                  throws SQLException
Executes the given SQL statement and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

Specified by:
executeUpdate in interface Statement
Parameters:
sql - must be an SQL INSERT, UPDATE or DELETE statement or an SQL statement that returns nothing
columnNames - - an array of the names of the columns that should be returned from the inserted row
Returns:
either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
Throws:
SQLException
Since:
MMBase 1.5, JDBC 1.4

execute

public boolean execute(String sql,
                       int autoGeneratedKeys)
                throws SQLException
Executes the given SQL statement, which may return multiple results, and signals the driver that any auto-generated keys should be made available for retrieval.

Specified by:
execute in interface Statement
Parameters:
sql - any SQL statement
autoGeneratedKeys - a flag indicating whether auto-generated keys should be made available for retrieval
Returns:
true if the first result is a ResultSet object; false if it is an update count or there are no results
Throws:
SQLException
Since:
MMBase 1.5, JDBC 1.4

execute

public boolean execute(String sql,
                       int[] columnIndexes)
                throws SQLException
Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

Specified by:
execute in interface Statement
Parameters:
sql - any SQL statement
columnIndexes - an array of column indexes indicating the columns that should be returned from the inserted row
Returns:
true if the first result is a ResultSet object; false if it is an update count or there are no results
Throws:
SQLException
Since:
MMBase 1.5, JDBC 1.4

execute

public boolean execute(String sql,
                       String[] columnNames)
                throws SQLException
Executes the given SQL statement, which may return multiple results, and signals the driver that the auto-generated keys indicated in the given array should be made available for retrieval.

Specified by:
execute in interface Statement
Parameters:
sql - any SQL statement
columnNames - - an array of the names of the columns that should be returned from the inserted row
Returns:
true if the first result is a ResultSet object; false if it is an update count or there are no results
Throws:
SQLException
Since:
MMBase 1.5, JDBC 1.4

getResultSetHoldability

public int getResultSetHoldability()
                            throws SQLException
Retrieves the result set holdability for ResultSet objects generated by this Statement object.

Specified by:
getResultSetHoldability in interface Statement
Returns:
either ResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMIT
Throws:
SQLException
Since:
MMBase 1.5, JDBC 1.4

isClosed

public boolean isClosed()
                 throws SQLException
Specified by:
isClosed in interface Statement
Throws:
SQLException

setPoolable

public void setPoolable(boolean p)
                 throws SQLException
Specified by:
setPoolable in interface Statement
Throws:
SQLException

isPoolable

public boolean isPoolable()
                   throws SQLException
Specified by:
isPoolable in interface Statement
Throws:
SQLException

unwrap

public <T> T unwrap(Class<T> iface)
Specified by:
unwrap in interface Wrapper

isWrapperFor

public boolean isWrapperFor(Class<?> iface)
Specified by:
isWrapperFor in interface Wrapper


MMBase 2.0-SNAPSHOT - null