Top Description Fields Constructors Methods
org.hibernate.jdbc

public abstract Class AbstractBatcher

extends Object
implements Batcher
Class Inheritance
All Implemented Interfaces
org.hibernate.jdbc.Batcher
Known Direct Subclasses
org.hibernate.jdbc.BatchingBatcher, org.hibernate.jdbc.NonBatchingBatcher
Imports
java.sql.CallableStatement, .Connection, .PreparedStatement, .ResultSet, .SQLException, java.util.HashSet, .Iterator, .ConcurrentModificationException, org.slf4j.Logger, .LoggerFactory, org.hibernate.AssertionFailure, .HibernateException, .Interceptor, .ScrollMode, .TransactionException, org.hibernate.dialect.Dialect, org.hibernate.engine.SessionFactoryImplementor, org.hibernate.exception.JDBCExceptionHelper, org.hibernate.jdbc.util.FormatStyle, org.hibernate.util.JDBCExceptionReporter

Manages prepared statements and batching.
Author
Gavin King

Field Summary

Modifier and TypeField and Description
private PreparedStatement
private String
private final ConnectionManager
private final SessionFactoryImplementor
private static int
private static int
private final Interceptor
pack-priv boolean
private PreparedStatement
protected static final Logger
private int
private int
private boolean
private HashSet<E>
private HashSet<E>
private long

Constructor Summary

AccessConstructor and Description
public
AbstractBatcher(ConnectionManager connectionManager, Interceptor interceptor)

Method Summary

Modifier and TypeMethod and Description
public void
abortBatch(SQLException
the (not null) exception that is the reason for aborting
sqle
)

Implements org.hibernate.jdbc.Batcher.abortBatch.

Must be called when an exception occurs
public void
cancelLastQuery()

Implements org.hibernate.jdbc.Batcher.cancelLastQuery.

Cancel the current query statement
public void
closeConnection(Connection conn)

Implements org.hibernate.jdbc.Batcher.closeConnection.

Dispose of the JDBC connection
private void
public void
closeQueryStatement(PreparedStatement ps, ResultSet rs)

Implements org.hibernate.jdbc.Batcher.closeQueryStatement.

Close a prepared statement opened with prepareQueryStatement()
private void
public void
closeStatement(PreparedStatement ps)

Implements org.hibernate.jdbc.Batcher.closeStatement.

Close a prepared or callable statement opened using prepareStatement() or prepareCallableStatement()
public void
closeStatements()

Implements org.hibernate.jdbc.Batcher.closeStatements.

Actually releases the batcher, allowing it to cleanup internally held resources.
protected abstract void
public void
private CallableStatement
getCallableStatement(final Connection conn, String sql, boolean scrollable)

protected SessionFactoryImplementor
private PreparedStatement
getPreparedStatement(final Connection conn, final String sql, final boolean scrollable, final ScrollMode scrollMode)

private PreparedStatement
getPreparedStatement(final Connection conn, String sql, boolean scrollable, final boolean useGetGeneratedKeys, final String[] namedGeneratedKeys, final ScrollMode scrollMode, final boolean callable)

public ResultSet
getResultSet(PreparedStatement ps)

Implements org.hibernate.jdbc.Batcher.getResultSet.

Execute the statement and return the result set
public ResultSet
getResultSet(CallableStatement ps, Dialect dialect)

Implements org.hibernate.jdbc.Batcher.getResultSet.

Execute the statement and return the result set from a callable statement
private String
protected PreparedStatement
public boolean
private void
log(String sql)

private void
private void
private void
private void
public Connection
openConnection()

Implements org.hibernate.jdbc.Batcher.openConnection.

Obtain a JDBC connection
public String
public CallableStatement
prepareBatchCallableStatement(String sql)

Implements org.hibernate.jdbc.Batcher.prepareBatchCallableStatement.

Get a batchable callable statement to use for inserting / deleting / updating (might be called many times before a single call to executeBatch()).
public PreparedStatement
prepareBatchStatement(String sql)

