BatchingBatcherpublic class BatchingBatcher extends AbstractBatcher An implementation of the Batcher interface that
actually uses batching |
Fields Summary |
---|
private int | batchSize | private Expectation[] | expectations |
Constructors Summary |
---|
public BatchingBatcher(ConnectionManager connectionManager, org.hibernate.Interceptor interceptor)
super( connectionManager, interceptor );
expectations = new Expectation[ getFactory().getSettings().getJdbcBatchSize() ];
|
Methods Summary |
---|
public void | addToBatch(Expectation expectation)
if ( !expectation.canBeBatched() ) {
throw new HibernateException( "attempting to batch an operation which cannot be batched" );
}
PreparedStatement batchUpdate = getStatement();
batchUpdate.addBatch();
expectations[ batchSize++ ] = expectation;
if ( batchSize == getFactory().getSettings().getJdbcBatchSize() ) {
doExecuteBatch( batchUpdate );
}
| private void | checkRowCounts(int[] rowCounts, java.sql.PreparedStatement ps)
int numberOfRowCounts = rowCounts.length;
if ( numberOfRowCounts != batchSize ) {
log.warn( "JDBC driver did not return the expected number of row counts" );
}
for ( int i = 0; i < numberOfRowCounts; i++ ) {
expectations[i].verifyOutcome( rowCounts[i], ps, i );
}
| protected void | doExecuteBatch(java.sql.PreparedStatement ps)
if ( batchSize == 0 ) {
log.debug( "no batched statements to execute" );
}
else {
if ( log.isDebugEnabled() ) {
log.debug( "Executing batch size: " + batchSize );
}
try {
checkRowCounts( ps.executeBatch(), ps );
}
catch (RuntimeException re) {
log.error( "Exception executing batch: ", re );
throw re;
}
finally {
batchSize = 0;
}
}
|
|