org.midao.jdbc.core
Class QueryRunner

java.lang.Object
  extended by org.midao.jdbc.core.AbstractQueryRunner
      extended by org.midao.jdbc.core.QueryRunner
All Implemented Interfaces:
QueryRunnerService

public class QueryRunner
extends AbstractQueryRunner

Base QueryRunnerService implementation


Field Summary
 
Fields inherited from class org.midao.jdbc.core.AbstractQueryRunner
overrider
 
Constructor Summary
QueryRunner(java.sql.Connection conn)
          Creates new QueryRunner instance
QueryRunner(java.sql.Connection conn, java.lang.Class<? extends TypeHandler> typeHandlerClazz)
          Creates new QueryRunner instance
QueryRunner(java.sql.Connection conn, java.lang.Class<? extends TypeHandler> typeHandlerClazz, java.lang.Class<? extends StatementHandler> statementHandlerClazz)
          Creates new QueryRunner instance
QueryRunner(javax.sql.DataSource ds)
          Creates new QueryRunner instance
QueryRunner(javax.sql.DataSource ds, java.lang.Class<? extends TypeHandler> typeHandlerClazz)
          Creates new QueryRunner instance
QueryRunner(javax.sql.DataSource ds, java.lang.Class<? extends TypeHandler> typeHandlerClazz, java.lang.Class<? extends StatementHandler> statementHandlerClazz)
          Creates new QueryRunner instance
 
Method Summary
 int[] batch(InputHandler[] inputHandlers)
          Execute a batch of SQL INSERT, UPDATE, or DELETE queries.
 int[] batch(java.lang.String sql, java.lang.Object[][] params)
          Execute a batch of SQL INSERT, UPDATE, or DELETE queries.
<T> T
call(AbstractNamedInputHandler<T> inputHandler)
          Executes the given CALL SQL statement.
<T> T
call(AbstractNamedInputHandler<T> inputHandler, java.lang.String catalog, java.lang.String schema, boolean useCache)
          Executes the given CALL SQL statement.
 QueryParameters call(AbstractQueryInputHandler inputHandler)
          Executes the given CALL SQL statement.
<T,S> CallResults
call(InputHandler<T> inputHandler, OutputHandler<S> outputHandler)
          Executes the given CALL SQL statement.
<T,S> CallResults
call(InputHandler<T> inputHandler, OutputHandler<S> outputHandler, java.lang.String catalog, java.lang.String schema, boolean useCache)
          Executes the given CALL SQL statement.
<T> T
query(InputHandler inputHandler, OutputHandler<T> outputHandler)
          Executes the given SELECT SQL query and returns a result object.
<T> T
query(java.lang.String sql, OutputHandler<T> outputHandler)
          Executes the given SELECT SQL without any replacement parameters.
<T> T
query(java.lang.String sql, OutputHandler<T> outputHandler, java.lang.Object... params)
          Executes the given SELECT SQL query and returns a result object.
 int update(InputHandler inputHandler)
          Executes the given INSERT, UPDATE, or DELETE SQL statement.
<T> T
update(InputHandler inputHandler, OutputHandler<T> outputHandler)
          Executes the given INSERT, UPDATE, or DELETE SQL statement.
 int update(java.lang.String sql)
          Executes the given INSERT, UPDATE, or DELETE SQL statement without any replacement parameters.
 int update(java.lang.String sql, java.lang.Object... params)
          Executes the given INSERT, UPDATE, or DELETE SQL statement.
 int update(java.lang.String sql, java.lang.Object param)
          Executes the given INSERT, UPDATE, or DELETE SQL statement with a single replacement parameter.
<T> T
update(java.lang.String sql, OutputHandler<T> outputHandler, java.lang.Object... params)
          Executes the given INSERT, UPDATE, or DELETE SQL statement.
 
Methods inherited from class org.midao.jdbc.core.AbstractQueryRunner
batch, call, commit, convertToQueryInputHandler, createStatement, getExceptionHandler, getMetadataHandler, getOverrider, getQueryParams, getQueryParams, getSqlQuery, getStatementHandler, getTransactionHandler, getTransactionIsolationLevel, getTypeHandler, isTransactionManualMode, nullException, override, overrideOnce, prepareCall, prepareStatement, query, releaseSavepoint, removeOverride, rollback, rollback, setExceptionHandler, setMetadataHandler, setSavepoint, setSavepoint, setStatementHandler, setTransactionHandler, setTransactionIsolationLevel, setTransactionManualMode, setTypeHandler, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryRunner

public QueryRunner(javax.sql.DataSource ds)
Creates new QueryRunner instance

Parameters:
ds - SQL DataSource

QueryRunner

public QueryRunner(java.sql.Connection conn)
Creates new QueryRunner instance

Parameters:
conn - SQL Connection

