T
- The class that the code will be operating on.ID
- The class of the ID column associated with the class. The T class does not require an ID field. The class
needs an ID parameter however so you can use Void or Object to satisfy the compiler.public class StatementExecutor<T,ID> extends Object implements GenericRowMapper<String[]>
Constructor and Description |
---|
StatementExecutor(DatabaseType databaseType,
TableInfo<T,ID> tableInfo,
Dao<T,ID> dao)
Provides statements for various SQL operations.
|
Modifier and Type | Method and Description |
---|---|
SelectIterator<T,ID> |
buildIterator(BaseDaoImpl<T,ID> classDao,
ConnectionSource connectionSource,
int resultFlags,
ObjectCache objectCache)
Create and return a SelectIterator for the class using the default mapped query for all statement.
|
SelectIterator<T,ID> |
buildIterator(BaseDaoImpl<T,ID> classDao,
ConnectionSource connectionSource,
PreparedStmt<T> preparedStmt,
ObjectCache objectCache,
int resultFlags)
Create and return an
SelectIterator for the class using a prepared statement. |
<CT> CT |
callBatchTasks(ConnectionSource connectionSource,
Callable<CT> callable)
Call batch tasks inside of a connection which may, or may not, have been "saved".
|
int |
create(DatabaseConnection databaseConnection,
T data,
ObjectCache objectCache)
Create a new entry in the database from an object.
|
int |
delete(DatabaseConnection databaseConnection,
PreparedDelete<T> preparedDelete)
Delete rows that match the prepared statement.
|
int |
delete(DatabaseConnection databaseConnection,
T data,
ObjectCache objectCache)
Delete an object from the database.
|
int |
deleteById(DatabaseConnection databaseConnection,
ID id,
ObjectCache objectCache)
Delete an object from the database by id.
|
int |
deleteIds(DatabaseConnection databaseConnection,
Collection<ID> ids,
ObjectCache objectCache)
Delete a collection of objects from the database.
|
int |
deleteObjects(DatabaseConnection databaseConnection,
Collection<T> datas,
ObjectCache objectCache)
Delete a collection of objects from the database.
|
int |
executeRaw(DatabaseConnection connection,
String statement,
String[] arguments)
Return true if it worked else false.
|
int |
executeRawNoArgs(DatabaseConnection connection,
String statement)
Return true if it worked else false.
|
RawRowMapper<T> |
getRawRowMapper()
Return a raw row mapper suitable for use with
Dao.queryRaw(String, RawRowMapper, String...) . |
GenericRowMapper<T> |
getSelectStarRowMapper()
Return a row mapper suitable for mapping 'select *' queries.
|
boolean |
ifExists(DatabaseConnection connection,
ID id) |
String[] |
mapRow(DatabaseResults results)
Used to convert a results row to an object.
|
List<T> |
query(ConnectionSource connectionSource,
PreparedStmt<T> preparedStmt,
ObjectCache objectCache)
Return a list of all of the data in the table that matches the
PreparedStmt . |
List<T> |
queryForAll(ConnectionSource connectionSource,
ObjectCache objectCache)
Return a list of all of the data in the table.
|
long |
queryForCountStar(DatabaseConnection databaseConnection)
Return a long value which is the number of rows in the table.
|
T |
queryForFirst(DatabaseConnection databaseConnection,
PreparedStmt<T> preparedStmt,
ObjectCache objectCache)
Return the first object that matches the
PreparedStmt or null if none. |
T |
queryForId(DatabaseConnection databaseConnection,
ID id,
ObjectCache objectCache)
Return the object associated with the id or null if none.
|
long |
queryForLong(DatabaseConnection databaseConnection,
PreparedStmt<T> preparedStmt)
Return a long value from a prepared query.
|
long |
queryForLong(DatabaseConnection databaseConnection,
String query,
String[] arguments)
Return a long from a raw query with String[] arguments.
|
<UO> GenericRawResults<UO> |
queryRaw(ConnectionSource connectionSource,
String query,
DatabaseResultsMapper<UO> mapper,
String[] arguments,
ObjectCache objectCache)
Return a results object associated with an internal iterator is mapped by the user's rowMapper.
|
<UO> GenericRawResults<UO> |
queryRaw(ConnectionSource connectionSource,
String query,
DataType[] columnTypes,
RawRowObjectMapper<UO> rowMapper,
String[] arguments,
ObjectCache objectCache)
Return a results object associated with an internal iterator is mapped by the user's rowMapper.
|
GenericRawResults<Object[]> |
queryRaw(ConnectionSource connectionSource,
String query,
DataType[] columnTypes,
String[] arguments,
ObjectCache objectCache)
Return a results object associated with an internal iterator that returns Object[] results.
|
<UO> GenericRawResults<UO> |
queryRaw(ConnectionSource connectionSource,
String query,
RawRowMapper<UO> rowMapper,
String[] arguments,
ObjectCache objectCache)
Return a results object associated with an internal iterator is mapped by the user's rowMapper.
|
GenericRawResults<String[]> |
queryRaw(ConnectionSource connectionSource,
String query,
String[] arguments,
ObjectCache objectCache)
Return a results object associated with an internal iterator that returns String[] results.
|
int |
refresh(DatabaseConnection databaseConnection,
T data,
ObjectCache objectCache)
Does a query for the object's Id and copies in each of the field values from the database to refresh the data
parameter.
|
int |
update(DatabaseConnection databaseConnection,
PreparedUpdate<T> preparedUpdate)
Update rows in the database.
|
int |
update(DatabaseConnection databaseConnection,
T data,
ObjectCache objectCache)
Update an object in the database.
|
int |
updateId(DatabaseConnection databaseConnection,
T data,
ID newId,
ObjectCache objectCache)
Update an object in the database to change its id to the newId parameter.
|
int |
updateRaw(DatabaseConnection connection,
String statement,
String[] arguments)
Return the number of rows affected.
|
public T queryForId(DatabaseConnection databaseConnection, ID id, ObjectCache objectCache) throws SQLException
SELECT col1,col2,... FROM ... WHERE ... = id
type query.SQLException
public T queryForFirst(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt, ObjectCache objectCache) throws SQLException
PreparedStmt
or null if none.SQLException
public List<T> queryForAll(ConnectionSource connectionSource, ObjectCache objectCache) throws SQLException
Dao.iterator()
if this is the case.SQLException
public long queryForCountStar(DatabaseConnection databaseConnection) throws SQLException
SQLException
public long queryForLong(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt) throws SQLException
SQLException
public long queryForLong(DatabaseConnection databaseConnection, String query, String[] arguments) throws SQLException
SQLException
public List<T> query(ConnectionSource connectionSource, PreparedStmt<T> preparedStmt, ObjectCache objectCache) throws SQLException
PreparedStmt
. Should be used carefully if
the table is large. Consider using the Dao.iterator()
if this is the case.SQLException
public SelectIterator<T,ID> buildIterator(BaseDaoImpl<T,ID> classDao, ConnectionSource connectionSource, int resultFlags, ObjectCache objectCache) throws SQLException
SQLException
public GenericRowMapper<T> getSelectStarRowMapper() throws SQLException
SQLException
public RawRowMapper<T> getRawRowMapper()
Dao.queryRaw(String, RawRowMapper, String...)
.public SelectIterator<T,ID> buildIterator(BaseDaoImpl<T,ID> classDao, ConnectionSource connectionSource, PreparedStmt<T> preparedStmt, ObjectCache objectCache, int resultFlags) throws SQLException
SelectIterator
for the class using a prepared statement.SQLException
public GenericRawResults<String[]> queryRaw(ConnectionSource connectionSource, String query, String[] arguments, ObjectCache objectCache) throws SQLException
SQLException
public <UO> GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query, RawRowMapper<UO> rowMapper, String[] arguments, ObjectCache objectCache) throws SQLException
SQLException
public <UO> GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes, RawRowObjectMapper<UO> rowMapper, String[] arguments, ObjectCache objectCache) throws SQLException
SQLException
public GenericRawResults<Object[]> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes, String[] arguments, ObjectCache objectCache) throws SQLException
SQLException
public <UO> GenericRawResults<UO> queryRaw(ConnectionSource connectionSource, String query, DatabaseResultsMapper<UO> mapper, String[] arguments, ObjectCache objectCache) throws SQLException
SQLException
public int updateRaw(DatabaseConnection connection, String statement, String[] arguments) throws SQLException
SQLException
public int executeRawNoArgs(DatabaseConnection connection, String statement) throws SQLException
SQLException
public int executeRaw(DatabaseConnection connection, String statement, String[] arguments) throws SQLException
SQLException
public int create(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException
SQLException
public int update(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException
SQLException
public int updateId(DatabaseConnection databaseConnection, T data, ID newId, ObjectCache objectCache) throws SQLException
SQLException
public int update(DatabaseConnection databaseConnection, PreparedUpdate<T> preparedUpdate) throws SQLException
SQLException
public int refresh(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException
SQLException
public int delete(DatabaseConnection databaseConnection, T data, ObjectCache objectCache) throws SQLException
SQLException
public int deleteById(DatabaseConnection databaseConnection, ID id, ObjectCache objectCache) throws SQLException
SQLException
public int deleteObjects(DatabaseConnection databaseConnection, Collection<T> datas, ObjectCache objectCache) throws SQLException
SQLException
public int deleteIds(DatabaseConnection databaseConnection, Collection<ID> ids, ObjectCache objectCache) throws SQLException
SQLException
public int delete(DatabaseConnection databaseConnection, PreparedDelete<T> preparedDelete) throws SQLException
SQLException
public <CT> CT callBatchTasks(ConnectionSource connectionSource, Callable<CT> callable) throws SQLException
SQLException
public String[] mapRow(DatabaseResults results) throws SQLException
GenericRowMapper
mapRow
in interface GenericRowMapper<String[]>
results
- Results object we are mapping.SQLException
- If we could not get the SQL results or instantiate the object.public boolean ifExists(DatabaseConnection connection, ID id) throws SQLException
SQLException
This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.