com.jpattern.orm.session
Class PlainSqlPerformer

java.lang.Object
  extended by com.jpattern.orm.session.PlainSqlPerformer
All Implemented Interfaces:
SqlPerformer

public class PlainSqlPerformer
extends Object
implements SqlPerformer

Author:
Francesco Cina 02/lug/2011

Constructor Summary
PlainSqlPerformer(SqlPerformerStrategy sqlPerformerStrategy)
           
 
Method Summary
 int[] batchUpdate(List<String> sqls)
          Issue multiple SQL updates on a single JDBC Statement using batching.
 int[] batchUpdate(String sql, BatchPreparedStatementSetter psc)
          Issue multiple SQL updates on a single JDBC Statement using batching.
 int[] batchUpdate(String sql, List<Object[]> args)
          Issue multiple SQL updates on a single JDBC Statement using batching.
 void execute(String sql)
          Issue a single SQL execute, typically a DDL statement.
 int getMaxRows()
          Return the maximum number of rows specified for this sql query.
 int getQueryTimeout()
          Return the query timeout for the statements.
<T> T
query(String sql, ResultSetReader<T> rse, Collection<?> args)
          Execute a query given static SQL, reading the ResultSet with a IResultSetReader.
<T> T
query(String sql, ResultSetReader<T> rse, Object... args)
          Execute a query given static SQL, reading the ResultSet with a IResultSetReader.
<T> List<T>
query(String sql, ResultSetRowReader<T> rsrr, Collection<?> args)
          Execute a query given static SQL, reading the ResultSet with a ResultSetRowReader.
<T> List<T>
query(String sql, ResultSetRowReader<T> rsrr, Object... args)
          Execute a query given static SQL, reading the ResultSet with a ResultSetRowReader.
 Object[] queryForArray(String sql, Collection<?> values)
          Execute a query given static SQL and read the result creating an ordered array with the extracted column values (return null if no rows are returned)
 Object[] queryForArray(String sql, Object... values)
          Execute a query given static SQL and read the result creating an ordered array with the extracted column values (return null if no rows are returned)
 BigDecimal queryForBigDecimal(String sql, Collection<?> values)
          Execute a query given static SQL and read the result as a BigDecimal value (return null if no rows are returned)
 BigDecimal queryForBigDecimal(String sql, Object... values)
          Execute a query given static SQL and read the result as a BigDecimal value (return null if no rows are returned)
 Boolean queryForBoolean(String sql, Collection<?> values)
          Execute a query given static SQL and read the result as a boolean value (return null if no rows are returned)
 Boolean queryForBoolean(String sql, Object... values)
          Execute a query given static SQL and read the result as a boolean value (return null if no rows are returned)
 Double queryForDouble(String sql, Collection<?> values)
          Execute a query given static SQL and read the result as a double value (return null if no rows are returned)
 Double queryForDouble(String sql, Object... values)
          Execute a query given static SQL and read the result as a double value (return null if no rows are returned)
 Float queryForFloat(String sql, Collection<?> values)
          Execute a query given static SQL and read the result as a float value (return null if no rows are returned)
 Float queryForFloat(String sql, Object... values)
          Execute a query given static SQL and read the result as a float value (return null if no rows are returned)
 Integer queryForInt(String sql, Collection<?> values)
          Execute a query given static SQL and read the result as an int value (return null if no rows are returned)
 Integer queryForInt(String sql, Object... values)
          Execute a query given static SQL and read the result as an int value (return null if no rows are returned)
 List<Object[]> queryForList(String sql, Collection<?> values)
          Execute a query given static SQL and read the result creating a List of all the ordered arrays with the extracted column values for every row.
 List<Object[]> queryForList(String sql, Object... values)
          Execute a query given static SQL and read the result creating a List of all the ordered arrays with the extracted column values for every row.
 Long queryForLong(String sql, Collection<?> values)
          Execute a query given static SQL and read the result as an long value (return null if no rows are returned)
 Long queryForLong(String sql, Object... values)
          Execute a query given static SQL and read the result as an long value (return null if no rows are returned)
 String queryForString(String sql, Collection<?> values)
          Execute a query given static SQL and read the result as a String value (return null if no rows are returned)
 String queryForString(String sql, Object... values)
          Execute a query given static SQL and read the result as a String value (return null if no rows are returned)
<T> T
queryForUnique(String sql, ResultSetRowReader<T> rsrr, Collection<?> args)
          Execute a query given static SQL, reading the ResultSet with a ResultSetRowReader.
