com.googlecode.jdbw.impl
Class SQLExecutorImpl

java.lang.Object
  extended by com.googlecode.jdbw.impl.SQLExecutorImpl
All Implemented Interfaces:
SQLExecutor

public abstract class SQLExecutorImpl
extends Object
implements SQLExecutor

This class is an implementation of the SQLExecutor that provides most of the functionality required for sending queries and receiving data. This class does not deal with setting up and tearing down database connections; rather it expects the user to pass in a valid connection and close it when done.

Normally, you wouldn't use this class directly, but rather through classes such as the AutoExecutor or the DatabaseTransaction, which is using this class behind the scenes. You call methods on DatabaseConnection to get one of those.

Author:
Martin Berglund
See Also:
AutoExecutor, DatabaseTransaction, DatabaseConnection

Field Summary
protected  Connection connection
           
 
Constructor Summary
protected SQLExecutorImpl(Connection connection)
           
 
Method Summary
 void batchWrite(BatchUpdateHandler handler, List<String> batchedSQL)
          Executes a list of queries as one batch on the remote database server
 void batchWrite(BatchUpdateHandler handler, String SQL, List<Object[]> parameters)
          Executes a batch query where the SQL is structurally the same but parameters are different.
 void execute(ExecuteResultHandler handler, String SQL, Object... parameters)
          Sends a query to the database and handles any results through a callback interface
protected  void executeUpdate(Statement statement, String SQL)
           
protected  ResultSet getGeneratedKeys(Statement statement)
           
protected  PreparedStatement prepareBatchUpdateStatement(String SQL)
           
protected  PreparedStatement prepareExecuteStatement(String SQL)
           
protected  PreparedStatement prepareInsertStatement(String SQL)
           
protected  PreparedStatement prepareQueryStatement(String SQL)
           
protected  void setParameter(PreparedStatement statement, Object object, int i)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

protected final Connection connection
Constructor Detail

SQLExecutorImpl

protected SQLExecutorImpl(Connection connection)
Method Detail

execute

public void execute(ExecuteResultHandler handler,
                    String SQL,
                    Object... parameters)
             throws SQLException
Description copied from interface: SQLExecutor
Sends a query to the database and handles any results through a callback interface

Specified by:
execute in interface SQLExecutor
Parameters:
handler - Callback interface to use for any results of the query
SQL - SQL code to send to the database server, use ? for parameter substitution
parameters - List of parameters to insert into the query, must be one for every ? used
Throws:
SQLException

batchWrite

public void batchWrite(BatchUpdateHandler handler,
                       String SQL,
                       List<Object[]> parameters)
                throws SQLException
Description copied from interface: SQLExecutor
Executes a batch query where the SQL is structurally the same but parameters are different. Usefull for inserting, updating or deleting multiple rows from the same table.

Specified by:
batchWrite in interface SQLExecutor
Parameters:
handler - Callback interface to use for any results of the query
SQL - SQL to use for all queries, use ? for the parameter substitution
parameters - List of object arrays, where one array equals one query sent to the server
Throws:
SQLException

batchWrite

public void batchWrite(BatchUpdateHandler handler,
                       List<String> batchedSQL)
                throws SQLException
Description copied from interface: SQLExecutor
Executes a list of queries as one batch on the remote database server

Specified by:
batchWrite in interface SQLExecutor
Parameters:
handler - Callback interface to use for any results of the query
batchedSQL - List of SQL to send to the remote server
Throws:
SQLException

prepareQueryStatement

protected PreparedStatement prepareQueryStatement(String SQL)
                                           throws SQLException
Throws:
SQLException

prepareInsertStatement

protected PreparedStatement prepareInsertStatement(String SQL)
                                            throws SQLException
Throws:
SQLException

prepareBatchUpdateStatement

protected PreparedStatement prepareBatchUpdateStatement(String SQL)
                                                 throws SQLException
Throws:
SQLException

prepareExecuteStatement

protected PreparedStatement prepareExecuteStatement(String SQL)
                                             throws SQLException
Throws:
SQLException

executeUpdate

protected void executeUpdate(Statement statement,
                             String SQL)
                      throws SQLException
Throws:
SQLException

getGeneratedKeys

protected ResultSet getGeneratedKeys(Statement statement)
                              throws SQLException
Throws:
SQLException

setParameter

protected void setParameter(PreparedStatement statement,
                            Object object,
                            int i)
                     throws SQLException
Throws:
SQLException


Copyright © 2012. All Rights Reserved.