Implements org.hibernate.jdbc.Batcher.prepareBatchStatement.

Get a batchable prepared statement to use for inserting / deleting / updating (might be called many times before a single call to executeBatch()).
public CallableStatement
prepareCallableQueryStatement(String sql, boolean scrollable, ScrollMode scrollMode)

Implements org.hibernate.jdbc.Batcher.prepareCallableQueryStatement.

Get a prepared statement for use in loading / querying.
public CallableStatement
prepareCallableStatement(String sql)

Implements org.hibernate.jdbc.Batcher.prepareCallableStatement.

Get a non-batchable callable statement to use for inserting / deleting / updating.
private String
public PreparedStatement
prepareQueryStatement(String sql, boolean scrollable, ScrollMode scrollMode)

Implements org.hibernate.jdbc.Batcher.prepareQueryStatement.

Get a prepared statement for use in loading / querying.
public PreparedStatement
prepareSelectStatement(String sql)

Implements org.hibernate.jdbc.Batcher.prepareSelectStatement.

Get a non-batchable prepared statement to use for selecting.
public PreparedStatement
prepareStatement(String sql)

Implements org.hibernate.jdbc.Batcher.prepareStatement.

Get a non-batchable prepared statement to use for inserting / deleting / updating.
public PreparedStatement
prepareStatement(String sql, boolean getGeneratedKeys)

Implements org.hibernate.jdbc.Batcher.prepareStatement.

