HHH-15581 Extract skipRow and bindParameters from DeferredResultSetAccess

So that Hibernate Reactive can call them.
This commit is contained in:
Davide D'Alto 2022-09-30 18:05:05 +01:00 committed by Davide D'Alto
parent 2f45da6e35
commit af5ebb2a7f

View File

@ -169,15 +169,9 @@ public boolean usesFollowOnLocking() {
return usesFollowOnLocking;
}
private void executeQuery() {
final LogicalConnectionImplementor logicalConnection = getPersistenceContext().getJdbcCoordinator().getLogicalConnection();
protected void bindParameters(PreparedStatement preparedStatement) throws SQLException {
final QueryOptions queryOptions = executionContext.getQueryOptions();
try {
LOG.tracef( "Executing query to retrieve ResultSet : %s", finalSql );
// prepare the query
preparedStatement = statementCreator.apply( finalSql );
// set options
if ( queryOptions != null ) {
if ( queryOptions.getFetchSize() != null ) {
@ -212,6 +206,17 @@ private void executeQuery() {
preparedStatement.setMaxRows( maxRows );
}
}
}
private void executeQuery() {
final LogicalConnectionImplementor logicalConnection = getPersistenceContext().getJdbcCoordinator().getLogicalConnection();
try {
LOG.tracef( "Executing query to retrieve ResultSet : %s", finalSql );
// prepare the query
preparedStatement = statementCreator.apply( finalSql );
bindParameters( preparedStatement );
final SessionEventListenerManager eventListenerManager = executionContext.getSession()
.getEventListenerManager();
@ -229,6 +234,22 @@ private void executeQuery() {
sqlStatementLogger.logSlowQuery( preparedStatement, executeStartNanos );
}
skipRows( resultSet );
logicalConnection.getResourceRegistry().register( resultSet, preparedStatement );
}
catch (SQLException e) {
throw executionContext.getSession().getJdbcServices().getSqlExceptionHelper().convert(
e,
"JDBC exception executing SQL [" + finalSql + "]"
);
}
finally {
logicalConnection.afterStatement();
}
}
protected void skipRows(ResultSet resultSet) throws SQLException {
// For dialects that don't support an offset clause
final int rowsToSkip;
if ( !jdbcSelect.usesLimitParameters() && limit != null && limit.getFirstRow() != null && !limitHandler.supportsLimitOffset() ) {
@ -254,18 +275,6 @@ private void executeQuery() {
for (int i = 1; i < rowsToSkip && resultSet.next(); i++) {}
}
}
logicalConnection.getResourceRegistry().register( resultSet, preparedStatement );
}
catch (SQLException e) {
throw executionContext.getSession().getJdbcServices().getSqlExceptionHelper().convert(
e,
"JDBC exception executing SQL [" + finalSql + "]"
);
}
finally {
logicalConnection.afterStatement();
}
}
protected ResultSet wrapResultSet(ResultSet resultSet) throws SQLException {