|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.uwyn.rife.database.DbQueryManager
public class DbQueryManager
This is a convenience class to make it easy to control the queries that
handle the retrieval, storage, update and removal of data in a database.
All queries will be executed in a connection of the Datasource
that's provided to the constructor of the DbQueryManager.
A collection of convenience methods have been provided to quickly
execute queries in a variety of manners without having to worry about the
logic behind it or having to remember to close the queries at the
appropriate moment. These methods optionally interact with the
DbPreparedStatementHandler and DbResultSetHandler
classes to make it possible to fully customize the executed queries. The
following categories of worry-free methods exist:
Lower-level methods are also available for the sake of repetitive
code-reduction. To obtain execute regular statements directly,
use the executeQuery method.
Finally, since DbStatement and
DbPreparedStatement instances preserve a reference to their
resultset, it's easy to iterate over the rows of a resultset with the
fetch or fetchAll methods.
DbPreparedStatement,
DbStatement,
DbRowProcessor,
DbPreparedStatementHandler,
DbResultSetHandler,
DbConnectionUser| Constructor Summary | |
|---|---|
DbQueryManager(Datasource datasource)
Instantiates a new DbQueryManager object and ties it to
the provided datasource. |
|
| Method Summary | ||
|---|---|---|
Object |
clone()
Simply clones the instance with the default clone method. |
|
boolean |
executeFetchAll(ReadQuery query,
DbRowProcessor rowProcessor)
Safely and quickly fetches all the rows from the results of a select query. |
|
boolean |
executeFetchAll(ReadQuery query,
DbRowProcessor rowProcessor,
DbPreparedStatementHandler handler)
Safely fetches all the rows from the results of a customizable select query. |
|
|
executeFetchAllBeans(ReadQuery query,
Class<BeanType> beanClass)
Safely and quickly fetches the all the bean instances from the results of a select query. |
|
|
executeFetchAllBeans(ReadQuery query,
Class<BeanType> beanClass,
DbPreparedStatementHandler handler)
Safely fetches the all the bean instances from the results of a customizable select query. |
|
boolean |
executeFetchFirst(ReadQuery query,
DbRowProcessor rowProcessor)
Safely and quickly fetches the first row from the results of a select query. |
|
boolean |
executeFetchFirst(ReadQuery query,
DbRowProcessor rowProcessor,
DbPreparedStatementHandler handler)
Safely fetches the first row from the results of a customizable select query. |
|
|
executeFetchFirstBean(ReadQuery query,
Class<BeanType> beanClass)
Safely and quickly fetches the first bean instance from the results of a select query. |
|
|
executeFetchFirstBean(ReadQuery query,
Class<BeanType> beanClass,
DbPreparedStatementHandler handler)
Safely fetches the first bean instance from the results of a customizable select query. |
|
boolean |
executeGetFirstBoolean(ReadQuery query)
Safely and quickly retrieves the first cell as a boolean
from the results of a select query. |
|
boolean |
executeGetFirstBoolean(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a boolean from the
results of a customizable select query. |
|
byte |
executeGetFirstByte(ReadQuery query)
Safely and quickly retrieves the first cell as a byte from
the results of a select query. |
|
byte |
executeGetFirstByte(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a byte from the results
of a customizable select query. |
|
byte[] |
executeGetFirstBytes(ReadQuery query)
Safely and quickly retrieves the first cell as a byte
array from the results of a select query. |
|
byte[] |
executeGetFirstBytes(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a byte array from the
results of a customizable select query. |
|
Date |
executeGetFirstDate(ReadQuery query)
Safely and quickly retrieves the first cell as a sql Date
from the results of a select query. |
|
Date |
executeGetFirstDate(ReadQuery query,
Calendar cal)
Safely and quickly retrieves the first cell as a sql Date
from the results of a select query. |
|
Date |
executeGetFirstDate(ReadQuery query,
Calendar cal,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a sql Date from the
results of a customizable select query. |
|
Date |
executeGetFirstDate(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a sql Date from the
results of a customizable select query. |
|
double |
executeGetFirstDouble(ReadQuery query)
Safely and quickly retrieves the first cell as a double
from the results of a select query. |
|
double |
executeGetFirstDouble(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a double from the
results of a customizable select query. |
|
float |
executeGetFirstFloat(ReadQuery query)
Safely and quickly retrieves the first cell as a float
from the results of a select query. |
|
float |
executeGetFirstFloat(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a float from the
results of a customizable select query. |
|
int |
executeGetFirstInt(ReadQuery query)
Safely and quickly retrieves the first cell as a int from
the results of a select query. |
|
int |
executeGetFirstInt(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a int from the results
of a customizable select query. |
|
long |
executeGetFirstLong(ReadQuery query)
Safely and quickly retrieves the first cell as a long from
the results of a select query. |
|
long |
executeGetFirstLong(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a long from the results
of a customizable select query. |
|
short |
executeGetFirstShort(ReadQuery query)
Safely and quickly retrieves the first cell as a short
from the results of a select query. |
|
short |
executeGetFirstShort(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a short from the
results of a customizable select query. |
|
String |
executeGetFirstString(ReadQuery query)
Safely and quickly retrieves the first cell as a String
from the results of a select query. |
|
String |
executeGetFirstString(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a String from the
results of a customizable select query. |
|
Time |
executeGetFirstTime(ReadQuery query)
Safely and quickly retrieves the first cell as a sql Time
from the results of a select query. |
|
Time |
executeGetFirstTime(ReadQuery query,
Calendar cal)
Safely and quickly retrieves the first cell as a sql Time
from the results of a select query. |
|
Time |
executeGetFirstTime(ReadQuery query,
Calendar cal,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a sql Time from the
results of a customizable select query. |
|
Time |
executeGetFirstTime(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a sql Time from the
results of a customizable select query. |
|
Timestamp |
executeGetFirstTimestamp(ReadQuery query)
Safely and quickly retrieves the first cell as a sql Timestamp from the results of a select query. |
|
Timestamp |
executeGetFirstTimestamp(ReadQuery query,
Calendar cal)
Safely and quickly retrieves the first cell as a sql Timestamp from the results of a select query. |
|
Timestamp |
executeGetFirstTimestamp(ReadQuery query,
Calendar cal,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a sql Timestamp from
the results of a customizable select query. |
|
Timestamp |
executeGetFirstTimestamp(ReadQuery query,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as a sql Timestamp from
the results of a customizable select query. |
|
boolean |
executeHasResultRows(ReadQuery query)
Safely and quickly verifies if a select query returns any rows. |
|
boolean |
executeHasResultRows(ReadQuery query,
DbPreparedStatementHandler handler)
Safely verifies if a customizable select query returns any rows. |
|
DbStatement |
executeQuery(ReadQuery query)
Executes a query statement in a connection of this DbQueryManager's Datasource. |
|
|
executeQuery(ReadQuery query,
DbPreparedStatementHandler handler)
Executes a customizable select statement. |
|
|
executeQuery(ReadQuery query,
DbResultSetHandler handler)
Executes a select statement and handle the results in a custom fashion. |
|
int |
executeUpdate(Query query)
Safely and quickly executes an update statement. |
|
int |
executeUpdate(Query query,
DbPreparedStatementHandler handler)
Safely execute an updates statement. |
|
int |
executeUpdate(String sql)
Safely and quickly executes an update statement. |
|
|
executeUseFirstAsciiStream(ReadQuery query,
InputStreamUser user)
Safely and quickly retrieves the first cell as an ASCII InputStream from the results of a select query. |
|
|
executeUseFirstAsciiStream(ReadQuery query,
InputStreamUser user,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as an ASCII InputStream
from the results of a customizable select query. |
|
|
executeUseFirstBinaryStream(ReadQuery query,
InputStreamUser user)
Safely and quickly retrieves the first cell as an binary InputStream from the results of a select query. |
|
|
executeUseFirstBinaryStream(ReadQuery query,
InputStreamUser user,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as an binary InputStream
from the results of a customizable select query. |
|
|
executeUseFirstCharacterStream(ReadQuery query,
ReaderUser user)
Safely and quickly retrieves the first cell as an character Reader from the results of a select query. |
|
|
executeUseFirstCharacterStream(ReadQuery query,
ReaderUser user,
DbPreparedStatementHandler handler)
Safely retrieves the first cell as an character Reader
from the results of a customizable select query. |
|
boolean |
fetch(ResultSet resultSet)
Fetches the next row of a resultset without processing it in any way. |
|
boolean |
fetch(ResultSet resultSet,
DbRowProcessor rowProcessor)
Fetches the next row of a resultset and processes it through a DbRowProcessor. |
|
boolean |
fetchAll(ResultSet resultSet,
DbRowProcessor rowProcessor)
Fetches all the next rows of a resultset and processes it through a DbRowProcessor. |
|
DbConnection |
getConnection()
Obtains a DbConnection of this DbQueryManager's
Datasource. |
|
Datasource |
getDatasource()
Retrieves the Datasource of this
DbQueryManager. |
|
|
inTransaction(DbTransactionUser user)
Ensures that all the instructions that are executed in the provided DbTransactionUser instance are executed inside a transaction
and committed afterwards. |
|
|
reserveConnection(DbConnectionUser user)
Reserves a database connection for a this particular thread for all the instructions that are executed in the provided DbConnectionUser
instance. |
|
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DbQueryManager(Datasource datasource)
DbQueryManager object and ties it to
the provided datasource.
datasource - the datasource that will be used to obtain database
connections from| Method Detail |
|---|
public int executeUpdate(String sql)
throws DatabaseException
DbStatement.executeUpdate(String) method, but also
automatically closes the statement after its execution.
This method is typically used in situations where one static update query needs to be executed without any parametrization or other processing.
DbQueryManager manager = new DbQueryManager(datasource);
int count = manager.executeUpdate("INSERT INTO person (name) VALUES ('me')");
sql - the sql query that has to be executed
DatabaseException - see DbStatement.executeUpdate(String)DbStatement.executeUpdate(String),
executeUpdate(Query)
public int executeUpdate(Query query)
throws DatabaseException
DbStatement.executeUpdate(Query) method, but also
automatically closes the statement after its execution.
This method is typically used in situations where one static update query needs to be executed without any parametrization or other processing.
DbQueryManager manager = new DbQueryManager(datasource);
Insert insert = new Insert(datasource);
insert.into("person").field("name", "me");
int count = manager.executeUpdate(insert);
query - the query builder instance that needs to be executed
DatabaseException - see DbStatement.executeUpdate(Query)DbStatement.executeUpdate(Query),
executeUpdate(String)
public int executeUpdate(Query query,
DbPreparedStatementHandler handler)
throws DatabaseException
DbPreparedStatement.executeUpdate() method, but also automatically
closes the statement after its execution and allows customization of
the prepared statement through an optional instance of DbPreparedStatementHandler.
This method is typically used when you need to fully customize a query at runtime, but still want to benefit of a safety net that ensures that the allocated statement will be closed.
DbQueryManager manager = new DbQueryManager(datasource);
Insert insert = new Insert(datasource);
insert.into("person").fieldParameter("name");
final String name = "me";
int count = manager.executeUpdate(insert, new DbPreparedStatementHandler() {
public void setParameters(DbPreparedStatement statement)
{
statement
.setString("name", name);
}
});
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
DatabaseException - see DbPreparedStatement.executeUpdate()DbPreparedStatement.executeUpdate(),
DbPreparedStatementHandler
public boolean executeHasResultRows(ReadQuery query)
throws DatabaseException
DbResultSet.hasResultRows() method, but
also automatically closes the statement after its execution.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.from("person");
boolean result = manager.executeHasResultRows(select);
query - the query builder instance that needs to be executed
true when rows were returned by the query; or
false otherwise
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.hasResultRows()DbPreparedStatement.executeQuery(),
DbResultSet.hasResultRows(),
DbPreparedStatementHandler
public boolean executeHasResultRows(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
DbResultSet.hasResultRows() method, but
also automatically closes the statement after its execution and allows
customization of the prepared statement through an optional instance of
DbPreparedStatementHandler.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.from("person").whereParameter("name", "=");
final String name = "you";
boolean result = manager.executeHasResultRows(select, new DbPreparedStatementHandler() {
public void setParameters(DbPreparedStatement statement)
{
statement
.setString("name", name);
}
});
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
true when rows were returned by the query; or
false otherwise
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.hasResultRows()DbPreparedStatement.executeQuery(),
DbResultSet.hasResultRows(),
DbPreparedStatementHandler
public String executeGetFirstString(ReadQuery query)
throws DatabaseException
String
from the results of a select query. It relies on the wrapped DbResultSet.getFirstString() method, but also automatically closes the
statement after its execution.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.field("name").from("person");
String result = manager.executeGetFirstString(select);
query - the query builder instance that needs to be executed
String in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstString()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstString(),
DbPreparedStatementHandler
public String executeGetFirstString(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
String from the
results of a customizable select query. It relies on the wrapped DbResultSet.getFirstString() method, but also automatically closes the
statement after its execution and allows customization of the prepared
statement through an optional instance of DbPreparedStatementHandler.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.field("first").from("person").whereParameter("last", "=");
final String last = "Smith";
String result = manager.executeGetFirstString(select, new DbPreparedStatementHandler() {
public void setParameters(DbPreparedStatement statement)
{
statement
.setString("last", last);
}
});
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
String in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstString()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstString(),
DbPreparedStatementHandler
public boolean executeGetFirstBoolean(ReadQuery query)
throws DatabaseException
boolean
from the results of a select query. It relies on the wrapped DbResultSet.getFirstBoolean() method, but also automatically closes
the statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executed
boolean in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstBoolean()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstBoolean(),
DbPreparedStatementHandler
public boolean executeGetFirstBoolean(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
boolean from the
results of a customizable select query. It relies on the wrapped DbResultSet.getFirstBoolean() method, but also automatically closes
the statement after its execution and allows customization of the
prepared statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
boolean in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstBoolean()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstBoolean(),
DbPreparedStatementHandler
public byte executeGetFirstByte(ReadQuery query)
throws DatabaseException
byte from
the results of a select query. It relies on the wrapped DbResultSet.getFirstByte() method, but also automatically closes the
statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executed
byte in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstByte()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstByte(),
DbPreparedStatementHandler
public byte executeGetFirstByte(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
byte from the results
of a customizable select query. It relies on the wrapped DbResultSet.getFirstByte() method, but also automatically closes the
statement after its execution and allows customization of the prepared
statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
byte in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstByte()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstByte(),
DbPreparedStatementHandler
public short executeGetFirstShort(ReadQuery query)
throws DatabaseException
short
from the results of a select query. It relies on the wrapped DbResultSet.getFirstShort() method, but also automatically closes the
statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executed
short in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstShort()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstShort(),
DbPreparedStatementHandler
public short executeGetFirstShort(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
short from the
results of a customizable select query. It relies on the wrapped DbResultSet.getFirstShort() method, but also automatically closes the
statement after its execution and allows customization of the prepared
statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
short in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstShort()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstShort(),
DbPreparedStatementHandler
public int executeGetFirstInt(ReadQuery query)
throws DatabaseException
int from
the results of a select query. It relies on the wrapped DbResultSet.getFirstInt() method, but also automatically closes the
statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executed
int in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstInt()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstInt(),
DbPreparedStatementHandler
public int executeGetFirstInt(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
int from the results
of a customizable select query. It relies on the wrapped DbResultSet.getFirstInt() method, but also automatically closes the
statement after its execution and allows customization of the prepared
statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
int in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstInt()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstInt(),
DbPreparedStatementHandler
public long executeGetFirstLong(ReadQuery query)
throws DatabaseException
long from
the results of a select query. It relies on the wrapped DbResultSet.getFirstLong() method, but also automatically closes the
statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executed
long in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstLong()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstLong(),
DbPreparedStatementHandler
public long executeGetFirstLong(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
long from the results
of a customizable select query. It relies on the wrapped DbResultSet.getFirstLong() method, but also automatically closes the
statement after its execution and allows customization of the prepared
statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
long in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstLong()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstLong(),
DbPreparedStatementHandler
public float executeGetFirstFloat(ReadQuery query)
throws DatabaseException
float
from the results of a select query. It relies on the wrapped DbResultSet.getFirstFloat() method, but also automatically closes the
statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executed
float in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstFloat()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstFloat(),
DbPreparedStatementHandler
public float executeGetFirstFloat(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
float from the
results of a customizable select query. It relies on the wrapped DbResultSet.getFirstFloat() method, but also automatically closes the
statement after its execution and allows customization of the prepared
statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
float in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstFloat()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstFloat(),
DbPreparedStatementHandler
public double executeGetFirstDouble(ReadQuery query)
throws DatabaseException
double
from the results of a select query. It relies on the wrapped DbResultSet.getFirstDouble() method, but also automatically closes the
statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executed
double in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstDouble()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstDouble(),
DbPreparedStatementHandler
public double executeGetFirstDouble(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
double from the
results of a customizable select query. It relies on the wrapped DbResultSet.getFirstDouble() method, but also automatically closes the
statement after its execution and allows customization of the prepared
statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
double in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstDouble()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstDouble(),
DbPreparedStatementHandler
public byte[] executeGetFirstBytes(ReadQuery query)
throws DatabaseException
byte
array from the results of a select query. It relies on the wrapped
DbResultSet.getFirstBytes() method, but also automatically
closes the statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executed
byte array in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstBytes()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstBytes(),
DbPreparedStatementHandler
public byte[] executeGetFirstBytes(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
byte array from the
results of a customizable select query. It relies on the wrapped DbResultSet.getFirstBytes() method, but also automatically closes the
statement after its execution and allows customization of the prepared
statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
byte array in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstBytes()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstBytes(),
DbPreparedStatementHandler
public Date executeGetFirstDate(ReadQuery query)
throws DatabaseException
Date
from the results of a select query. It relies on the wrapped DbResultSet.getFirstDate() method, but also automatically closes the
statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executed
Date in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstDate()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstDate(),
DbPreparedStatementHandler
public Date executeGetFirstDate(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
Date from the
results of a customizable select query. It relies on the wrapped DbResultSet.getFirstDate() method, but also automatically closes the
statement after its execution and allows customization of the prepared
statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
Date in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstDate()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstDate(),
DbPreparedStatementHandler
public Date executeGetFirstDate(ReadQuery query,
Calendar cal)
throws DatabaseException
Date
from the results of a select query. It relies on the wrapped DbResultSet.getFirstDate(Calendar) method, but also automatically
closes the statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedcal - the Calendar object to use in constructing the
date
Date in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstDate(Calendar)DbPreparedStatement.executeQuery(),
DbResultSet.getFirstDate(Calendar),
DbPreparedStatementHandler
public Date executeGetFirstDate(ReadQuery query,
Calendar cal,
DbPreparedStatementHandler handler)
throws DatabaseException
Date from the
results of a customizable select query. It relies on the wrapped DbResultSet.getFirstDate(Calendar) method, but also automatically
closes the statement after its execution and allows customization of
the prepared statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedcal - the Calendar object to use in constructing the
datehandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
Date in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstDate(Calendar)DbPreparedStatement.executeQuery(),
DbResultSet.getFirstDate(Calendar),
DbPreparedStatementHandler
public Time executeGetFirstTime(ReadQuery query)
throws DatabaseException
Time
from the results of a select query. It relies on the wrapped DbResultSet.getFirstTime() method, but also automatically closes the
statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executed
Time in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstTime()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstTime(),
DbPreparedStatementHandler
public Time executeGetFirstTime(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
Time from the
results of a customizable select query. It relies on the wrapped DbResultSet.getFirstTime() method, but also automatically closes the
statement after its execution and allows customization of the prepared
statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
Time in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstTime()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstTime(),
DbPreparedStatementHandler
public Time executeGetFirstTime(ReadQuery query,
Calendar cal)
throws DatabaseException
Time
from the results of a select query. It relies on the wrapped DbResultSet.getFirstTime(Calendar) method, but also automatically
closes the statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedcal - the Calendar object to use in constructing the
time
Time in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstTime(Calendar)DbPreparedStatement.executeQuery(),
DbResultSet.getFirstTime(Calendar),
DbPreparedStatementHandler
public Time executeGetFirstTime(ReadQuery query,
Calendar cal,
DbPreparedStatementHandler handler)
throws DatabaseException
Time from the
results of a customizable select query. It relies on the wrapped DbResultSet.getFirstTime(Calendar) method, but also automatically
closes the statement after its execution and allows customization of
the prepared statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedcal - the Calendar object to use in constructing the
timehandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
Time in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstTime(Calendar)DbPreparedStatement.executeQuery(),
DbResultSet.getFirstTime(Calendar),
DbPreparedStatementHandler
public Timestamp executeGetFirstTimestamp(ReadQuery query)
throws DatabaseException
Timestamp from the results of a select query. It relies on
the wrapped DbResultSet.getFirstTimestamp() method, but also
automatically closes the statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executed
Timestamp in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstTimestamp()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstTimestamp(),
DbPreparedStatementHandler
public Timestamp executeGetFirstTimestamp(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
Timestamp from
the results of a customizable select query. It relies on the wrapped
DbResultSet.getFirstTimestamp() method, but also automatically
closes the statement after its execution and allows customization of
the prepared statement through an optional instance of DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
Timestamp in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstTimestamp()DbPreparedStatement.executeQuery(),
DbResultSet.getFirstTimestamp(),
DbPreparedStatementHandler
public Timestamp executeGetFirstTimestamp(ReadQuery query,
Calendar cal)
throws DatabaseException
Timestamp from the results of a select query. It relies on
the wrapped DbResultSet.getFirstTimestamp(Calendar) method, but
also automatically closes the statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedcal - the Calendar object to use in constructing the
timestamp
Timestamp in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstTimestamp(Calendar)DbPreparedStatement.executeQuery(),
DbResultSet.getFirstTimestamp(Calendar),
DbPreparedStatementHandler
public Timestamp executeGetFirstTimestamp(ReadQuery query,
Calendar cal,
DbPreparedStatementHandler handler)
throws DatabaseException
Timestamp from
the results of a customizable select query. It relies on the wrapped
DbResultSet.getFirstTimestamp(Calendar) method, but also
automatically closes the statement after its execution and allows
customization of the prepared statement through an optional instance of
DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executedcal - the Calendar object to use in constructing the
timestamphandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
Timestamp in the query's resultset
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstTimestamp(Calendar)DbPreparedStatement.executeQuery(),
DbResultSet.getFirstTimestamp(Calendar),
DbPreparedStatementHandler
public <ResultType> ResultType executeUseFirstAsciiStream(ReadQuery query,
InputStreamUser user)
throws DatabaseException,
InnerClassException
InputStream from the results of a select query. It relies
on the wrapped DbResultSet.getFirstAsciiStream() method, but
also automatically closes the statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executeduser - an instance of InputStreamUser
that contains the logic that will be executed with this stream
useInputStream method of
the provided InputStreamUser instance
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstAsciiStream()
InnerClassException - when errors occurs inside the
InputStreamUserInputStreamUser,
DbPreparedStatement.executeQuery(),
DbResultSet.getFirstAsciiStream(),
DbPreparedStatementHandler
public <ResultType> ResultType executeUseFirstAsciiStream(ReadQuery query,
InputStreamUser user,
DbPreparedStatementHandler handler)
throws DatabaseException,
InnerClassException
InputStream
from the results of a customizable select query. It relies on the
wrapped DbResultSet.getFirstAsciiStream() method, but also
automatically closes the statement after its execution and allows
customization of the prepared statement through an optional instance of
DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executeduser - an instance of InputStreamUser
that contains the logic that will be executed with this streamhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
useInputStream method of
the provided InputStreamUser instance
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstAsciiStream()
InnerClassException - when errors occurs inside the
InputStreamUserInputStreamUser,
DbPreparedStatement.executeQuery(),
DbResultSet.getFirstAsciiStream(),
DbPreparedStatementHandler
public <ResultType> ResultType executeUseFirstCharacterStream(ReadQuery query,
ReaderUser user)
throws DatabaseException,
InnerClassException
Reader from the results of a select query. It relies on
the wrapped DbResultSet.getFirstCharacterStream() method, but
also automatically closes the statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executeduser - an instance of ReaderUser
that contains the logic that will be executed with this reader
useReader method of
the provided ReaderUser instance
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstCharacterStream()
InnerClassException - when errors occurs inside the
ReaderUserReaderUser,
DbPreparedStatement.executeQuery(),
DbResultSet.getFirstCharacterStream(),
DbPreparedStatementHandler
public <ResultType> ResultType executeUseFirstCharacterStream(ReadQuery query,
ReaderUser user,
DbPreparedStatementHandler handler)
throws DatabaseException,
InnerClassException
Reader
from the results of a customizable select query. It relies on the
wrapped DbResultSet.getFirstCharacterStream() method, but also
automatically closes the statement after its execution and allows
customization of the prepared statement through an optional instance of
DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executeduser - an instance of ReaderUser
that contains the logic that will be executed with this readerhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
useReader method of
the provided ReaderUser instance
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstCharacterStream()
InnerClassException - when errors occurs inside the
ReaderUserReaderUser,
DbPreparedStatement.executeQuery(),
DbResultSet.getFirstCharacterStream(),
DbPreparedStatementHandler
public <ResultType> ResultType executeUseFirstBinaryStream(ReadQuery query,
InputStreamUser user)
throws DatabaseException,
InnerClassException
InputStream from the results of a select query. It relies
on the wrapped DbResultSet.getFirstBinaryStream() method, but
also automatically closes the statement after its execution.
Refer to executeGetFirstString
for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executeduser - an instance of InputStreamUser
that contains the logic that will be executed with this stream
useInputStream method of
the provided InputStreamUser instance
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstBinaryStream()
InnerClassException - when errors occurs inside the
InputStreamUserInputStreamUser,
DbPreparedStatement.executeQuery(),
DbResultSet.getFirstBinaryStream(),
DbPreparedStatementHandler
public <ResultType> ResultType executeUseFirstBinaryStream(ReadQuery query,
InputStreamUser user,
DbPreparedStatementHandler handler)
throws DatabaseException,
InnerClassException
InputStream
from the results of a customizable select query. It relies on the
wrapped DbResultSet.getFirstBinaryStream() method, but also
automatically closes the statement after its execution and allows
customization of the prepared statement through an optional instance of
DbPreparedStatementHandler.
Refer to executeGetFirstString for an example code snippet, it's 100% analogue.
query - the query builder instance that needs to be executeduser - an instance of InputStreamUser
that contains the logic that will be executed with this streamhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
useInputStream method of
the provided InputStreamUser instance
DatabaseException - see DbPreparedStatement.executeQuery()and DbResultSet.getFirstBinaryStream()
InnerClassException - when errors occurs inside the
InputStreamUserInputStreamUser,
DbPreparedStatement.executeQuery(),
DbResultSet.getFirstBinaryStream(),
DbPreparedStatementHandler
public boolean executeFetchFirst(ReadQuery query,
DbRowProcessor rowProcessor)
throws DatabaseException
fetch(ResultSet, DbRowProcessor) method, but automatically closes the
statement after its execution.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.from("person").where("name", "=", "me");
DbRowProcessor processor = new YourProcessor();
boolean result = manager.executeFetchFirst(select, processor);
query - the query builder instance that needs to be executedrowProcessor - a DbRowProcessor instance, if it's
null no processing will be performed on the fetched row
true if a row was retrieved; or
false if there are no more rows .
DatabaseException - see DbPreparedStatement.executeQuery()and fetch(ResultSet, DbRowProcessor)fetch(ResultSet, DbRowProcessor),
DbRowProcessor
public boolean executeFetchFirst(ReadQuery query,
DbRowProcessor rowProcessor,
DbPreparedStatementHandler handler)
throws DatabaseException
fetch(ResultSet, DbRowProcessor) method, but also automatically
closes the statement after its execution and allows customization of
the prepared statement through an optional instance of DbPreparedStatementHandler.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.from("person").whereParameter("name", "=");
DbRowProcessor processor = new YourProcessor();
final String name = "you";
boolean result = manager.executeFetchFirst(select, processor, new DbPreparedStatementHandler() {
public void setParameters(DbPreparedStatement statement)
{
statement
.setString("name", name);
}
});
query - the query builder instance that needs to be executedrowProcessor - a DbRowProcessor instance, if it's
null no processing will be performed on the fetched rowhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
true if a row was retrieved; or
false if there are no more rows .
DatabaseException - see DbPreparedStatement.executeQuery()and fetch(ResultSet, DbRowProcessor)fetch(ResultSet, DbRowProcessor),
DbRowProcessor
public <BeanType> BeanType executeFetchFirstBean(ReadQuery query,
Class<BeanType> beanClass)
throws DatabaseException
executeFetchFirst(ReadQuery, DbRowProcessor) method, but automatically
uses an appropriate DbBeanFetcher instance and returns the
resulting bean.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.from("person").fields(Person.class);
Person person = manager.executeFetchFirstBean(select, Person.class);
query - the query builder instance that needs to be executedbeanClass - the class of the bean
true if a row was retrieved; or
false if there are no more rows .
DatabaseException - see DbBeanFetcher and executeFetchFirst(ReadQuery, DbRowProcessor)executeFetchFirst(ReadQuery, DbRowProcessor),
DbBeanFetcher
public <BeanType> BeanType executeFetchFirstBean(ReadQuery query,
Class<BeanType> beanClass,
DbPreparedStatementHandler handler)
throws DatabaseException
executeFetchFirst(ReadQuery, DbRowProcessor) method, but automatically
uses an appropriate DbBeanFetcher instance, returns the
resulting bean and allows customization of the prepared statement
through an optional instance of DbPreparedStatementHandler.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.from("person").fields(Person.class).whereParameter("name", "=");
final String name = "you";
Person person = manager.executeFetchFirstBean(select, Person.class, new DbPreparedStatementHandler() {
public void setParameters(DbPreparedStatement statement)
{
statement
.setString("name", name);
}
});
query - the query builder instance that needs to be executedbeanClass - the class of the beanhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
true if a row was retrieved; or
false if there are no more rows .
DatabaseException - see DbBeanFetcher and executeFetchFirst(ReadQuery, DbRowProcessor)executeFetchFirst(ReadQuery, DbRowProcessor),
DbBeanFetcher
public boolean executeFetchAll(ReadQuery query,
DbRowProcessor rowProcessor)
throws DatabaseException
fetchAll(ResultSet, DbRowProcessor) method, but automatically closes
the statement after its execution.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.from("person").where("gender", "=", "m");
DbRowProcessor processor = new YourProcessor();
boolean result = manager.executeFetchAll(select, processor);
query - the query builder instance that needs to be executedrowProcessor - a DbRowProcessor instance, if it's
null no processing will be performed on the fetched rows
true if rows were retrieved; or
false if there are no more rows .
DatabaseException - see DbPreparedStatement.executeQuery()and fetchAll(ResultSet, DbRowProcessor)fetchAll(ResultSet, DbRowProcessor),
DbRowProcessor
public boolean executeFetchAll(ReadQuery query,
DbRowProcessor rowProcessor,
DbPreparedStatementHandler handler)
throws DatabaseException
fetchAll(ResultSet, DbRowProcessor) method, but also automatically
closes the statement after its execution and allows customization of
the prepared statement through an optional instance of DbPreparedStatementHandler.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.from("person").whereParameter("gender", "=");
DbRowProcessor processor = new YourProcessor();
final String name = "m";
boolean result = manager.executeFetchAll(select, processor, new DbPreparedStatementHandler() {
public void setParameters(DbPreparedStatement statement)
{
statement
.setString("gender", name);
}
});
query - the query builder instance that needs to be executedrowProcessor - a DbRowProcessor instance, if it's
null no processing will be performed on the fetched rowhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
true if rows were retrieved; or
false if there are no more rows .
DatabaseException - see DbPreparedStatement.executeQuery()and fetchAll(ResultSet, DbRowProcessor)fetchAll(ResultSet, DbRowProcessor),
DbRowProcessor
public <BeanType> List<BeanType> executeFetchAllBeans(ReadQuery query,
Class<BeanType> beanClass)
throws DatabaseException
executeFetchAll(ReadQuery, DbRowProcessor) method, but automatically
uses an appropriate DbBeanFetcher instance and returns the
results.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.from("person").fields(Person.class).where("gender", "=", "m");
List persons = manager.executeFetchAllBeans(select, Person.class);
query - the query builder instance that needs to be executedbeanClass - the class of the bean
a List instance with all the beans, the list is empty if
no beans could be returned
DatabaseException - see DbBeanFetcher and executeFetchAll(ReadQuery, DbRowProcessor)executeFetchAll(ReadQuery, DbRowProcessor),
DbBeanFetcher
public <BeanType> List<BeanType> executeFetchAllBeans(ReadQuery query,
Class<BeanType> beanClass,
DbPreparedStatementHandler handler)
throws DatabaseException
executeFetchAll(ReadQuery, DbRowProcessor) method, but automatically
uses an appropriate DbBeanFetcher instance, returns the results
and allows customization of the prepared statement through an optional
instance of DbPreparedStatementHandler.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select.from("person").fields(Person.class).whereParameter("gender", "=");
final String name = "m";
List persons = manager.executeFetchAllBeans(select, Person.class, new DbPreparedStatementHandler() {
public void setParameters(DbPreparedStatement statement)
{
statement
.setString("gender", name);
}
});
query - the query builder instance that needs to be executedbeanClass - the class of the beanhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
a List instance with all the beans, the list is empty if
no beans could be returned
DatabaseException - see DbBeanFetcher and executeFetchAll(ReadQuery, DbRowProcessor)executeFetchAll(ReadQuery, DbRowProcessor),
DbBeanFetcher
public <ResultType> ResultType executeQuery(ReadQuery query,
DbPreparedStatementHandler handler)
throws DatabaseException
DbPreparedStatement.executeQuery() method, but also
automatically closes the statement after its execution and allows
complete customization of the prepared statement through an optional
instance of DbPreparedStatementHandler.
This method is typically used when you need to fully customize a query at runtime, but still want to benefit of a safety net that ensures that the allocated statement will be closed. Often another more specialized method in this class will already serve your needs, so be sure to verify that you actually need to intervene on every front.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select
.field("first")
.field("last")
.from("person")
.whereParameter("name", "=");
final String name = "you";
String result = (String)manager.executeQuery(select, new DbPreparedStatementHandler() {
public void setParameters(DbPreparedStatement statement)
{
statement
.setString("name", name);
}
public Object concludeResults(DbResultSet resultset)
throws SQLException
{
return resultset.getString("first")+" "+resultset.getString("last");
}
});
query - the query builder instance that needs to be executedhandler - an instance of DbPreparedStatementHandler
that will be used to customize the query execution; or
null if you don't want to customize it at all
concludeResults
method; or
null if this method wasn't overridden
DatabaseException - see DbPreparedStatement.executeQuery()DbPreparedStatement.executeQuery(),
DbPreparedStatementHandler
public <ResultType> ResultType executeQuery(ReadQuery query,
DbResultSetHandler handler)
throws DatabaseException
DbPreparedStatement.executeQuery()
method, but also automatically closes the statement after its execution
and allows interaction with the resultset through an optional instance
of DbResultSetHandler.
This method is typically used when you need to interact with the results of a query, but still want to benefit of a safety net that ensures that the allocated statement will be closed. Often another more specialized method in this class will already serve your needs, so be sure to verify that there isn't another one that's better suited.
DbQueryManager manager = new DbQueryManager(datasource);
Select select = new Select(datasource);
select
.field("first")
.field("last")
.from("person");
String result = (String)manager.executeQuery(select, new DbResultSetHandler() {
public Object concludeResults(DbResultSet resultset)
throws SQLException
{
return resultset.getString("first")+" "+resultset.getString("last");
}
});
query - the query builder instance that needs to be executedhandler - an instance of DbResultSetHandler
that will be used to handle the results of the query execution; or
null if you don't want to customize it at all
concludeResults
method; or
null if this method wasn't overridden
DatabaseException - see DbPreparedStatement.executeQuery()DbPreparedStatement.executeQuery(),
DbResultSetHandler
public <ResultType> ResultType reserveConnection(DbConnectionUser user)
throws InnerClassException,
DatabaseException
DbConnectionUser
instance.
This is typically used to ensure that a series of operations is done with the same connection, even though a database pool is used in the background.
Person person;
final Insert store_data = new Insert(datasource).into("person").fields(person);
final Select get_last_id = new Select(datasource).from("person").field("LAST_INSERT_ID()");
final DbQueryManager manager = new DbQueryManager(datasource);
int id = ((Integer)manager.reserveConnection(new DbConnectionUser() {
public Integer useConnection(DbConnection connection)
{
manager.executeUpdate(store_data);
return new Integer(manager.executeGetFirstInt(get_last_id));
}
})).intValue();
user - an instance of DbConnectionUser that contains
the logic that will be executed
useConnection method of
the provided DbConnectionUser instance
DatabaseException - when errors occurs during the reservation
of a connection for this thread
InnerClassException - when errors occurs inside the
DbConnectionUserDbConnectionUser.useConnection(DbConnection)
public <ResultType> ResultType inTransaction(DbTransactionUser user)
throws InnerClassException,
DatabaseException
DbTransactionUser instance are executed inside a transaction
and committed afterwards. This doesn't mean that a new transaction will
always be created. If a transaction is already active, it will simply
be re-used. The commit will also only be take place if a new
transaction has actually been started, otherwise it's the
responsibility of the enclosing code to execute the commit. If an
runtime exception occurs during the execution and a new transaction has
been started beforehand, it will be automatically rolled back.
If you need to explicitly roll back an active transaction, use the
rollback method of the
DbTransactionUser class. If you use a regular rollback
method, it's possible that you're inside a nested transaction executed
and that after the rollback, other logic continues to be executed
outside the transaction. Using the correct rollback method, stops the execution of
the active DbTransactionUser and breaks out of any number
of them nesting.
It's recommended to always use transactions through this method since it ensures that transactional code can be re-used and enclosed in other transactional code. Correctly using the regular transaction-related methods requires great care and planning and often results in error-prone and not reusable code.
final Insert insert = new Insert(mDatasource).into("valuelist").field("value", 232);
final DbQueryManager manager = new DbQueryManager(datasource);
manager.inTransaction(new DbTransactionUserWithoutResult() {
public void useTransactionWithoutResult()
throws InnerClassException
{
manager.executeUpdate(insert);
manager.executeUpdate(insert);
}
});
user - an instance of DbTransactionUser that contains
the logic that will be executed
useTransaction method of
the provided DbTransactionUser instance
DatabaseException - when errors occurs during the handling of
the transaction
InnerClassException - when errors occurs inside the
DbTransactionUserDbTransactionUser.useTransaction(),
DbTransactionUserWithoutResult.useTransactionWithoutResult()
public DbStatement executeQuery(ReadQuery query)
throws DatabaseException
DbQueryManager's Datasource. Functions
exactly as the wrapped DbStatement.executeQuery(ReadQuery) method.
Note that the statement will not be automatically closed since using this method implies that you still have to work with the resultset.
query - the query builder instance that should be executed
DatabaseException - see DbStatement.executeQuery(ReadQuery)DbStatement.executeQuery(ReadQuery)
public boolean fetch(ResultSet resultSet)
throws DatabaseException
resultSet - a valid ResultSet instance
true if a new row was retrieved; or
false if there are no more rows .
DatabaseException - when an error occurred during the fetch of
the next row in the resultsetfetch(ResultSet, DbRowProcessor)
public boolean fetch(ResultSet resultSet,
DbRowProcessor rowProcessor)
throws DatabaseException
DbRowProcessor.
resultSet - a valid ResultSet instancerowProcessor - a DbRowProcessor instance, if it's
null no processing will be performed on the fetched row
true if a new row was retrieved; or
false if there are no more rows .
DatabaseException - when an error occurred during the fetch of
the next row in the resultsetfetch(ResultSet),
DbRowProcessor
public boolean fetchAll(ResultSet resultSet,
DbRowProcessor rowProcessor)
throws DatabaseException
DbRowProcessor.
resultSet - a valid ResultSet instancerowProcessor - a DbRowProcessor instance, if it's
null no processing will be performed on the fetched rows
true if rows were fetched; or
false if the resultset contained no rows.
DatabaseException - when an error occurred during the fetch of
the next rows in the resultsetDbRowProcessor
public DbConnection getConnection()
throws DatabaseException
DbConnection of this DbQueryManager's
Datasource. Functions exactly as the wrapped Datasource.getConnection() method.
DbConnection
DatabaseException - see Datasource.getConnection()Datasource.getConnection()public Datasource getDatasource()
Datasource of this
DbQueryManager.
Datasourcepublic Object clone()
clone in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||