|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.boylesoftware.cb2.util.sql.StatementWrapper
Wrapper around a JDBC's Statement
interface
implementation. You can derive your statement wrapper classes from
this one and override some of its methods, while all the others
will be calling appropriate methods on the wrapped, "real" statement.
This class also provides some "hook" methods called in certain situations. Note that if your redefine interface methods in your subclass and you use hooks you will have to call the base method from your redefined one in order to make the hooks invoked. Alternatively you call them yourself directly from the redefined interface method.
Field Summary | |
protected java.sql.Connection |
con
Connection, which will be returned by the getConnection
method. |
static int |
EXECUTE_TYPE_BATCH
Indicates executeBatch call. |
static int |
EXECUTE_TYPE_GENERIC
Indicates generic execute call. |
static int |
EXECUTE_TYPE_QUERY
Indicates executeQuery call. |
static int |
EXECUTE_TYPE_UPDATE
Indicates executeUpdate call. |
protected java.sql.Statement |
stmt
The wrapped 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 | |
StatementWrapper()
Creates a new wrapper. |
|
StatementWrapper(java.sql.Connection con,
java.sql.Statement stmt)
Creates a new wrapper and sets the wrapped statement to the specified one. |
Method Summary | |
void |
addBatch(java.lang.String sql)
Interface method wrapper. |
void |
cancel()
Interface method wrapper. |
void |
clearBatch()
Interface method wrapper. |
void |
clearWarnings()
Interface method wrapper. |
void |
close()
Interface method wrapper. |
boolean |
execute(java.lang.String sql)
Interface method wrapper. |
boolean |
execute(java.lang.String sql,
int autoGeneratedKeys)
Interface method wrapper. |
boolean |
execute(java.lang.String sql,
int[] columnIndexes)
Interface method wrapper. |
boolean |
execute(java.lang.String sql,
java.lang.String[] columnNames)
Interface method wrapper. |
int[] |
executeBatch()
Interface method wrapper. |
java.sql.ResultSet |
executeQuery(java.lang.String sql)
Interface method wrapper. |
int |
executeUpdate(java.lang.String sql)
Interface method wrapper. |
int |
executeUpdate(java.lang.String sql,
int autoGeneratedKeys)
Interface method wrapper. |
int |
executeUpdate(java.lang.String sql,
int[] columnIndexes)
Interface method wrapper. |
int |
executeUpdate(java.lang.String sql,
java.lang.String[] columnNames)
Interface method wrapper. |
java.sql.Connection |
getConnection()
Interface method wrapper. |
int |
getFetchDirection()
Interface method wrapper. |
int |
getFetchSize()
Interface method wrapper. |
java.sql.ResultSet |
getGeneratedKeys()
Interface method wrapper. |
int |
getMaxFieldSize()
Interface method wrapper. |
int |
getMaxRows()
Interface method wrapper. |
boolean |
getMoreResults()
Interface method wrapper. |
boolean |
getMoreResults(int current)
Interface method wrapper. |
int |
getQueryTimeout()
Interface method wrapper. |
java.sql.ResultSet |
getResultSet()
Interface method wrapper. |
int |
getResultSetConcurrency()
Interface method wrapper. |
int |
getResultSetHoldability()
Interface method wrapper. |
int |
getResultSetType()
Interface method wrapper. |
int |
getUpdateCount()
Interface method wrapper. |
java.sql.SQLWarning |
getWarnings()
Interface method wrapper. |
java.sql.Statement |
getWrappedStatement()
Returns the wrapped statement. |
protected void |
postCallHook()
This hook is invoked after every interface method call. |
protected void |
postexecuteHook(java.sql.ResultSet rs,
int cnt,
boolean isResultSet)
This hook method is called from all the methods that cause the statement execution after the actuall method on the underlying statement returns. |
protected java.lang.String |
preexecuteHook(int executeType,
java.lang.String sql)
This hook method is called from all the methods that cause the statement execution before the control is actually passed down to the underlying statement. |
void |
setConnection(java.sql.Connection con)
Sets the connection, which will be returned by the getConnection method. |
void |
setCursorName(java.lang.String name)
Interface method wrapper. |
void |
setEscapeProcessing(boolean enable)
Interface method wrapper. |
void |
setFetchDirection(int direction)
Interface method wrapper. |
void |
setFetchSize(int rows)
Interface method wrapper. |
void |
setMaxFieldSize(int max)
Interface method wrapper. |
void |
setMaxRows(int max)
Interface method wrapper. |
void |
setQueryTimeout(int seconds)
Interface method wrapper. |
void |
setWrappedStatement(java.sql.Statement stmt)
Sets the wrapped statement. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int EXECUTE_TYPE_QUERY
executeQuery
call.
public static final int EXECUTE_TYPE_UPDATE
executeUpdate
call.
public static final int EXECUTE_TYPE_GENERIC
execute
call.
public static final int EXECUTE_TYPE_BATCH
executeBatch
call.
protected java.sql.Connection con
getConnection
method. If not set, then getConnection
on the
wrapped statement will be used.
protected java.sql.Statement stmt
Constructor Detail |
public StatementWrapper()
setWrappedStatement
call before using the
instance.
public StatementWrapper(java.sql.Connection con, java.sql.Statement stmt)
con
- connection, which will be returned by the
getConnection
method. If null
,
then getConnection
on the wrapped statement
will be used.stmt
- the statement to be wrapped.Method Detail |
public void setConnection(java.sql.Connection con)
getConnection
method. If null
,
then getConnection
on the wrapped statement
will be used.
con
- the connection to set.public void setWrappedStatement(java.sql.Statement stmt)
stmt
- statement to wrap.public java.sql.Statement getWrappedStatement()
public java.sql.ResultSet executeQuery(java.lang.String sql) throws java.sql.SQLException
Also calles preexecuteHook
and
postexecuteHook
hooks.
executeQuery
in interface java.sql.Statement
java.sql.SQLException
public int executeUpdate(java.lang.String sql) throws java.sql.SQLException
Also calles preexecuteHook
and
postexecuteHook
hooks.
executeUpdate
in interface java.sql.Statement
java.sql.SQLException
public void close() throws java.sql.SQLException
close
in interface java.sql.Statement
java.sql.SQLException
public int getMaxFieldSize() throws java.sql.SQLException
getMaxFieldSize
in interface java.sql.Statement
java.sql.SQLException
public void setMaxFieldSize(int max) throws java.sql.SQLException
setMaxFieldSize
in interface java.sql.Statement
java.sql.SQLException
public int getMaxRows() throws java.sql.SQLException
getMaxRows
in interface java.sql.Statement
java.sql.SQLException
public void setMaxRows(int max) throws java.sql.SQLException
setMaxRows
in interface java.sql.Statement
java.sql.SQLException
public void setEscapeProcessing(boolean enable) throws java.sql.SQLException
setEscapeProcessing
in interface java.sql.Statement
java.sql.SQLException
public int getQueryTimeout() throws java.sql.SQLException
getQueryTimeout
in interface java.sql.Statement
java.sql.SQLException
public void setQueryTimeout(int seconds) throws java.sql.SQLException
setQueryTimeout
in interface java.sql.Statement
java.sql.SQLException
public void cancel() throws java.sql.SQLException
cancel
in interface java.sql.Statement
java.sql.SQLException
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException
getWarnings
in interface java.sql.Statement
java.sql.SQLException
public void clearWarnings() throws java.sql.SQLException
clearWarnings
in interface java.sql.Statement
java.sql.SQLException
public void setCursorName(java.lang.String name) throws java.sql.SQLException
setCursorName
in interface java.sql.Statement
java.sql.SQLException
public boolean execute(java.lang.String sql) throws java.sql.SQLException
Also calles preexecuteHook
and
postexecuteHook
hooks.
execute
in interface java.sql.Statement
java.sql.SQLException
public java.sql.ResultSet getResultSet() throws java.sql.SQLException
getResultSet
in interface java.sql.Statement
java.sql.SQLException
public int getUpdateCount() throws java.sql.SQLException
getUpdateCount
in interface java.sql.Statement
java.sql.SQLException
public boolean getMoreResults() throws java.sql.SQLException
getMoreResults
in interface java.sql.Statement
java.sql.SQLException
public void setFetchDirection(int direction) throws java.sql.SQLException
setFetchDirection
in interface java.sql.Statement
java.sql.SQLException
public int getFetchDirection() throws java.sql.SQLException
getFetchDirection
in interface java.sql.Statement
java.sql.SQLException
public void setFetchSize(int rows) throws java.sql.SQLException
setFetchSize
in interface java.sql.Statement
java.sql.SQLException
public int getFetchSize() throws java.sql.SQLException
getFetchSize
in interface java.sql.Statement
java.sql.SQLException
public int getResultSetConcurrency() throws java.sql.SQLException
getResultSetConcurrency
in interface java.sql.Statement
java.sql.SQLException
public int getResultSetType() throws java.sql.SQLException
getResultSetType
in interface java.sql.Statement
java.sql.SQLException
public void addBatch(java.lang.String sql) throws java.sql.SQLException
addBatch
in interface java.sql.Statement
java.sql.SQLException
public void clearBatch() throws java.sql.SQLException
clearBatch
in interface java.sql.Statement
java.sql.SQLException
public int[] executeBatch() throws java.sql.SQLException
Also calles preexecuteHook
and
postexecuteHook
hooks.
executeBatch
in interface java.sql.Statement
java.sql.SQLException
public java.sql.Connection getConnection() throws java.sql.SQLException
getConnection
in interface java.sql.Statement
java.sql.SQLException
public boolean getMoreResults(int current) throws java.sql.SQLException
getMoreResults
in interface java.sql.Statement
java.sql.SQLException
public java.sql.ResultSet getGeneratedKeys() throws java.sql.SQLException
getGeneratedKeys
in interface java.sql.Statement
java.sql.SQLException
public int executeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
Also calles preexecuteHook
and
postexecuteHook
hooks.
executeUpdate
in interface java.sql.Statement
java.sql.SQLException
public int executeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
Also calles preexecuteHook
and
postexecuteHook
hooks.
executeUpdate
in interface java.sql.Statement
java.sql.SQLException
public int executeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
Also calles preexecuteHook
and
postexecuteHook
hooks.
executeUpdate
in interface java.sql.Statement
java.sql.SQLException
public boolean execute(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLException
Also calles preexecuteHook
and
postexecuteHook
hooks.
execute
in interface java.sql.Statement
java.sql.SQLException
public boolean execute(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLException
Also calles preexecuteHook
and
postexecuteHook
hooks.
execute
in interface java.sql.Statement
java.sql.SQLException
public boolean execute(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLException
Also calles preexecuteHook
and
postexecuteHook
hooks.
execute
in interface java.sql.Statement
java.sql.SQLException
public int getResultSetHoldability() throws java.sql.SQLException
getResultSetHoldability
in interface java.sql.Statement
java.sql.SQLException
protected void postCallHook() throws java.sql.SQLException
java.sql.SQLException
- to indicate an error in the method.protected java.lang.String preexecuteHook(int executeType, java.lang.String sql) throws java.sql.SQLException
sql
parameter back, but you can override this method
in a subclass.
executeType
- one of EXECUTE_TYPE_xxx
constants
indicating the type of the call.sql
- SQL text passed to the execute method by the caller, or
null
if not applicable (for example it is a prepared
statement)
java.sql.SQLException
- if an error happened.protected void postexecuteHook(java.sql.ResultSet rs, int cnt, boolean isResultSet) throws java.sql.SQLException
Note that this hook is not called if there was an exception in the underlying statement.
rs
- result set returned by the underlying statement or
null
if not applicable.cnt
- update count returned by the underlying statement or
-1
if not applicable.isResultSet
- true
if the first result is a
ResultSet
object, false
if it is an update
count or there are no results.
java.sql.SQLException
- if an error happened.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |