com.j256.ormlite.stmt
Class StatementExecutor<T,ID>

java.lang.Object
  extended by com.j256.ormlite.stmt.StatementExecutor<T,ID>
All Implemented Interfaces:
GenericRowMapper<String[]>

public class StatementExecutor<T,ID>
extends Object
implements GenericRowMapper<String[]>

Executes SQL statements for a particular table in a particular database. Basically a call through to various mapped statement methods.

Author:
graywatson

Constructor Summary
StatementExecutor(DatabaseType databaseType, TableInfo<T,ID> tableInfo, Dao<T,ID> dao)
          Provides statements for various SQL operations.
 
Method Summary
 SelectIterator<T,ID> buildIterator(BaseDaoImpl<T,ID> classDao, ConnectionSource connectionSource, 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)
          Create and return an SelectIterator for the class using a prepared statement.
<CT> CT
callBatchTasks(DatabaseConnection connection, boolean saved, Callable<CT> callable)
          Call batch tasks insude 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.
 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.
 long queryForCountStar(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt)
          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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatementExecutor

public StatementExecutor(DatabaseType databaseType,
                         TableInfo<T,ID> tableInfo,
                         Dao<T,ID> dao)
Provides statements for various SQL operations.

Method Detail

queryForId

public T queryForId(DatabaseConnection databaseConnection,
                    ID id,
                    ObjectCache objectCache)
             throws SQLException
Return the object associated with the id or null if none. This does a SQL select col1,col2,... from ... where ... = id type query.

Throws:
SQLException

queryForFirst

public T queryForFirst(DatabaseConnection databaseConnection,
                       PreparedStmt<T> preparedStmt,
                       ObjectCache objectCache)
                throws SQLException
Return the first object that matches the PreparedStmt or null if none.

Throws:
SQLException

queryForAll

public List<T> queryForAll(ConnectionSource connectionSource,
                           ObjectCache objectCache)
                    throws SQLException
Return a list of all of the data in the table. Should be used carefully if the table is large. Consider using the Dao.iterator() if this is the case.

Throws:
SQLException

queryForCountStar

public long queryForCountStar(DatabaseConnection databaseConnection)
                       throws SQLException
Return a long value which is the number of rows in the table.

Throws:
SQLException

queryForCountStar

public long queryForCountStar(DatabaseConnection databaseConnection,
                              PreparedStmt<T> preparedStmt)
                       throws SQLException
Return a long value which is the number of rows in the table.

Throws:
SQLException

query

public List<T> query(ConnectionSource connectionSource,
                     PreparedStmt<T> preparedStmt,
                     ObjectCache objectCache)
              throws SQLException
Return a list of all of the data in the table that matches the PreparedStmt. Should be used carefully if the table is large. Consider using the Dao.iterator() if this is the case.

Throws:
SQLException

buildIterator

public SelectIterator<T,ID> buildIterator(BaseDaoImpl<T,ID> classDao,
                                          ConnectionSource connectionSource,
                                          ObjectCache objectCache)
                                   throws SQLException
Create and return a SelectIterator for the class using the default mapped query for all statement.

Throws:
SQLException

getSelectStarRowMapper

public GenericRowMapper<T> getSelectStarRowMapper()
                                           throws SQLException
Return a row mapper suitable for mapping 'select *' queries.

Throws:
SQLException

buildIterator

public SelectIterator<T,ID> buildIterator(BaseDaoImpl<T,ID> classDao,
                                          ConnectionSource connectionSource,
                                          PreparedStmt<T> preparedStmt,
                                          ObjectCache objectCache)
                                   throws SQLException
Create and return an SelectIterator for the class using a prepared statement.

Throws:
SQLException

queryRaw

public GenericRawResults<String[]> queryRaw(ConnectionSource connectionSource,
                                            String query,
                                            String[] arguments,
                                            ObjectCache objectCache)
                                     throws SQLException
Return a results object associated with an internal iterator that returns String[] results.