<T> T
queryForUnique(String sql, ResultSetRowReader<T> rsrr, Object... args)
          Execute a query given static SQL, reading the ResultSet with a ResultSetRowReader.
 void setMaxRows(int maxRows)
          Set the maximum number of rows returnd by the execution of the sql query
 void setQueryTimeout(int queryTimeout)
          Set the query timeout for the statements.
 int update(String sql, Collection<?> args)
          Perform a single SQL update operation (such as an insert, update or delete statement).
 int update(String sql, GeneratedKeyReader generatedKeyReader, Collection<?> args)
          Issue an update statement using a PreparedStatementCreator to provide SQL and any required parameters.
 int update(String sql, GeneratedKeyReader generatedKeyReader, Object... args)
          Issue an update statement using a PreparedStatementCreator to provide SQL and any required parameters.
 int update(String sql, GeneratedKeyReader generatedKeyReader, PreparedStatementSetter psc)
          Issue an update statement using a PreparedStatementCreator to provide SQL and any required parameters.
 int update(String sql, Object... args)
          Perform a single SQL update operation (such as an insert, update or delete statement).
 int update(String sql, PreparedStatementSetter psc)
          Perform a single SQL update operation (such as an insert, update or delete statement).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlainSqlPerformer

public PlainSqlPerformer(SqlPerformerStrategy sqlPerformerStrategy)
Method Detail

setMaxRows

public final void setMaxRows(int maxRows)
Description copied from interface: SqlPerformer
Set the maximum number of rows returnd by the execution of the sql query

Specified by:
setMaxRows in interface SqlPerformer

getMaxRows

public final int getMaxRows()
Description copied from interface: SqlPerformer
Return the maximum number of rows specified for this sql query.

Specified by:
getMaxRows in interface SqlPerformer

setQueryTimeout

public final void setQueryTimeout(int queryTimeout)
Description copied from interface: SqlPerformer
Set the query timeout for the statements.

Specified by:
setQueryTimeout in interface SqlPerformer

getQueryTimeout

public final int getQueryTimeout()
Description copied from interface: SqlPerformer
Return the query timeout for the statements.

Specified by:
getQueryTimeout in interface SqlPerformer

queryForInt

public final Integer queryForInt(String sql,
                                 Object... values)
                          throws OrmException,
                                 OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as an int value (return null if no rows are returned)

Specified by:
queryForInt in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForInt

public final Integer queryForInt(String sql,
                                 Collection<?> values)
                          throws OrmException,
                                 OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as an int value (return null if no rows are returned)

Specified by:
queryForInt in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForLong

public final Long queryForLong(String sql,
                               Object... values)
                        throws OrmException,
                               OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as an long value (return null if no rows are returned)

Specified by:
queryForLong in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForLong

public final Long queryForLong(String sql,
                               Collection<?> values)
                        throws OrmException,
                               OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as an long value (return null if no rows are returned)

Specified by:
queryForLong in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForDouble

public final Double queryForDouble(String sql,
                                   Object... values)
                            throws OrmException,
                                   OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as a double value (return null if no rows are returned)

Specified by:
queryForDouble in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForDouble

public final Double queryForDouble(String sql,
                                   Collection<?> values)
                            throws OrmException,
                                   OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as a double value (return null if no rows are returned)

Specified by:
queryForDouble in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForFloat

public final Float queryForFloat(String sql,
                                 Object... values)
                          throws OrmException,
                                 OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as a float value (return null if no rows are returned)

Specified by:
queryForFloat in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForFloat

public final Float queryForFloat(String sql,
                                 Collection<?> values)
                          throws OrmException,
                                 OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as a float value (return null if no rows are returned)

Specified by:
queryForFloat in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForString

public final String queryForString(String sql,
                                   Object... values)
                            throws OrmException,
                                   OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as a String value (return null if no rows are returned)

Specified by:
queryForString in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForString

public final String queryForString(String sql,
                                   Collection<?> values)
                            throws OrmException,
                                   OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as a String value (return null if no rows are returned)

Specified by:
queryForString in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForBoolean

public final Boolean queryForBoolean(String sql,
                                     Object... values)
                              throws OrmException,
                                     OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as a boolean value (return null if no rows are returned)

Specified by:
queryForBoolean in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForBoolean

public final Boolean queryForBoolean(String sql,
                                     Collection<?> values)
                              throws OrmException,
                                     OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as a boolean value (return null if no rows are returned)

Specified by:
queryForBoolean in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForBigDecimal

