org.jcreme.sql
Class WrappedStatement

java.lang.Object
  extended byorg.jcreme.sql.WrappedStatement
All Implemented Interfaces:
java.sql.Statement
Direct Known Subclasses:
WrappedPreparedStatement

public class WrappedStatement
extends java.lang.Object
implements java.sql.Statement

This class enables to wrap an actual statement to provide a few extra services: tracing of the queries, handling of some exceptions (rollback, loss of connection). The ResultSets provided by this class are wrapped around the actual ResultSet.

Version:
$Revision: 1.1 $
Author:
$Author: dbregeon $

Field Summary
protected  java.lang.String baseQuery
          The initial query assigned to the Statement.
protected  java.util.Vector batchRequests
          This vector enables to store the queries contained in a batch statement.
protected  java.sql.Statement realStatement
          The underlying statement.
protected static java.lang.String UNKNOWN_QUERY
          The String displayed when no query has been assigned to the Statement yet.
 
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
WrappedStatement(java.sql.Statement statement)
          Enables to wrap a Statement.
 
Method Summary
 void addBatch(java.lang.String sql)
           
 void cancel()
           
 void clearBatch()
           
 void clearWarnings()
           
 void close()
           
 boolean execute(java.lang.String sql)
           
 boolean execute(java.lang.String sql, int autoGeneratedKeys)
           
 boolean execute(java.lang.String sql, int[] columnIndexes)
           
 boolean execute(java.lang.String sql, java.lang.String[] columnNames)
           
 int[] executeBatch()
           
 java.sql.ResultSet executeQuery(java.lang.String sql)
           
 int executeUpdate(java.lang.String sql)
           
 int executeUpdate(java.lang.String sql, int autoGeneratedKeys)
           
 int executeUpdate(java.lang.String sql, int[] columnIndexes)
           
 int executeUpdate(java.lang.String sql, java.lang.String[] columnNames)
           
protected  ConnectionLostException generateConnectionLostException(java.lang.String message, java.sql.SQLException e)
          This method generates a ConnectionLostException from an SQLException.
protected  DeadLockException generateDeadLockException(java.lang.String message, java.sql.SQLException e)
          This method generates a DeadLockException from an SQLException.
protected  java.sql.SQLException generateException(java.sql.SQLException e)
          This method enables to generate an SQLException that contains the query of the statement in its message.
protected  java.sql.SQLException generateException(java.lang.String message, java.sql.SQLException e)
          This method enables to append a message to the original exception's message.
protected  java.sql.SQLException generateNewException(java.lang.String message, java.sql.BatchUpdateException e)
          This method generates a BatchUpdateException from an SQLException.
protected  java.sql.SQLException generateNewException(java.lang.String message, java.sql.SQLException e)
          This method generates a new SQLException from an SQLException.
protected  java.lang.String getBatchRequestAt(int i)
          This method gives access to the batch query at the given index.
 java.sql.Connection getConnection()
           
 int getFetchDirection()
           
 int getFetchSize()
           
 java.sql.ResultSet getGeneratedKeys()
           
 int getMaxFieldSize()
           
 int getMaxRows()
           
 boolean getMoreResults()
           
 boolean getMoreResults(int current)
           
 int getQueryTimeout()
           
 java.sql.ResultSet getResultSet()
           
 int getResultSetConcurrency()
           
 int getResultSetHoldability()
           
 int getResultSetType()
           
 int getUpdateCount()
           
 java.sql.SQLWarning getWarnings()
           
protected  int manageException(java.sql.SQLException e)
          This method enables to call upon an ExceptionHandler to manage the given exception.
protected  int manageException(java.sql.SQLException e, CremeAction redo)
          This method enables to call upon an ExceptionHandler to manage the given exception.
protected  void setBaseQuery(java.lang.String sql)
          This method enables to set the base query of the statement.
 void setCursorName(java.lang.String name)
           
 void setEscapeProcessing(boolean enable)
           
 void setFetchDirection(int direction)
           
 void setFetchSize(int rows)
           
 void setMaxFieldSize(int max)
           
 void setMaxRows(int i)
           
 void setQueryTimeout(int seconds)
           
protected  void setRealStatement(java.sql.Statement statement)
          This method should be used by subclasses to set the realStatement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN_QUERY

protected static final java.lang.String UNKNOWN_QUERY
The String displayed when no query has been assigned to the Statement yet.

See Also:
Constant Field Values

realStatement

