//$Id: Batcher.java,v 1.4 2002/11/26 03:35:41 oneovthafew Exp $
package cirrus.hibernate.engine;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import cirrus.hibernate.HibernateException;
/**
* Manages <tt>PreparedStatement</tt>s for a session. Abstracts JDBC
* batching to maintain the illusion that a single logical batch
* exists for the whole session, even when batching is disabled.
* Provides transparent <tt>PreparedStatement</tt> caching.
* @see java.sql.PreparedStatement
* @see cirrus.hibernate.impl.SessionImpl
*/
public interface Batcher {
/**
* Get a prepared statement for use in loading / querying. If not explicitly
* released by <tt>closeQueryStatement()</tt>, it will be released when the
* session is closed or disconnected.
*/
public PreparedStatement prepareQueryStatement(String sql, boolean scrollable) throws SQLException, HibernateException;
/**
* Close a prepared statement opened with <tt>prepareQueryStatement()</tt>
*/
public void closeQueryStatement(PreparedStatement ps) throws SQLException;
/**
* Get a non-batchable prepared statement to use for inserting / deleting / updating.
* Must be explicitly released by <tt>closeStatement()</tt>
*/
public PreparedStatement prepareStatement(String sql) throws SQLException, HibernateException;
/**
* Close a prepared statement opened using <tt>prepareStatement()</tt>
*/
public void closeStatement(PreparedStatement ps) throws SQLException;
/**
* Get a batchable prepared statement to use for inserting / deleting / updating
* (might be called many times before a single call to <tt>executeBatch()</tt>).
* After setting parameters, call <tt>addToBatch</tt> - do not execute the
* statement explicitly.
* @see Batcher#addToBatch(int)
*/
public PreparedStatement prepareBatchStatement(String sql) throws SQLException, HibernateException;
/**
* Add an insert / delete / update to the current batch (might be called multiple times
* for single <tt>prepareBatchStatement()</tt>)
*/
public void addToBatch(int expectedRowCount) throws SQLException, HibernateException;
/**
* Execute the batch
*/
public void executeBatch() throws SQLException, HibernateException;
/**
* Close any query statements that were left lying around
*/
public void closeStatements();
}