public final BigDecimal queryForBigDecimal(String sql,
                                           Object... values)
                                    throws OrmException,
                                           OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as a BigDecimal value (return null if no rows are returned)

Specified by:
queryForBigDecimal in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForBigDecimal

public final BigDecimal queryForBigDecimal(String sql,
                                           Collection<?> values)
                                    throws OrmException,
                                           OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result as a BigDecimal value (return null if no rows are returned)

Specified by:
queryForBigDecimal in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForArray

public final Object[] queryForArray(String sql,
                                    Object... values)
                             throws OrmException,
                                    OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result creating an ordered array with the extracted column values (return null if no rows are returned)

Specified by:
queryForArray in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForArray

public final Object[] queryForArray(String sql,
                                    Collection<?> values)
                             throws OrmException,
                                    OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result creating an ordered array with the extracted column values (return null if no rows are returned)

Specified by:
queryForArray in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmNotUniqueResultException - if more than one row is returned from the query
OrmException

queryForList

public final List<Object[]> queryForList(String sql,
                                         Object... values)
                                  throws OrmException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result creating a List of all the ordered arrays with the extracted column values for every row.

Specified by:
queryForList in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmException

queryForList

public final List<Object[]> queryForList(String sql,
                                         Collection<?> values)
                                  throws OrmException
Description copied from interface: SqlPerformer
Execute a query given static SQL and read the result creating a List of all the ordered arrays with the extracted column values for every row.

Specified by:
queryForList in interface SqlPerformer
Parameters:
sql - SQL query to execute
values - arguments to bind to the query
Returns:
Throws:
OrmException

execute

public void execute(String sql)
             throws OrmException
Description copied from interface: SqlPerformer
Issue a single SQL execute, typically a DDL statement.

Specified by:
execute in interface SqlPerformer
Parameters:
sql - static SQL to execute
Throws:
OrmException

query

public <T> T query(String sql,
                   ResultSetReader<T> rse,
                   Object... args)
        throws OrmException
Description copied from interface: SqlPerformer
Execute a query given static SQL, reading the ResultSet with a IResultSetReader.

Specified by:
query in interface SqlPerformer
Parameters:
sql - SQL query to execute
rse - object that will extract all rows of results
args - arguments to bind to the query
Returns:
an arbitrary result object, as returned by the IResultSetExtractor
Throws:
OrmException

query

public <T> T query(String sql,
                   ResultSetReader<T> rse,
                   Collection<?> args)
        throws OrmException
Description copied from interface: SqlPerformer
Execute a query given static SQL, reading the ResultSet with a IResultSetReader.

Specified by:
query in interface SqlPerformer
Parameters:
sql - SQL query to execute
rse - object that will extract all rows of results
args - arguments to bind to the query
Returns:
an arbitrary result object, as returned by the IResultSetExtractor
Throws:
OrmException

query

public <T> List<T> query(String sql,
                         ResultSetRowReader<T> rsrr,
                         Object... args)
              throws OrmException
Description copied from interface: SqlPerformer
Execute a query given static SQL, reading the ResultSet with a ResultSetRowReader.

Specified by:
query in interface SqlPerformer
Parameters:
sql - SQL query to execute
rsrr - object that will extract all rows of results
args - arguments to bind to the query
Returns:
an arbitrary result object, as returned by the ResultSetRowReader
Throws:
OrmException

query

public <T> List<T> query(String sql,
                         ResultSetRowReader<T> rsrr,
                         Collection<?> args)
              throws OrmException
Description copied from interface: SqlPerformer
Execute a query given static SQL, reading the ResultSet with a ResultSetRowReader.

Specified by:
query in interface SqlPerformer
Parameters:
sql - SQL query to execute
rsrr - object that will extract all rows of results
args - arguments to bind to the query
Returns:
an arbitrary result object, as returned by the ResultSetRowReader
Throws:
OrmException

queryForUnique

public <T> T queryForUnique(String sql,
                            ResultSetRowReader<T> rsrr,
                            Object... args)
                 throws OrmException,
                        OrmNotUniqueResultException
Description copied from interface: SqlPerformer
Execute a query given static SQL, reading the ResultSet with a ResultSetRowReader.

Specified by:
queryForUnique in interface SqlPerformer
Parameters:
sql - SQL query to execute
rsrr - object that will extract th result's row
args - arguments to bind to the query
Returns:
an arbitrary result object, as returned by the ResultSetRowReader
Throws:
OrmNotUniqueResultException - if not exactly one row is returned by the query execution
OrmException

queryForUnique