protected java.sql.Statement realStatement
The underlying statement.


batchRequests

protected final java.util.Vector batchRequests
This vector enables to store the queries contained in a batch statement.


baseQuery

protected java.lang.String baseQuery
The initial query assigned to the Statement.

Constructor Detail

WrappedStatement

public WrappedStatement(java.sql.Statement statement)
                 throws java.sql.SQLException
Enables to wrap a Statement.

Parameters:
statement - the statement to wrap.
Throws:
java.sql.SQLException - if the statement is null.
Method Detail

setRealStatement

protected void setRealStatement(java.sql.Statement statement)
                         throws java.sql.SQLException
This method should be used by subclasses to set the realStatement. It also sets the ExceptionHandler and the rollback and lossOfConnection actions.

Parameters:
statement - the statement to wrap.
Throws:
java.sql.SQLException - if the statement is null.

setBaseQuery

protected void setBaseQuery(java.lang.String sql)
                     throws java.sql.SQLException
This method enables to set the base query of the statement.

Parameters:
sql - the sql query underlying the statement.
Throws:
java.sql.SQLException - if the query is null.

generateException

protected java.sql.SQLException generateException(java.sql.SQLException e)
This method enables to generate an SQLException that contains the query of the statement in its message.

Parameters:
e - the original exception.
Returns:
an exception which has the query as message.

generateException

protected java.sql.SQLException generateException(java.lang.String message,
                                                  java.sql.SQLException e)
This method enables to append a message to the original exception's message.

Parameters:
message - the message to append.
e - the original exception.
Returns:
an exception with the appended message.

generateDeadLockException

protected DeadLockException generateDeadLockException(java.lang.String message,
                                                      java.sql.SQLException e)
This method generates a DeadLockException from an SQLException.

Parameters:
message - the message to append.
e - the original exception.
Returns:
a DeadLockException with the given message.

generateConnectionLostException

protected ConnectionLostException generateConnectionLostException(java.lang.String message,
                                                                  java.sql.SQLException e)
This method generates a ConnectionLostException from an SQLException.

Parameters:
message - the message to append.
e - the original exception.
Returns:
a ConnectionLostException with the given message.

generateNewException

protected java.sql.SQLException generateNewException(java.lang.String message,
                                                     java.sql.SQLException e)
This method generates a new SQLException from an SQLException.

Parameters:
message - the message to append.
e - the original exception.
Returns:
a new SQLException with the given message.

generateNewException

protected java.sql.SQLException generateNewException(java.lang.String message,
                                                     java.sql.BatchUpdateException e)
This method generates a BatchUpdateException from an SQLException.

Parameters:
message - the message to append.
e - the original exception.
Returns:
a BatchUpdateException with the given message.

manageException

protected int manageException(java.sql.SQLException e)
This method enables to call upon an ExceptionHandler to manage the given exception. Both rollbacks and loss of connections are handled through this method.

Parameters:
e - exception to handle.
Returns:
the type of the exception as defined in the SQLExceptionHandler interface.

manageException

protected int manageException(java.sql.SQLException e,
                              CremeAction redo)
This method enables to call upon an ExceptionHandler to manage the given exception. Both rollbacks and loss of connections are handled through this method. This method also enables to redo the action that caused the original exception.

Parameters:
e - exception to handle.
redo - the action that caused the original exception.
Returns:
the type of the exception as defined in the SQLExceptionHandler interface.

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sql)
                                throws java.sql.SQLException
Specified by:
executeQuery in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.executeQuery(java.lang.String)

executeUpdate

public int executeUpdate(java.lang.String sql)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.executeUpdate(java.lang.String)

close

public void close()
           throws java.sql.SQLException
Specified by:
close in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.close()

getMaxFieldSize

public int getMaxFieldSize()
                    throws java.sql.SQLException
Specified by:
getMaxFieldSize in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getMaxFieldSize()

setMaxFieldSize

public void setMaxFieldSize(int max)
                     throws java.sql.SQLException
Specified by:
setMaxFieldSize in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.setMaxFieldSize(int)

getMaxRows

public int getMaxRows()
               throws java.sql.SQLException
Specified by:
getMaxRows in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getMaxRows()

setMaxRows

public void setMaxRows(int i)
                throws java.sql.SQLException
Specified by:
setMaxRows in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.setMaxRows(int)

setEscapeProcessing

public void setEscapeProcessing(boolean enable)
                         throws java.sql.SQLException
Specified by:
setEscapeProcessing in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.setEscapeProcessing(boolean)