QueryRunner

public QueryRunner(javax.sql.DataSource ds,
                   java.lang.Class<? extends TypeHandler> typeHandlerClazz)
Creates new QueryRunner instance

Parameters:
ds - SQL DataSource
typeHandlerClazz - TypeHandler implementation class (from which new TypeHandler instance would be created)

QueryRunner

public QueryRunner(javax.sql.DataSource ds,
                   java.lang.Class<? extends TypeHandler> typeHandlerClazz,
                   java.lang.Class<? extends StatementHandler> statementHandlerClazz)
Creates new QueryRunner instance

Parameters:
ds - SQL DataSource
typeHandlerClazz - TypeHandler implementation class (from which new TypeHandler instance would be created)
statementHandlerClazz - StatementHandler implementation class (from which new TypeHandler instance would be created)

QueryRunner

public QueryRunner(java.sql.Connection conn,
                   java.lang.Class<? extends TypeHandler> typeHandlerClazz)
Creates new QueryRunner instance

Parameters:
conn - SQL Connection
typeHandlerClazz - TypeHandler implementation class (from which new TypeHandler instance would be created)

QueryRunner

public QueryRunner(java.sql.Connection conn,
                   java.lang.Class<? extends TypeHandler> typeHandlerClazz,
                   java.lang.Class<? extends StatementHandler> statementHandlerClazz)
Creates new QueryRunner instance

Parameters:
conn - SQL Connection
typeHandlerClazz - TypeHandler implementation class (from which new TypeHandler instance would be created)
statementHandlerClazz - StatementHandler implementation class (from which new TypeHandler instance would be created)
Method Detail

batch

public int[] batch(java.lang.String sql,
                   java.lang.Object[][] params)
            throws java.sql.SQLException
Execute a batch of SQL INSERT, UPDATE, or DELETE queries.

Parameters:
sql - The SQL to execute.
params - An array of query replacement parameters. Each row in this array is one set of batch replacement values.
Returns:
Array with number of rows updated per statement.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

batch

public int[] batch(InputHandler[] inputHandlers)
            throws java.sql.SQLException
Execute a batch of SQL INSERT, UPDATE, or DELETE queries.

Parameters:
inputHandlers - Input Handler which would be executed
Returns:
Array with number of rows updated per statement.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

query

public <T> T query(java.lang.String sql,
                   OutputHandler<T> outputHandler,
                   java.lang.Object... params)
        throws java.sql.SQLException
Executes the given SELECT SQL query and returns a result object.

Type Parameters:
T - The type of object that the handler returns
Parameters:
sql - The SQL statement to execute.
outputHandler - The handler used to create the result object from Query output
params - Initialize the PreparedStatement's IN parameters with this array.
Returns:
An object generated by the handler.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

query

public <T> T query(InputHandler inputHandler,
                   OutputHandler<T> outputHandler)
        throws java.sql.SQLException
Executes the given SELECT SQL query and returns a result object.

Type Parameters:
T - The type of object that the handler returns
Parameters:
inputHandler - Input Handler which would be executed
outputHandler - The handler used to create the result object from Query output
Returns:
An object generated by the handler.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

query

public <T> T query(java.lang.String sql,
                   OutputHandler<T> outputHandler)
        throws java.sql.SQLException
Executes the given SELECT SQL without any replacement parameters.

Type Parameters:
T - The type of object that the handler returns
Parameters:
sql - The SQL statement to execute.
outputHandler - The handler used to create the result object from Query output
Returns:
An object generated by the handler.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

update

public int update(java.lang.String sql)
           throws java.sql.SQLException
Executes the given INSERT, UPDATE, or DELETE SQL statement without any replacement parameters.

Parameters:
sql - The SQL statement to execute.
Returns:
The number of rows updated.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

update

public int update(java.lang.String sql,
                  java.lang.Object param)
           throws java.sql.SQLException
Executes the given INSERT, UPDATE, or DELETE SQL statement with a single replacement parameter.

Parameters:
sql - The SQL statement to execute.
param - The replacement parameter.
Returns:
The number of rows updated.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

update

public int update(java.lang.String sql,
                  java.lang.Object... params)
           throws java.sql.SQLException
Executes the given INSERT, UPDATE, or DELETE SQL statement.

Parameters:
sql - The SQL statement to execute.
params - Initializes the PreparedStatement's IN (i.e. '?') parameters.
Returns:
The number of rows updated.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

update

public int update(InputHandler inputHandler)
           throws java.sql.SQLException
Executes the given INSERT, UPDATE, or DELETE SQL statement.

Parameters:
inputHandler - Input Handler which would be executed
Returns:
The number of rows updated.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

update

public <T> T update(InputHandler inputHandler,
                    OutputHandler<T> outputHandler)
         throws java.sql.SQLException
