|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.tentackle.db.StatementWrapper
public class StatementWrapper
A wrapper for sql statements.
Will catch and report SQLExceptions and
keep track of being used only once after Db.createStatement().
| Field Summary | |
|---|---|
protected ManagedConnection |
con
the managed connection |
protected boolean |
ready
flag if statement is marked ready for being consumed |
protected Statement |
stmt
the sql statement |
| Constructor Summary | |
|---|---|
StatementWrapper(ManagedConnection con,
Statement stmt)
Creates a wrapper for an sql statement. |
|
| Method Summary | |
|---|---|
void |
close()
Closes this statement. |
protected void |
detachDb()
Detach the db from the connection. |
ResultSetWrapper |
executeQuery(String sql)
Executes a query. |
ResultSetWrapper |
executeQuery(String sql,
boolean withinTx)
Executes a query. |
int |
executeUpdate(String sql)
Executes the given SQL statement. |
ManagedConnection |
getConnection()
Gets the connection. |
Db |
getDb()
Gets the currently attached Db. |
int |
getFetchDirection()
Retrieves the direction for fetching rows from database tables that is the default for result sets generated from this Statement object. |
int |
getFetchSize()
Retrieves the number of result set rows that is the default fetch size for ResultSet objects
generated from this Statement object. |
int |
getMaxRows()
Retrieves the maximum number of rows that a ResultSet object produced by this
Statement object can contain. |
Statement |
getStatement()
Gets the wrapped statement. |
boolean |
isClosed()
Determines whether this statement is closed. |
boolean |
isMarkedReady()
Returns whether this statement is marked ready. Used to determine unused pending statements in servers when closing dead sessions. |
void |
markReady()
Marks the statement to be ready for being consumed by a Db attached
to a ConnectionManager.This is an additional measure to enforce the programming rule that a statement is being used only once after Db.createStatement()
(for non-prepared statements) or after Db.getPreparedStatement(int)
for prepared statements. |
void |
setFetchDirection(int direction)
Gives the driver a hint as to the direction in which rows will be processed in ResultSet
objects created using this Statement object. |
void |
setFetchSize(int rows)
Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for ResultSet objects genrated by this Statement. |
void |
setMaxRows(int max)
Sets the limit for the maximum number of rows that any ResultSet object generated by this Statement
object can contain to the given number. |
String |
toString()
Returns the text representation of the wrapped statement. |
void |
unmarkReady()
Unmarks (consumes) this statement previously marked ready. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected ManagedConnection con
protected Statement stmt
protected boolean ready
| Constructor Detail |
|---|
public StatementWrapper(ManagedConnection con,
Statement stmt)
con - the connectionstmt - the sql statement| Method Detail |
|---|
public ManagedConnection getConnection()
public Statement getStatement()
public Db getDb()
public void markReady()
Db attached
to a ConnectionManager.Db.createStatement()
(for non-prepared statements) or after Db.getPreparedStatement(int)
for prepared statements.
Notice: if a statement may be marked ready more than once, i.e. an open result
exists (which would be closed according to the JDBC specs), a DbRuntimeException is thrown.
The specs in Statement say:
By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.Without this additional measure a "ResultSet closed" exception will be thrown by the JDBC-driver on the next usage of the first resultset and you wouldn't have any clue which resultset forced the closing.
public void unmarkReady()
public boolean isMarkedReady()
public String toString()
toString in class Objectprotected void detachDb()
public int executeUpdate(String sql)
sql - an sql-statement
public ResultSetWrapper executeQuery(String sql,
boolean withinTx)
sql - is the query sql stringwithinTx - is true if start a transaction for this query.
public ResultSetWrapper executeQuery(String sql)
sql - is the query sql string
public void close()
public boolean isClosed()
public void setFetchSize(int rows)
ResultSet objects genrated by this Statement.
If the value specified is zero, then the hint is ignored.
The default value is zero.
rows - the number of rows to fetchgetFetchSize()public int getFetchSize()
ResultSet objects
generated from this Statement object.
If this Statement object has not set
a fetch size by calling the method setFetchSize,
the return value is implementation-specific.
Statement objectsetFetchSize(int)public void setMaxRows(int max)
ResultSet object generated by this Statement
object can contain to the given number.
If the limit is exceeded, the excess
rows are silently dropped.
max - the new max rows limit; zero means there is no limitgetMaxRows()public int getMaxRows()
ResultSet object produced by this
Statement object can contain. If this limit is exceeded,
the excess rows are silently dropped.
ResultSet
object produced by this Statement object;
zero means there is no limitsetMaxRows(int)public void setFetchDirection(int direction)
ResultSet
objects created using this Statement object. The
default value is ResultSet.FETCH_FORWARD.
Note that this method sets the default fetch direction for
result sets generated by this Statement object.
Each result set has its own methods for getting and setting
its own fetch direction.
direction - the initial direction for processing rowsgetFetchDirection()public int getFetchDirection()
Statement object.
If this Statement object has not set
a fetch direction by calling the method setFetchDirection,
the return value is implementation-specific.
Statement objectsetFetchDirection(int)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||