org.hibernate.jdbc
Class AbstractBatcher

java.lang.Object
  extended by org.hibernate.jdbc.AbstractBatcher
All Implemented Interfaces:
Batcher
Direct Known Subclasses:
BatchingBatcher, NonBatchingBatcher

public abstract class AbstractBatcher
extends Object
implements Batcher

Manages prepared statements and batching.

Author:
Gavin King

Field Summary
protected static org.slf4j.Logger log
           
 
Constructor Summary
AbstractBatcher(ConnectionManager connectionManager, Interceptor interceptor)
           
 
Method Summary
 void abortBatch(SQLException sqle)
          Must be called when an exception occurs
 void cancelLastQuery()
          Cancel the current query statement
 void closeConnection(Connection conn)
          Dispose of the JDBC connection
 void closeQueryStatement(PreparedStatement ps, ResultSet rs)
          Close a prepared statement opened with prepareQueryStatement()
 void closeStatement(PreparedStatement ps)
          Close a prepared or callable statement opened using prepareStatement() or prepareCallableStatement()
 void closeStatements()
          Actually releases the batcher, allowing it to cleanup internally held resources.
protected abstract  void doExecuteBatch(PreparedStatement ps)
           
 void executeBatch()
          Execute the batch
protected  SessionFactoryImplementor getFactory()
           
 ResultSet getResultSet(CallableStatement ps, Dialect dialect)
          Execute the statement and return the result set from a callable statement
 ResultSet getResultSet(PreparedStatement ps)
          Execute the statement and return the result set
protected  PreparedStatement getStatement()
           
 boolean hasOpenResources()
           
 Connection openConnection()
          Obtain a JDBC connection
 String openResourceStatsAsString()
           
 CallableStatement prepareBatchCallableStatement(String sql)
          Get a batchable callable statement to use for inserting / deleting / updating (might be called many times before a single call to executeBatch()).
 PreparedStatement prepareBatchStatement(String sql)
          Get a batchable prepared statement to use for inserting / deleting / updating (might be called many times before a single call to executeBatch()).
 CallableStatement prepareCallableQueryStatement(String sql, boolean scrollable, ScrollMode scrollMode)
          Get a prepared statement for use in loading / querying.
 CallableStatement prepareCallableStatement(String sql)
          Get a non-batchable callable statement to use for inserting / deleting / updating.
 PreparedStatement prepareQueryStatement(String sql, boolean scrollable, ScrollMode scrollMode)
          Get a prepared statement for use in loading / querying.
 PreparedStatement prepareSelectStatement(String sql)
          Get a non-batchable prepared statement to use for selecting.
 PreparedStatement prepareStatement(String sql)
          Get a non-batchable prepared statement to use for inserting / deleting / updating.
 PreparedStatement prepareStatement(String sql, boolean getGeneratedKeys)
          Get a non-batchable prepared statement to use for inserting / deleting / updating, using JDBC3 getGeneratedKeys (Connection.prepareStatement(String, int)).
 PreparedStatement prepareStatement(String sql, String[] columnNames)
          Get a non-batchable prepared statement to use for inserting / deleting / updating.
 void setTransactionTimeout(int seconds)
          Set the transaction timeout to seconds later than the current system time.
 void unsetTransactionTimeout()
          Unset the transaction timeout, called after the end of a transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.hibernate.jdbc.Batcher
addToBatch
 

Field Detail

log

protected static final org.slf4j.Logger log
Constructor Detail

AbstractBatcher

public AbstractBatcher(ConnectionManager connectionManager,
                       Interceptor interceptor)
Method Detail

setTransactionTimeout

public void setTransactionTimeout(int seconds)
Description copied from interface: Batcher
Set the transaction timeout to seconds later than the current system time.

Specified by:
setTransactionTimeout in interface Batcher

unsetTransactionTimeout

public void unsetTransactionTimeout()
Description copied from interface: Batcher
Unset the transaction timeout, called after the end of a transaction.

Specified by:
unsetTransactionTimeout in interface Batcher

getStatement

protected PreparedStatement getStatement()

prepareCallableStatement

public CallableStatement prepareCallableStatement(String sql)
                                           throws SQLException,
                                                  HibernateException
Description copied from interface: Batcher
Get a non-batchable callable statement to use for inserting / deleting / updating.

Must be explicitly released by Batcher.closeStatement(java.sql.PreparedStatement) after use.

Specified by:
prepareCallableStatement in interface Batcher
Throws:
SQLException
HibernateException

prepareStatement

public PreparedStatement prepareStatement(String sql)
                                   throws SQLException,
                                          HibernateException
Description copied from interface: Batcher
Get a non-batchable prepared statement to use for inserting / deleting / updating.

Must be explicitly released by Batcher.closeStatement(java.sql.PreparedStatement) after use.

Specified by:
prepareStatement in interface Batcher
Throws:
SQLException
HibernateException

prepareStatement

public PreparedStatement prepareStatement(String sql,
                                          boolean getGeneratedKeys)
                                   throws SQLException,
                                          HibernateException
Description copied from interface: Batcher
Get a non-batchable prepared statement to use for inserting / deleting / updating, using JDBC3 getGeneratedKeys (Connection.prepareStatement(String, int)).

Must be explicitly released by Batcher.closeStatement(java.sql.PreparedStatement) after use.

Specified by:
prepareStatement in interface Batcher
Throws:
SQLException
HibernateException

prepareStatement

public PreparedStatement prepareStatement(String sql,
                                          String[] columnNames)
                                   throws SQLException,
                                          HibernateException
