HHH-15779 Avoid stateful lambdas in hot processing of JdbcValuesResultSetImpl

This commit is contained in:
Sanne Grinovero 2022-11-29 12:35:19 +00:00 committed by Sanne Grinovero
parent a91e46a682
commit c7bd022b07
1 changed files with 57 additions and 92 deletions

View File

@ -82,58 +82,26 @@ public class JdbcValuesResultSetImpl extends AbstractJdbcValues {
@Override @Override
protected final boolean processNext(RowProcessingState rowProcessingState) { protected final boolean processNext(RowProcessingState rowProcessingState) {
return advance( return advance( advanceNext() );
() -> {
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().next() ) {
return false;
}
return true;
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (next) ResultSet position", e );
}
}
);
} }
@Override @Override
protected boolean processPrevious(RowProcessingState rowProcessingState) { protected boolean processPrevious(RowProcessingState rowProcessingState) {
return advance( return advance( advancePrevious() );
() -> {
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().previous() ) {
return false;
}
return true;
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (previous) ResultSet position", e );
}
}
);
} }
@Override @Override
protected boolean processScroll(int numberOfRows, RowProcessingState rowProcessingState) { protected boolean processScroll(int numberOfRows, RowProcessingState rowProcessingState) {
return advance( return advance( scrollRows( numberOfRows ) );
() -> { }
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().relative( numberOfRows ) ) {
return false;
}
return true; private boolean scrollRows(final int numberOfRows) {
} try {
catch (SQLException e) { return resultSetAccess.getResultSet().relative( numberOfRows );
throw makeExecutionException( "Error advancing (scroll) ResultSet position", e ); }
} catch (SQLException e) {
} throw makeExecutionException( "Error advancing (scroll) ResultSet position", e );
); }
} }
@Override @Override
@ -148,21 +116,16 @@ public class JdbcValuesResultSetImpl extends AbstractJdbcValues {
@Override @Override
protected boolean processPosition(int position, RowProcessingState rowProcessingState) { protected boolean processPosition(int position, RowProcessingState rowProcessingState) {
return advance( return advance( advanceToPosition( position ) );
() -> { }
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().absolute( position ) ) {
return false;
}
return true; private boolean advanceToPosition(final int position) {
} try {
catch (SQLException e) { return resultSetAccess.getResultSet().absolute( position );
throw makeExecutionException( "Error advancing (scroll) ResultSet position", e ); }
} catch (SQLException e) {
} throw makeExecutionException( "Error advancing (scroll) ResultSet position", e );
); }
} }
@Override @Override
@ -198,21 +161,7 @@ public class JdbcValuesResultSetImpl extends AbstractJdbcValues {
@Override @Override
public boolean first(RowProcessingState rowProcessingState) { public boolean first(RowProcessingState rowProcessingState) {
return advance( return advance( advanceToFirst() );
() -> {
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().first() ) {
return false;
}
return true;
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (first) ResultSet position", e );
}
}
);
} }
@Override @Override
@ -248,30 +197,46 @@ public class JdbcValuesResultSetImpl extends AbstractJdbcValues {
@Override @Override
public boolean last(RowProcessingState rowProcessingState) { public boolean last(RowProcessingState rowProcessingState) {
return advance( return advance( advanceToLast() );
() -> {
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().last() ) {
return false;
}
return true;
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (last) ResultSet position", e );
}
}
);
} }
@FunctionalInterface private boolean advanceNext() {
private interface Advancer { try {
boolean advance(); return resultSetAccess.getResultSet().next();
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (next) ResultSet position", e );
}
} }
private boolean advance(Advancer advancer) { private boolean advanceToLast() {
final boolean hasResult = advancer.advance(); try {
return resultSetAccess.getResultSet().last();
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (last) ResultSet position", e );
}
}
private boolean advanceToFirst() {
try {
return resultSetAccess.getResultSet().first();
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (first) ResultSet position", e );
}
}
private boolean advancePrevious() {
try {
return resultSetAccess.getResultSet().previous();
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (previous) ResultSet position", e );
}
}
private boolean advance(final boolean hasResult) {
if ( ! hasResult ) { if ( ! hasResult ) {
return false; return false;
} }