| Method from org.hibernate.jdbc.AbstractBatcher Detail: |
public void abortBatch(SQLException sqle) {
try {
if (batchUpdate!=null) closeStatement(batchUpdate);
}
catch (SQLException e) {
//noncritical, swallow and let the other propagate!
JDBCExceptionReporter.logExceptions(e);
}
finally {
batchUpdate=null;
batchUpdateSQL=null;
}
}
|
public void cancelLastQuery() throws HibernateException {
try {
if (lastQuery!=null) lastQuery.cancel();
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
factory.getSQLExceptionConverter(),
sqle,
"Cannot cancel query"
);
}
}
|
public void closeConnection(Connection conn) throws HibernateException {
if ( conn == null ) {
log.debug( "found null connection on AbstractBatcher#closeConnection" );
// EARLY EXIT!!!!
return;
}
if ( log.isDebugEnabled() ) {
log.debug( "closing JDBC connection" + preparedStatementCountsToString() + resultSetCountsToString() );
}
try {
if ( !conn.isClosed() ) {
JDBCExceptionReporter.logAndClearWarnings( conn );
}
factory.getConnectionProvider().closeConnection( conn );
}
catch ( SQLException sqle ) {
throw JDBCExceptionHelper.convert( factory.getSQLExceptionConverter(), sqle, "Cannot close connection" );
}
}
|
public void closeQueryStatement(PreparedStatement ps,
ResultSet rs) throws SQLException {
boolean psStillThere = statementsToClose.remove( ps );
try {
if ( rs != null ) {
if ( resultSetsToClose.remove( rs ) ) {
logCloseResults();
rs.close();
}
}
}
finally {
if ( psStillThere ) {
closeQueryStatement( ps );
}
}
}
|
public void closeStatement(PreparedStatement ps) throws SQLException {
logClosePreparedStatement();
closePreparedStatement(ps);
}
|
public void closeStatements() {
try {
releasing = true;
try {
if ( batchUpdate != null ) {
batchUpdate.close();
}
}
catch ( SQLException sqle ) {
//no big deal
log.warn( "Could not close a JDBC prepared statement", sqle );
}
batchUpdate = null;
batchUpdateSQL = null;
Iterator iter = resultSetsToClose.iterator();
while ( iter.hasNext() ) {
try {
logCloseResults();
( ( ResultSet ) iter.next() ).close();
}
catch ( SQLException e ) {
// no big deal
log.warn( "Could not close a JDBC result set", e );
}
catch ( ConcurrentModificationException e ) {
// this has been shown to happen occasionally in rare cases
// when using a transaction manager + transaction-timeout
// where the timeout calls back through Hibernate's
// registered transaction synchronization on a separate
// "reaping" thread. In cases where that reaping thread
// executes through this block at the same time the main
// application thread does we can get into situations where
// these CMEs occur. And though it is not "allowed" per-se,
// the end result without handling it specifically is infinite
// looping. So here, we simply break the loop
log.info( "encountered CME attempting to release batcher; assuming cause is tx-timeout scenario and ignoring" );
break;
}
catch ( Throwable e ) {
// sybase driver (jConnect) throwing NPE here in certain
// cases, but we'll just handle the general "unexpected" case
log.warn( "Could not close a JDBC result set", e );
}
}
resultSetsToClose.clear();
iter = statementsToClose.iterator();
while ( iter.hasNext() ) {
try {
closeQueryStatement( ( PreparedStatement ) iter.next() );
}
catch ( ConcurrentModificationException e ) {
// see explanation above...
log.info( "encountered CME attempting to release batcher; assuming cause is tx-timeout scenario and ignoring" );
break;
}
catch ( SQLException e ) {
// no big deal
log.warn( "Could not close a JDBC statement", e );
}
}
statementsToClose.clear();
}
finally {
releasing = false;
}
}
Actually releases the batcher, allowing it to cleanup internally held
resources. |
abstract protected void doExecuteBatch(PreparedStatement ps) throws HibernateException, SQLException
|
public void executeBatch() throws HibernateException {
if (batchUpdate!=null) {
try {
try {
doExecuteBatch(batchUpdate);
}
finally {
closeStatement(batchUpdate);
}
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
factory.getSQLExceptionConverter(),
sqle,
"Could not execute JDBC batch update",
batchUpdateSQL
);
}
finally {
batchUpdate=null;
batchUpdateSQL=null;
}
}
}
|
protected SessionFactoryImplementor getFactory() {
return factory;
}
|
public ResultSet getResultSet(PreparedStatement ps) throws SQLException {
ResultSet rs = ps.executeQuery();
resultSetsToClose.add(rs);
logOpenResults();
return rs;
}
|
public ResultSet getResultSet(CallableStatement ps,
Dialect dialect) throws SQLException {
ResultSet rs = dialect.getResultSet(ps);
resultSetsToClose.add(rs);
logOpenResults();
return rs;
}
|
protected PreparedStatement getStatement() {
return batchUpdate;
}
|
public boolean hasOpenResources() {
return resultSetsToClose.size() > 0 || statementsToClose.size() > 0;
}
|
public Connection openConnection() throws HibernateException {
log.debug("opening JDBC connection");
try {
return factory.getConnectionProvider().getConnection();
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
factory.getSQLExceptionConverter(),
sqle,
"Cannot open connection"
);
}
}
|
public String openResourceStatsAsString() {
return preparedStatementCountsToString() + resultSetCountsToString();
}
|
public CallableStatement prepareBatchCallableStatement(String sql) throws HibernateException, SQLException {
if ( !sql.equals(batchUpdateSQL) ) { // TODO: what if batchUpdate is a callablestatement ?
batchUpdate=prepareCallableStatement(sql); // calls executeBatch()
batchUpdateSQL=sql;
}
return (CallableStatement)batchUpdate;
}
|
public PreparedStatement prepareBatchStatement(String sql) throws HibernateException, SQLException {
sql = getSQL( sql );
if ( !sql.equals(batchUpdateSQL) ) {
batchUpdate=prepareStatement(sql); // calls executeBatch()
batchUpdateSQL=sql;
}
else {
log.debug("reusing prepared statement");
log(sql);
}
return batchUpdate;
}
|
public CallableStatement prepareCallableQueryStatement(String sql,
boolean scrollable,
ScrollMode scrollMode) throws HibernateException, SQLException {
logOpenPreparedStatement();
CallableStatement ps = ( CallableStatement ) getPreparedStatement(
connectionManager.getConnection(),
sql,
scrollable,
false,
null,
scrollMode,
true
);
setStatementFetchSize( ps );
statementsToClose.add( ps );
lastQuery = ps;
return ps;
}
|
public CallableStatement prepareCallableStatement(String sql) throws HibernateException, SQLException {
executeBatch();
logOpenPreparedStatement();
return getCallableStatement( connectionManager.getConnection(), sql, false);
}
|
public PreparedStatement prepareQueryStatement(String sql,
boolean scrollable,
ScrollMode scrollMode) throws HibernateException, SQLException {
logOpenPreparedStatement();
PreparedStatement ps = getPreparedStatement(
connectionManager.getConnection(),
sql,
scrollable,
scrollMode
);
setStatementFetchSize( ps );
statementsToClose.add( ps );
lastQuery = ps;
return ps;
}
|
public PreparedStatement prepareSelectStatement(String sql) throws HibernateException, SQLException {
logOpenPreparedStatement();
return getPreparedStatement(
connectionManager.getConnection(),
sql,
false,
false,
null,
null,
false
);
}
|
public PreparedStatement prepareStatement(String sql) throws HibernateException, SQLException {
return prepareStatement( sql, false );
}
|
public PreparedStatement prepareStatement(String sql,
boolean getGeneratedKeys) throws HibernateException, SQLException {
executeBatch();
logOpenPreparedStatement();
return getPreparedStatement(
connectionManager.getConnection(),
sql,
false,
getGeneratedKeys,
null,
null,
false
);
}
|
public PreparedStatement prepareStatement(String sql,
String[] columnNames) throws HibernateException, SQLException {
executeBatch();
logOpenPreparedStatement();
return getPreparedStatement(
connectionManager.getConnection(),
sql,
false,
false,
columnNames,
null,
false
);
}
|
public void setTransactionTimeout(int seconds) {
isTransactionTimeoutSet = true;
transactionTimeout = System.currentTimeMillis() / 1000 + seconds;
}
|
public void unsetTransactionTimeout() {
isTransactionTimeoutSet = false;
}
|