getQueryTimeout

public int getQueryTimeout()
                    throws java.sql.SQLException
Specified by:
getQueryTimeout in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getQueryTimeout()

setQueryTimeout

public void setQueryTimeout(int seconds)
                     throws java.sql.SQLException
Specified by:
setQueryTimeout in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.setQueryTimeout(int)

cancel

public void cancel()
            throws java.sql.SQLException
Specified by:
cancel in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.cancel()

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Specified by:
getWarnings in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getWarnings()

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Specified by:
clearWarnings in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.clearWarnings()

setCursorName

public void setCursorName(java.lang.String name)
                   throws java.sql.SQLException
Specified by:
setCursorName in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.setCursorName(java.lang.String)

execute

public boolean execute(java.lang.String sql)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.execute(java.lang.String)

getResultSet

public java.sql.ResultSet getResultSet()
                                throws java.sql.SQLException
Specified by:
getResultSet in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getResultSet()

getUpdateCount

public int getUpdateCount()
                   throws java.sql.SQLException
Specified by:
getUpdateCount in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getUpdateCount()

getMoreResults

public boolean getMoreResults()
                       throws java.sql.SQLException
Specified by:
getMoreResults in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getMoreResults()

setFetchDirection

public void setFetchDirection(int direction)
                       throws java.sql.SQLException
Specified by:
setFetchDirection in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.setFetchDirection(int)

getFetchDirection

public int getFetchDirection()
                      throws java.sql.SQLException
Specified by:
getFetchDirection in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getFetchDirection()

setFetchSize

public void setFetchSize(int rows)
                  throws java.sql.SQLException
Specified by:
setFetchSize in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.setFetchSize(int)

getFetchSize

public int getFetchSize()
                 throws java.sql.SQLException
Specified by:
getFetchSize in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getFetchSize()

getResultSetConcurrency

public int getResultSetConcurrency()
                            throws java.sql.SQLException
Specified by:
getResultSetConcurrency in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getResultSetConcurrency()

getResultSetType

public int getResultSetType()
                     throws java.sql.SQLException
Specified by:
getResultSetType in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getResultSetType()

addBatch

public void addBatch(java.lang.String sql)
              throws java.sql.SQLException
Specified by:
addBatch in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.addBatch(java.lang.String)

clearBatch

public void clearBatch()
                throws java.sql.SQLException
Specified by:
clearBatch in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.clearBatch()

executeBatch

public int[] executeBatch()
                   throws java.sql.SQLException
Specified by:
executeBatch in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.executeBatch()

getBatchRequestAt

protected java.lang.String getBatchRequestAt(int i)
This method gives access to the batch query at the given index. It should be used for trace purpose.

Parameters:
i - the index of the batch query to find.
Returns:
the batch query at index.

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Specified by:
getConnection in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getConnection()

getMoreResults

public boolean getMoreResults(int current)
                       throws java.sql.SQLException
Specified by:
getMoreResults in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getMoreResults(int)

getGeneratedKeys

public java.sql.ResultSet getGeneratedKeys()
                                    throws java.sql.SQLException
Specified by:
getGeneratedKeys in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getGeneratedKeys()

executeUpdate

public int executeUpdate(java.lang.String sql,
                         int autoGeneratedKeys)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.executeUpdate(java.lang.String, int)

executeUpdate

public int executeUpdate(java.lang.String sql,
                         int[] columnIndexes)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.executeUpdate(java.lang.String, int[])

executeUpdate

public int executeUpdate(java.lang.String sql,
                         java.lang.String[] columnNames)
                  throws java.sql.SQLException
Specified by:
executeUpdate in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.executeUpdate(java.lang.String, java.lang.String[])

execute

public boolean execute(java.lang.String sql,
                       int autoGeneratedKeys)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.execute(java.lang.String, int)

execute

public boolean execute(java.lang.String sql,
                       int[] columnIndexes)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.execute(java.lang.String, int[])

execute

public boolean execute(java.lang.String sql,
                       java.lang.String[] columnNames)
                throws java.sql.SQLException
Specified by:
execute in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.execute(java.lang.String, java.lang.String[])

getResultSetHoldability

public int getResultSetHoldability()
                            throws java.sql.SQLException
Specified by:
getResultSetHoldability in interface java.sql.Statement
Throws:
java.sql.SQLException
See Also:
Statement.getResultSetHoldability()


Copyright 2006 null. All Rights Reserved.