com.jenkov.mrpersister.itf
Interface IPreparedStatementManager

All Known Implementing Classes:
PreparedStatementManagerBase

public interface IPreparedStatementManager

Represents a manager capable of preparing, initializing parameters of, executing and post processing a PreparedStatement.

In most cases you can just extend the PreparedStatementManagerBase which has default implementations for all four methods. Then you just override the methods you need. Typically it will be the init method.

Author:
Jakob Jenkov - Copyright 2005 Jenkov Development

Method Summary
 java.lang.Object execute(java.sql.PreparedStatement statement)
          Executes the PreparedStatement.
 void init(java.sql.PreparedStatement statement)
          Initializes the PreparedStatement.
 void postProcess(java.sql.PreparedStatement statement)
          Post processes the PreparedStatement after execution.
 java.sql.PreparedStatement prepare(java.lang.String sql, java.sql.Connection connection)
          Returns a PreparedStatement prepared from the SQL and the connection.
 

Method Detail

prepare

java.sql.PreparedStatement prepare(java.lang.String sql,
                                   java.sql.Connection connection)
                                   throws java.sql.SQLException,
                                          PersistenceException
Returns a PreparedStatement prepared from the SQL and the connection. Implement this method if the default implementation in PreparedStatementManagerBase doesn't match your needs. For instance, if you need to call a different Connection.prepare(...) method.

Parameters:
sql - The SQL to prepare the PreparedStatement for.
connection - The connection to use to prepare the PreparedStatement.
Returns:
A PreparedStatement.
Throws:
java.sql.SQLException - If the preparation fails.
PersistenceException - If something else goes wrong during the prepare method.

init

void init(java.sql.PreparedStatement statement)
          throws java.sql.SQLException,
                 PersistenceException
Initializes the PreparedStatement. Typicially this means setting the correct parameters on the statement (setString(1, "value"), setLong(1, 45) etc.).

Parameters:
statement - The PreparedStatement to initialize.
Throws:
java.sql.SQLException - If the initialization fails in the JDBC driver.
PersistenceException - If something else goes wrong during initialization.

execute

java.lang.Object execute(java.sql.PreparedStatement statement)
                         throws java.sql.SQLException,
                                PersistenceException
Executes the PreparedStatement.

Parameters:
statement - The PreparedStatement to execute.
Returns:
The result of the execute() method. For instance a ResultSet.
Throws:
java.sql.SQLException - If the executing fails.
PersistenceException - If something else fails during execution.

postProcess

void postProcess(java.sql.PreparedStatement statement)
                 throws java.sql.SQLException,
                        PersistenceException
Post processes the PreparedStatement after execution. Typically post processing will be reading of generated id's. You do not need to close the PreparedStatement in this method.

Parameters:
statement - The PreparedStatement to post process.
Throws:
java.sql.SQLException - If post processing fails in the driver.
PersistenceException - If something else fails during post processing.