Throws:
SQLException

queryRaw

public <UO> GenericRawResults<UO> queryRaw(ConnectionSource connectionSource,
                                           String query,
                                           RawRowMapper<UO> rowMapper,
                                           String[] arguments,
                                           ObjectCache objectCache)
                               throws SQLException
Return a results object associated with an internal iterator is mapped by the user's rowMapper.

Throws:
SQLException

queryRaw

public GenericRawResults<Object[]> queryRaw(ConnectionSource connectionSource,
                                            String query,
                                            DataType[] columnTypes,
                                            String[] arguments,
                                            ObjectCache objectCache)
                                     throws SQLException
Return a results object associated with an internal iterator that returns Object[] results.

Throws:
SQLException

updateRaw

public int updateRaw(DatabaseConnection connection,
                     String statement,
                     String[] arguments)
              throws SQLException
Return the number of rows affected.

Throws:
SQLException

executeRaw

public int executeRaw(DatabaseConnection connection,
                      String statement,
                      String[] arguments)
               throws SQLException
Return true if it worked else false.

Throws:
SQLException

create

public int create(DatabaseConnection databaseConnection,
                  T data,
                  ObjectCache objectCache)
           throws SQLException
Create a new entry in the database from an object.

Throws:
SQLException

update

public int update(DatabaseConnection databaseConnection,
                  T data,
                  ObjectCache objectCache)
           throws SQLException
Update an object in the database.

Throws:
SQLException

updateId

public int updateId(DatabaseConnection databaseConnection,
                    T data,
                    ID newId,
                    ObjectCache objectCache)
             throws SQLException
Update an object in the database to change its id to the newId parameter.

Throws:
SQLException

update

public int update(DatabaseConnection databaseConnection,
                  PreparedUpdate<T> preparedUpdate)
           throws SQLException
Update rows in the database.

Throws:
SQLException

refresh

public int refresh(DatabaseConnection databaseConnection,
                   T data,
                   ObjectCache objectCache)
            throws SQLException
Does a query for the object's Id and copies in each of the field values from the database to refresh the data parameter.

Throws:
SQLException

delete

public int delete(DatabaseConnection databaseConnection,
                  T data,
                  ObjectCache objectCache)
           throws SQLException
Delete an object from the database.

Throws:
SQLException

deleteById

public int deleteById(DatabaseConnection databaseConnection,
                      ID id,
                      ObjectCache objectCache)
               throws SQLException
Delete an object from the database by id.

Throws:
SQLException

deleteObjects

public int deleteObjects(DatabaseConnection databaseConnection,
                         Collection<T> datas,
                         ObjectCache objectCache)
                  throws SQLException
Delete a collection of objects from the database.

Throws:
SQLException

deleteIds

public int deleteIds(DatabaseConnection databaseConnection,
                     Collection<ID> ids,
                     ObjectCache objectCache)
              throws SQLException
Delete a collection of objects from the database.

Throws:
SQLException

delete

public int delete(DatabaseConnection databaseConnection,
                  PreparedDelete<T> preparedDelete)
           throws SQLException
Delete rows that match the prepared statement.

Throws:
SQLException

callBatchTasks

public <CT> CT callBatchTasks(DatabaseConnection connection,
                              boolean saved,
                              Callable<CT> callable)
                  throws Exception
Call batch tasks insude of a connection which may, or may not, have been "saved".

Throws:
Exception

mapRow

public String[] mapRow(DatabaseResults results)
                throws SQLException
Description copied from interface: GenericRowMapper
Used to convert a results row to an object.

Specified by:
mapRow in interface GenericRowMapper<String[]>
Parameters:
results - Results object we are mapping.
Returns:
The created object with all of the fields set from the results;
Throws:
SQLException - If we could not get the SQL results or instantiate the object.

ifExists

public boolean ifExists(DatabaseConnection connection,
                        ID id)
                 throws SQLException
Throws:
SQLException


This content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.