public class QueryWrapper extends StatementWrapper
StatementWrapper provides, it provides:
final Database db = ...;
final Schema schema = ...;
final String query = ...;
final QueryWrapper wrap = new QueryWrapper( db, query, new Object[]{ schema });
final QueryWrapper.QueryRunnable r =
new QueryWrapper.QueryRunnable()
{
public void processResultSet( ResultSet rs )
throws SQLException, DBException
{
while( rs.next() )
{
// process the result set as appropriate
}
}
};
try
{
wrap.executeQuery( r );
}
catch( DBException dbe )
{
// process exception
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
QueryWrapper.QueryRunnable
A QueryRunnable implementation is passed to the QueryWrapper on execute of
the query to process the resulting ResultSet.
|
StatementWrapper.ExecutionProxy, StatementWrapper.ExecutionRunnable<T>, StatementWrapper.Listener| Constructor and Description |
|---|
QueryWrapper(Database db,
java.lang.String query)
Creates a wrapper for a query with no parameters.
|
QueryWrapper(Database db,
java.lang.String query,
java.util.List params)
Creates a wrapper for the given query text.
|
QueryWrapper(Database db,
java.lang.String query,
java.lang.Object... params)
Creates a wrapper for the given query text.
|
QueryWrapper(java.lang.String name,
java.sql.Connection conn,
java.lang.String query,
java.lang.Object... params)
Only use in the absence of a Database (e.g.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the statement and result set if we got that far.
|
protected java.sql.Statement |
createStatment()
Creates the Statement object to use.
|
boolean |
execute()
Executes the statment against the database.
|
void |
executeQuery(int fetchSize,
QueryWrapper.QueryRunnable run)
Execute the query against the builder's connection using the appropriate
parameter substitutions.
|
void |
executeQuery(QueryWrapper.QueryRunnable run)
Execute the query against the builder's connection using the appropriate
parameter substitutions.
|
java.lang.String |
executeSingleCellQuery()
Convenience method that executes the query and expects a single row
with a single column.
|
java.lang.String |
getDatabaseName() |
protected java.util.List<java.lang.Object> |
getParameters()
Returns the parameters to substitute on the statement.
|
protected java.lang.String |
getQuery()
Returns the query string.
|
java.lang.String |
getStatementTextForLog()
For logging and exception handling.
|
void |
setContextObject(DBObject obj)
Sets a context DBObject that the statement is being executed for.
|
void |
setDatabaseName(java.lang.String dbName) |
static QueryWrapper |
union(QueryWrapper... wrappers)
Unions together the queries in the given wrapper and bundles up all the
parameters (if any) to be used with the various queries.
|
addListener, cancel, cancelExecution, createDBSQLException, createDBSQLException, doExecute, executeImpl, getConnection, getConnectionName, getDatabase, getExecutionProxy, getIdentifier, getLogger, getStatement, getStatementStrings, hasCancelled, isCancelled, isExecutionProxyThread, isIgnoreErrors, queryFinished, queryStarted, removeListener, setBypassExecutionProxy, setDatabase, setExecuting, setExecutionProxy, setIdentifier, setIgnoreErrors, setStatement, sqlTrace, throwCancelledException, throwDBException, throwDBException, throwDBExceptionpublic QueryWrapper(Database db, java.lang.String query)
#QueryWrapper(java.sql.Connection, java.lang.String, java.lang.Object...)public QueryWrapper(Database db, java.lang.String query, java.lang.Object... params)
public QueryWrapper(java.lang.String name,
java.sql.Connection conn,
java.lang.String query,
java.lang.Object... params)
public QueryWrapper(Database db, java.lang.String query, java.util.List params)
public void setContextObject(DBObject obj)
If the object has a DBObjectID with a databaseName set this will also set the databaseName on this wrapper.
setContextObject in class StatementWrapperobj - the context object for this wrapperpublic final void setDatabaseName(java.lang.String dbName)
public final java.lang.String getDatabaseName()
protected java.sql.Statement createStatment()
throws java.sql.SQLException
StatementWrappercreateStatment in class StatementWrapperjava.sql.SQLExceptionpublic java.lang.String getStatementTextForLog()
StatementWrappergetStatementTextForLog in class StatementWrapperprotected java.lang.String getQuery()
setMessageFormat()protected java.util.List<java.lang.Object> getParameters()
getQuery()public final boolean execute()
throws DBException
StatementWrapperexecute in class StatementWrapperDBExceptionStatement.execute(java.lang.String)public java.lang.String executeSingleCellQuery()
throws DBException
DBExceptionpublic void executeQuery(int fetchSize,
QueryWrapper.QueryRunnable run)
throws DBException
fetchSize - Gives the JDBC driver a hint as to the number of rows that
should be fetched from the database when more rows are needed.
If the value specified is zero, then the hint is ignored.DBExceptionpublic void executeQuery(QueryWrapper.QueryRunnable run) throws DBException
DBExceptionpublic void close()
finally{ ... } block.close in class StatementWrapperpublic static QueryWrapper union(QueryWrapper... wrappers)
No checking is done on the number of columns - the database will complain if they don't match.