Description copied from interface: Batcher
Get a non-batchable prepared statement to use for inserting / deleting / updating. using JDBC3 getGeneratedKeys (Connection.prepareStatement(String, String[])).

Must be explicitly released by Batcher.closeStatement(java.sql.PreparedStatement) after use.

Specified by:
prepareStatement in interface Batcher
Throws:
SQLException
HibernateException

prepareSelectStatement

public PreparedStatement prepareSelectStatement(String sql)
                                         throws SQLException,
                                                HibernateException
Description copied from interface: Batcher
Get a non-batchable prepared statement to use for selecting. Does not result in execution of the current batch.

Specified by:
prepareSelectStatement in interface Batcher
Throws:
SQLException
HibernateException

prepareQueryStatement

public PreparedStatement prepareQueryStatement(String sql,
                                               boolean scrollable,
                                               ScrollMode scrollMode)
                                        throws SQLException,
                                               HibernateException
Description copied from interface: Batcher
Get a prepared statement for use in loading / querying. If not explicitly released by closeQueryStatement(), it will be released when the session is closed or disconnected.

Specified by:
prepareQueryStatement in interface Batcher
Throws:
SQLException
HibernateException

prepareCallableQueryStatement

public CallableStatement prepareCallableQueryStatement(String sql,
                                                       boolean scrollable,
                                                       ScrollMode scrollMode)
                                                throws SQLException,
                                                       HibernateException
Description copied from interface: Batcher
Get a prepared statement for use in loading / querying. If not explicitly released by closeQueryStatement(), it will be released when the session is closed or disconnected.

Specified by:
prepareCallableQueryStatement in interface Batcher
Throws:
SQLException
HibernateException

abortBatch

public void abortBatch(SQLException sqle)
Description copied from interface: Batcher
Must be called when an exception occurs

Specified by:
abortBatch in interface Batcher
Parameters:
sqle - the (not null) exception that is the reason for aborting

getResultSet

public ResultSet getResultSet(PreparedStatement ps)
                       throws SQLException
Description copied from interface: Batcher
Execute the statement and return the result set

Specified by:
getResultSet in interface Batcher
Throws:
SQLException

getResultSet

public ResultSet getResultSet(CallableStatement ps,
                              Dialect dialect)
                       throws SQLException
Description copied from interface: Batcher
Execute the statement and return the result set from a callable statement

Specified by:
getResultSet in interface Batcher
Throws:
SQLException

closeQueryStatement

public void closeQueryStatement(PreparedStatement ps,
                                ResultSet rs)
                         throws SQLException
Description copied from interface: Batcher
Close a prepared statement opened with prepareQueryStatement()

Specified by:
closeQueryStatement in interface Batcher
Throws:
SQLException

prepareBatchStatement

public PreparedStatement prepareBatchStatement(String sql)
                                        throws SQLException,
                                               HibernateException
Description copied from interface: Batcher
Get a batchable prepared statement to use for inserting / deleting / updating (might be called many times before a single call to executeBatch()). After setting parameters, call addToBatch - do not execute the statement explicitly.

Specified by:
prepareBatchStatement in interface Batcher
Throws:
SQLException
HibernateException
See Also:
Batcher.addToBatch(org.hibernate.jdbc.Expectation)

prepareBatchCallableStatement

public CallableStatement prepareBatchCallableStatement(String sql)
                                                throws SQLException,
                                                       HibernateException
Description copied from interface: Batcher
Get a batchable callable statement to use for inserting / deleting / updating (might be called many times before a single call to executeBatch()). After setting parameters, call addToBatch - do not execute the statement explicitly.

Specified by:
prepareBatchCallableStatement in interface Batcher
Throws:
SQLException
HibernateException
See Also:
Batcher.addToBatch(org.hibernate.jdbc.Expectation)

executeBatch

public void executeBatch()
                  throws HibernateException
Description copied from interface: Batcher
Execute the batch

Specified by:
executeBatch in interface Batcher
Throws:
HibernateException

closeStatement

public void closeStatement(PreparedStatement ps)
                    throws SQLException
Description copied from interface: Batcher
Close a prepared or callable statement opened using prepareStatement() or prepareCallableStatement()

Specified by:
closeStatement in interface Batcher
Throws:
SQLException

closeStatements

public void closeStatements()
Actually releases the batcher, allowing it to cleanup internally held resources.

Specified by:
closeStatements in interface Batcher

doExecuteBatch

protected abstract void doExecuteBatch(PreparedStatement ps)
                                throws SQLException,
                                       HibernateException
Throws:
SQLException
HibernateException

getFactory

protected SessionFactoryImplementor getFactory()

openConnection

public Connection openConnection()
                          throws HibernateException
Description copied from interface: Batcher
Obtain a JDBC connection

Specified by:
openConnection in interface Batcher
Throws:
HibernateException

closeConnection

public void closeConnection(Connection conn)
                     throws HibernateException
Description copied from interface: Batcher
Dispose of the JDBC connection

Specified by:
closeConnection in interface Batcher
Throws:
HibernateException

cancelLastQuery

public void cancelLastQuery()
                     throws HibernateException
Description copied from interface: Batcher
Cancel the current query statement

Specified by:
cancelLastQuery in interface Batcher
Throws:
HibernateException

hasOpenResources

public boolean hasOpenResources()
Specified by:
hasOpenResources in interface Batcher

openResourceStatsAsString

public String openResourceStatsAsString()
Specified by:
openResourceStatsAsString in interface Batcher


Copyright © 2009 Hibernate.org. All Rights Reserved.