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)
          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)
          Create and return an SelectIterator for the class using a prepared statement.
 RawResults buildOldIterator(ConnectionSource connectionSource, String query)
          Return on old RawResults object associated with an internal iterator that matches the query argument.
<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)
          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)
          Delete an object from the database.
 int deleteIds(DatabaseConnection databaseConnection, Collection<ID> ids)
          Delete a collection of objects from the database.
 int deleteObjects(DatabaseConnection databaseConnection, Collection<T> datas)
          Delete a collection of objects from the database.
 int executeRaw(ConnectionSource connectionSource, String statement, String[] arguments)
          Return true if it worked else false.
 String[] mapRow(DatabaseResults results)
          Used to convert a results row to an object.
 List<T> query(ConnectionSource connectionSource, PreparedStmt<T> preparedStmt)
          Return a list of all of the data in the table that matches the PreparedStmt.
 List<T> queryForAll(ConnectionSource connectionSource)
          Return a list of all of the data in the table.
 RawResults queryForAllRawOld(ConnectionSource connectionSource, String query)
          Return a list of all of the data in the table that matches the PreparedStmt.
 long queryForCountStar(DatabaseConnection databaseConnection)
          Return a long value which is the number of rows in the table.
 T queryForFirst(DatabaseConnection databaseConnection, PreparedStmt<T> preparedStmt)
          Return the first object that matches the PreparedStmt or null if none.
 T queryForId(DatabaseConnection databaseConnection, ID id)
          Return the object associated with the id or null if none.
 GenericRawResults<Object[]> queryRaw(ConnectionSource connectionSource, String query, DataType[] columnTypes, String[] arguments)
          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)
          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)
          Return a results object associated with an internal iterator that returns String[] results.
 int refresh(DatabaseConnection databaseConnection, T data)
          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)
          Update an object in the database.
 int updateId(DatabaseConnection databaseConnection, T data, ID newId)
          Update an object in the database to change its id to the newId parameter.
 int updateRaw(ConnectionSource connectionSource, 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)
                  throws SQLException
Provides statements for various SQL operations.

Throws:
SQLException
Method Detail

queryForId

public T queryForId(DatabaseConnection databaseConnection,
                    ID id)
             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)
                throws SQLException
Return the first object that matches the PreparedStmt or null if none.

Throws:
SQLException

queryForAll

public List<T> queryForAll(ConnectionSource connectionSource)
                    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

query

public List<T> query(ConnectionSource connectionSource,
                     PreparedStmt<T> preparedStmt)
              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

queryForAllRawOld

public RawResults queryForAllRawOld(ConnectionSource connectionSource,
                                    String query)
                             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)
                                   throws SQLException
Create and return a SelectIterator for the class using the default mapped query for all statement.

Throws:
SQLException

buildIterator

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

Throws:
SQLException

buildOldIterator

public RawResults buildOldIterator(ConnectionSource connectionSource,
                                   String query)
                            throws SQLException
Return on old RawResults object associated with an internal iterator that matches the query argument.

Throws:
SQLException

queryRaw

public GenericRawResults<String[]> queryRaw(ConnectionSource connectionSource,
                                            String query,
                                            String[] arguments)
                                     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)
                               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)
                                     throws SQLException
Return a results object associated with an internal iterator that returns Object[] results.

Throws:
SQLException

updateRaw

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

Throws:
SQLException

executeRaw

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

Throws:
SQLException

create

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

Throws:
SQLException

update

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

Throws:
SQLException

updateId

public int updateId(DatabaseConnection databaseConnection,
                    T data,
                    ID newId)
             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)
            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)
           throws SQLException
Delete an object from the database.

Throws:
SQLException

deleteObjects

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

Throws:
SQLException

deleteIds

public int deleteIds(DatabaseConnection databaseConnection,
                     Collection<ID> ids)
              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.


Copyright © 2011. All Rights Reserved.