Executes the given INSERT, UPDATE, or DELETE SQL statement.

Type Parameters:
T - The type of object that the handler returns
Parameters:
inputHandler - Input Handler which would be executed
outputHandler - The handler used to create the result object from Query output
Returns:
An object generated by the handler.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

update

public <T> T update(java.lang.String sql,
                    OutputHandler<T> outputHandler,
                    java.lang.Object... params)
         throws java.sql.SQLException
Executes the given INSERT, UPDATE, or DELETE SQL statement.

Type Parameters:
T - The type of object that the handler returns
Parameters:
sql - The SQL statement to execute.
outputHandler - The handler used to create the result object from Query output
params - Initializes the PreparedStatement's IN (i.e. '?') parameters.
Returns:
An object generated by the handler.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

call

public QueryParameters call(AbstractQueryInputHandler inputHandler)
                     throws java.sql.SQLException
Executes the given CALL SQL statement. Allows execution of Stored Procedures/Functions

Parameters:
inputHandler - Input Handler which would be executed
Returns:
Query Output. All input parameters are updated from OUT parameters. Stored Function return is stored there as well. Can be received by invoking QueryParameters.getReturn()
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

call

public <T> T call(AbstractNamedInputHandler<T> inputHandler,
                  java.lang.String catalog,
                  java.lang.String schema,
                  boolean useCache)
       throws java.sql.SQLException
Executes the given CALL SQL statement. Allows execution of Stored Procedures/Functions This function reads database metadata and identifies OUT fields. Output from OUT fields is merged with input and returned as function return. If function fails during reading database metadata please use QueryRunnerService.call(org.midao.jdbc.core.handlers.input.query.AbstractQueryInputHandler) as it is possible to specify Direction in QueryParameters class

Type Parameters:
T - The type of object that the handler returns
Parameters:
inputHandler - Input Handler which would be executed
catalog - Database Catalog. If null would be specified - this value won't be used in search
schema - Database Schema. If null would be specified - this value won't be used in search
useCache - specifies if it should use cache for reading Stored Procedure/Function parameters
Returns:
An object generated by the handler.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

call

public <T> T call(AbstractNamedInputHandler<T> inputHandler)
       throws java.sql.SQLException
Executes the given CALL SQL statement. Allows execution of Stored Procedures/Functions This function reads database metadata and identifies OUT fields. Output from OUT fields is merged with input and returned as function return. If function fails during reading database metadata please use QueryRunnerService.call(org.midao.jdbc.core.handlers.input.query.AbstractQueryInputHandler) as it is possible to specify Direction in QueryParameters class

Type Parameters:
T - The type of object that the handler returns
Parameters:
inputHandler - Input Handler which would be executed
Returns:
An object generated by the handler.
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

call

public <T,S> CallResults call(InputHandler<T> inputHandler,
                              OutputHandler<S> outputHandler,
                              java.lang.String catalog,
                              java.lang.String schema,
                              boolean useCache)
                 throws java.sql.SQLException
Executes the given CALL SQL statement. Allows execution of Stored Procedures/Functions This function reads database metadata and identifies OUT fields. Output from OUT fields is merged with input and returned as function return. If function fails during reading database metadata please use QueryRunnerService.call(org.midao.jdbc.core.handlers.input.query.AbstractQueryInputHandler) as it is possible to specify Direction in QueryParameters class

Type Parameters:
T - The type of object that the input handler clones, updates and returns
S - The type of object that the output handler returns
Parameters:
inputHandler - Input Handler which would be executed
outputHandler - The handler used to create the result object from Query output
catalog - Database Catalog. If null would be specified - this value won't be used in search
schema - Database Schema. If null would be specified - this value won't be used in search
useCache - specifies if it should use cache for reading Stored Procedure/Function parameters
Returns:
CallResult which holds updated input and processed Query output (by OutputHandler)
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database

call

public <T,S> CallResults call(InputHandler<T> inputHandler,
                              OutputHandler<S> outputHandler)
                 throws java.sql.SQLException
Executes the given CALL SQL statement. Allows execution of Stored Procedures/Functions This function reads database metadata and identifies OUT fields. Output from OUT fields is merged with input and returned as function return. If function fails during reading database metadata please use QueryRunnerService.call(org.midao.jdbc.core.handlers.input.query.AbstractQueryInputHandler) as it is possible to specify Direction in QueryParameters class

Type Parameters:
T - The type of object that the input handler clones, updates and returns
S - The type of object that the output handler returns
Parameters:
inputHandler - Input Handler which would be executed
outputHandler - The handler used to create the result object from Query output
Returns:
CallResult which holds updated input and processed Query output (by OutputHandler)
Throws:
java.sql.SQLException - if exception would be thrown by Driver/Database


Copyright © 2013. All Rights Reserved.