public <T> T queryForUnique(String sql,
                            ResultSetRowReader<T> rsrr,
                            Collection<?> args)
                 throws OrmException
Description copied from interface: SqlPerformer
Execute a query given static SQL, reading the ResultSet with a ResultSetRowReader.

Specified by:
queryForUnique in interface SqlPerformer
Parameters:
sql - SQL query to execute
rsrr - object that will extract th result's row
args - arguments to bind to the query
Returns:
an arbitrary result object, as returned by the ResultSetRowReader
Throws:
OrmNotUniqueResultException - if not exactly one row is returned by the query execution
OrmException

update

public int update(String sql,
                  Object... args)
           throws OrmException
Description copied from interface: SqlPerformer
Perform a single SQL update operation (such as an insert, update or delete statement).

Specified by:
update in interface SqlPerformer
Parameters:
sql - static SQL to execute
args - arguments to bind to the query
Returns:
the number of rows affected
Throws:
OrmException

update

public int update(String sql,
                  Collection<?> args)
           throws OrmException
Description copied from interface: SqlPerformer
Perform a single SQL update operation (such as an insert, update or delete statement).

Specified by:
update in interface SqlPerformer
Parameters:
sql - static SQL to execute
args - arguments to bind to the query
Returns:
the number of rows affected
Throws:
OrmException

update

public int update(String sql,
                  PreparedStatementSetter psc)
           throws OrmException
Description copied from interface: SqlPerformer
Perform a single SQL update operation (such as an insert, update or delete statement).

Specified by:
update in interface SqlPerformer
Parameters:
sql - static SQL to execute
Returns:
the number of rows affected
Throws:
OrmException

update

public int update(String sql,
                  GeneratedKeyReader generatedKeyReader,
                  Object... args)
           throws OrmException
Description copied from interface: SqlPerformer
Issue an update statement using a PreparedStatementCreator to provide SQL and any required parameters. Generated keys can be read using the IGeneratedKeyReader.

Specified by:
update in interface SqlPerformer
generatedKeyReader - IGeneratedKeyReader to read the generated key
Returns:
the number of rows affected
Throws:
OrmException

update

public int update(String sql,
                  GeneratedKeyReader generatedKeyReader,
                  Collection<?> args)
           throws OrmException
Description copied from interface: SqlPerformer
Issue an update statement using a PreparedStatementCreator to provide SQL and any required parameters. Generated keys can be read using the IGeneratedKeyReader.

Specified by:
update in interface SqlPerformer
generatedKeyReader - IGeneratedKeyReader to read the generated key
Returns:
the number of rows affected
Throws:
OrmException

update

public int update(String sql,
                  GeneratedKeyReader generatedKeyReader,
                  PreparedStatementSetter psc)
           throws OrmException
Description copied from interface: SqlPerformer
Issue an update statement using a PreparedStatementCreator to provide SQL and any required parameters. Generated keys can be read using the GeneratedKeyReader.

Specified by:
update in interface SqlPerformer
Parameters:
sql - static SQL to execute
Returns:
the number of rows affected
Throws:
OrmException

batchUpdate

public int[] batchUpdate(List<String> sqls)
                  throws OrmException
Description copied from interface: SqlPerformer
Issue multiple SQL updates on a single JDBC Statement using batching.

Specified by:
batchUpdate in interface SqlPerformer
Returns:
an array of the number of rows affected by each statement
Throws:
OrmException

batchUpdate

public int[] batchUpdate(String sql,
                         List<Object[]> args)
                  throws OrmException
Description copied from interface: SqlPerformer
Issue multiple SQL updates on a single JDBC Statement using batching. The same query is executed for every Object array present in the args list which is the list of arguments to bind to the query.

Specified by:
batchUpdate in interface SqlPerformer
Parameters:
sql - defining a List of SQL statements that will be executed.
args - defining a List of Object arrays to bind to the query.
Returns:
an array of the number of rows affected by each statement
Throws:
OrmException

batchUpdate

public int[] batchUpdate(String sql,
                         BatchPreparedStatementSetter psc)
                  throws OrmException
Description copied from interface: SqlPerformer
Issue multiple SQL updates on a single JDBC Statement using batching. The values on the generated PreparedStatement are set using an IPreparedStatementCreator.

Specified by:
batchUpdate in interface SqlPerformer
Parameters:
sql - defining a List of SQL statements that will be executed.
psc - the creator to bind values on the PreparedStatement
Returns:
an array of the number of rows affected by each statement
Throws:
OrmException


Copyright © 2013. All Rights Reserved.