org.mmbase.module.database
Class MultiStatement

java.lang.Object
  extended byorg.mmbase.module.database.MultiStatement
All Implemented Interfaces:
Statement

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,v 1.18 2005/07/15 10:53:22 michiel Exp $
Author:
vpro, Pierre van Rooden
Warning: Contains Database Legacy Code
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
 
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
 
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()
           
 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 setQueryTimeout(int seconds)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

executeUpdate

public int executeUpdate(String sql)
                  throws SQLException
Specified by:
executeUpdate in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

close

public void close()
           throws SQLException
Specified by:
close in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getMaxFieldSize

public int getMaxFieldSize()
                    throws SQLException
Specified by:
getMaxFieldSize in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

setMaxFieldSize

public void setMaxFieldSize(int max)
                     throws SQLException
Specified by:
setMaxFieldSize in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getMaxRows

public int getMaxRows()
               throws SQLException
Specified by:
getMaxRows in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

setMaxRows

public void setMaxRows(int max)
                throws SQLException
Specified by:
setMaxRows in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

setEscapeProcessing

public void setEscapeProcessing(boolean enable)
                         throws SQLException
Specified by:
setEscapeProcessing in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getQueryTimeout

public int getQueryTimeout()
                    throws SQLException
Specified by:
getQueryTimeout in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

setQueryTimeout

public void setQueryTimeout(int seconds)
                     throws SQLException
Specified by:
setQueryTimeout in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

cancel

public void cancel()
            throws SQLException
Specified by:
cancel in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getWarnings

public SQLWarning getWarnings()
                       throws SQLException
Specified by:
getWarnings in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

clearWarnings

public void clearWarnings()
                   throws SQLException
Specified by:
clearWarnings in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

execute

public boolean execute(String sql)
                throws SQLException
Specified by:
execute in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getResultSet

public ResultSet getResultSet()
                       throws SQLException
Specified by:
getResultSet in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getUpdateCount

public int getUpdateCount()
                   throws SQLException
Specified by:
getUpdateCount in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getMoreResults

public boolean getMoreResults()
                       throws SQLException
Specified by:
getMoreResults in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

setCursorName

public void setCursorName(String name)
                   throws SQLException
Specified by:
setCursorName in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

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
Warning: No Java Documentation Available.

executeBatch

public int[] executeBatch()
                   throws SQLException
Specified by:
executeBatch in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

setFetchDirection

public void setFetchDirection(int dir)
                       throws SQLException
Specified by:
setFetchDirection in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getFetchDirection

public int getFetchDirection()
                      throws SQLException
Specified by:
getFetchDirection in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getResultSetConcurrency

public int getResultSetConcurrency()
                            throws SQLException
Specified by:
getResultSetConcurrency in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getResultSetType

public int getResultSetType()
                     throws SQLException
Specified by:
getResultSetType in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

addBatch

public void addBatch(String sql)
              throws SQLException
Specified by:
addBatch in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

clearBatch

public void clearBatch()
                throws SQLException
Specified by:
clearBatch in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getConnection

public Connection getConnection()
                         throws SQLException
Specified by:
getConnection in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

getFetchSize

public int getFetchSize()
                 throws SQLException
Specified by:
getFetchSize in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

setFetchSize

public void setFetchSize(int i)
                  throws SQLException
Specified by:
setFetchSize in interface Statement
Throws:
SQLException
Warning: No Java Documentation Available.

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


MMBase build 1.8.1.20060716