Get a non-batchable prepared statement to use for inserting / deleting / updating, using JDBC3 getGeneratedKeys (Connection#prepareStatement(String, int)).
public PreparedStatement
prepareStatement(String sql, String[] columnNames)

Implements org.hibernate.jdbc.Batcher.prepareStatement.

Get a non-batchable prepared statement to use for inserting / deleting / updating.
private String
private void
private void
public void
setTransactionTimeout(int seconds)

Implements org.hibernate.jdbc.Batcher.setTransactionTimeout.

Set the transaction timeout to seconds later than the current system time.
public void
unsetTransactionTimeout()

Implements org.hibernate.jdbc.Batcher.unsetTransactionTimeout.

Unset the transaction timeout, called after the end of a transaction.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

batchUpdateback to summary
private PreparedStatement batchUpdate
batchUpdateSQLback to summary
private String batchUpdateSQL
connectionManagerback to summary
private final ConnectionManager connectionManager
factoryback to summary
private final SessionFactoryImplementor factory
globalOpenPreparedStatementCountback to summary
private static int globalOpenPreparedStatementCount
globalOpenResultSetCountback to summary
private static int globalOpenResultSetCount
interceptorback to summary
private final Interceptor interceptor
isTransactionTimeoutSetback to summary
pack-priv boolean isTransactionTimeoutSet
lastQueryback to summary
private PreparedStatement lastQuery
logback to summary
protected static final Logger log
openPreparedStatementCountback to summary
private int openPreparedStatementCount
openResultSetCountback to summary
private int openResultSetCount
releasingback to summary
private boolean releasing
resultSetsToCloseback to summary
private HashSet<E> resultSetsToClose
statementsToCloseback to summary
private HashSet<E> statementsToClose
transactionTimeoutback to summary
private long transactionTimeout

Constructor Detail

AbstractBatcherback to summary
public AbstractBatcher(ConnectionManager connectionManager, Interceptor interceptor)

Method Detail

abortBatchback to summary
public void abortBatch(SQLException sqle)

Implements org.hibernate.jdbc.Batcher.abortBatch.

Doc from org.hibernate.jdbc.Batcher.abortBatch.

Must be called when an exception occurs

Parameters
sqle:SQLException

the (not null) exception that is the reason for aborting

cancelLastQueryback to summary
public void cancelLastQuery() throws HibernateException

Implements org.hibernate.jdbc.Batcher.cancelLastQuery.

Doc from org.hibernate.jdbc.Batcher.cancelLastQuery.

Cancel the current query statement

closeConnectionback to summary
public void closeConnection(Connection conn) throws HibernateException

Implements org.hibernate.jdbc.Batcher.closeConnection.

Doc from org.hibernate.jdbc.Batcher.closeConnection.

Dispose of the JDBC connection

closePreparedStatementback to summary
private void closePreparedStatement(PreparedStatement ps) throws SQLException
closeQueryStatementback to summary
public void closeQueryStatement(PreparedStatement ps, ResultSet rs) throws SQLException

Implements org.hibernate.jdbc.Batcher.closeQueryStatement.

Doc from org.hibernate.jdbc.Batcher.closeQueryStatement.

Close a prepared statement opened with prepareQueryStatement()

closeQueryStatementback to summary
private void closeQueryStatement(PreparedStatement ps) throws SQLException
closeStatementback to summary
public void closeStatement(PreparedStatement ps) throws SQLException

Implements org.hibernate.jdbc.Batcher.closeStatement.

Doc from org.hibernate.jdbc.Batcher.closeStatement.

Close a prepared or callable statement opened using prepareStatement() or prepareCallableStatement()

closeStatementsback to summary
public void closeStatements()

Implements org.hibernate.jdbc.Batcher.closeStatements.

Actually releases the batcher, allowing it to cleanup internally held resources.

doExecuteBatchback to summary
protected abstract void doExecuteBatch(PreparedStatement ps) throws SQLException, HibernateException
executeBatchback to summary
public void executeBatch() throws HibernateException

Implements org.hibernate.jdbc.Batcher.executeBatch.

Doc from org.hibernate.jdbc.Batcher.executeBatch.

Execute the batch

getCallableStatementback to summary
private CallableStatement getCallableStatement(final Connection conn, String sql, boolean scrollable) throws SQLException
getFactoryback to summary
protected SessionFactoryImplementor getFactory()
getPreparedStatementback to summary
private PreparedStatement getPreparedStatement(final Connection conn, final String sql, final boolean scrollable, final ScrollMode scrollMode) throws SQLException
getPreparedStatementback to summary
private PreparedStatement getPreparedStatement(final Connection conn, String sql, boolean scrollable, final boolean useGetGeneratedKeys, final String[] namedGeneratedKeys, final ScrollMode scrollMode, final boolean callable) throws SQLException
getResultSetback to summary
public ResultSet getResultSet(PreparedStatement ps) throws SQLException

Implements org.hibernate.jdbc.Batcher.getResultSet.

Doc from org.hibernate.jdbc.Batcher.getResultSet.

Execute the statement and return the result set

getResultSetback to summary
public ResultSet getResultSet(CallableStatement ps, Dialect dialect) throws SQLException

Implements org.hibernate.jdbc.Batcher.getResultSet.

Doc from org.hibernate.jdbc.Batcher.getResultSet.

Execute the statement and return the result set from a callable statement

getSQLback to summary
private String getSQL(String sql)
getStatementback to summary
protected PreparedStatement getStatement()
hasOpenResourcesback to summary
public boolean hasOpenResources()

Implements org.hibernate.jdbc.Batcher.hasOpenResources.

logback to summary
private void log(String sql)
logClosePreparedStatementback to summary
private void logClosePreparedStatement()
logCloseResultsback to summary
private void logCloseResults()
logOpenPreparedStatementback to summary
private void logOpenPreparedStatement()
logOpenResultsback to summary
private void logOpenResults()
openConnectionback to summary
public Connection openConnection() throws HibernateException

Implements org.hibernate.jdbc.Batcher.openConnection.

Doc from org.hibernate.jdbc.Batcher.openConnection.

Obtain a JDBC connection

openResourceStatsAsStringback to summary
public String openResourceStatsAsString()

Implements org.hibernate.jdbc.Batcher.openResourceStatsAsString.

prepareBatchCallableStatementback to summary
public CallableStatement prepareBatchCallableStatement(String sql) throws SQLException, HibernateException

Implements org.hibernate.jdbc.Batcher.prepareBatchCallableStatement.

Doc from org.hibernate.jdbc.Batcher.prepareBatchCallableStatement.

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.

prepareBatchStatementback to summary
public PreparedStatement prepareBatchStatement(String sql) throws SQLException, HibernateException

Implements org.hibernate.jdbc.Batcher.prepareBatchStatement.

Doc from org.hibernate.jdbc.Batcher.prepareBatchStatement.

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.

prepareCallableQueryStatementback to summary
public CallableStatement prepareCallableQueryStatement(String sql, boolean scrollable, ScrollMode scrollMode) throws SQLException, HibernateException

Implements org.hibernate.jdbc.Batcher.prepareCallableQueryStatement.

Doc from org.hibernate.jdbc.Batcher.prepareCallableQueryStatement.

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.

prepareCallableStatementback to summary
public CallableStatement prepareCallableStatement(String sql) throws SQLException, HibernateException

Implements org.hibernate.jdbc.Batcher.prepareCallableStatement.

Doc from org.hibernate.jdbc.Batcher.prepareCallableStatement.

Get a non-batchable callable statement to use for inserting / deleting / updating.

Must be explicitly released by closeStatement after use.

preparedStatementCountsToStringback to summary
private String preparedStatementCountsToString()
prepareQueryStatementback to summary
public PreparedStatement prepareQueryStatement(String sql, boolean scrollable, ScrollMode scrollMode) throws SQLException, HibernateException

Implements org.hibernate.jdbc.Batcher.prepareQueryStatement.

Doc from org.hibernate.jdbc.Batcher.prepareQueryStatement.

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.

prepareSelectStatementback to summary
public PreparedStatement prepareSelectStatement(String sql) throws SQLException, HibernateException

Implements org.hibernate.jdbc.Batcher.prepareSelectStatement.

Doc from org.hibernate.jdbc.Batcher.prepareSelectStatement.

Get a non-batchable prepared statement to use for selecting. Does not result in execution of the current batch.

prepareStatementback to summary
public PreparedStatement prepareStatement(String sql) throws SQLException, HibernateException

Implements org.hibernate.jdbc.Batcher.prepareStatement.

Doc from org.hibernate.jdbc.Batcher.prepareStatement.

Get a non-batchable prepared statement to use for inserting / deleting / updating.

Must be explicitly released by closeStatement after use.

prepareStatementback to summary
public PreparedStatement prepareStatement(String sql, boolean getGeneratedKeys) throws SQLException, HibernateException

Implements org.hibernate.jdbc.Batcher.prepareStatement.

Doc from org.hibernate.jdbc.Batcher.prepareStatement.

Get a non-batchable prepared statement to use for inserting / deleting / updating, using JDBC3 getGeneratedKeys (Connection#prepareStatement(String, int)).

Must be explicitly released by closeStatement after use.

prepareStatementback to summary
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException, HibernateException

Implements org.hibernate.jdbc.Batcher.prepareStatement.

Doc from org.hibernate.jdbc.Batcher.prepareStatement.

Get a non-batchable prepared statement to use for inserting / deleting / updating. using JDBC3 getGeneratedKeys (Connection#prepareStatement(String, String[])).

Must be explicitly released by closeStatement after use.

resultSetCountsToStringback to summary
private String resultSetCountsToString()
setStatementFetchSizeback to summary
private void setStatementFetchSize(PreparedStatement statement) throws SQLException
setTimeoutback to summary
private void setTimeout(PreparedStatement result) throws SQLException
setTransactionTimeoutback to summary
public void setTransactionTimeout(int seconds)

Implements org.hibernate.jdbc.Batcher.setTransactionTimeout.

Doc from org.hibernate.jdbc.Batcher.setTransactionTimeout.

Set the transaction timeout to seconds later than the current system time.

unsetTransactionTimeoutback to summary
public void unsetTransactionTimeout()

Implements org.hibernate.jdbc.Batcher.unsetTransactionTimeout.

Doc from org.hibernate.jdbc.Batcher.unsetTransactionTimeout.

Unset the transaction timeout, called after the end of a transaction.