Skip to content

Commit

Permalink
HHH-15779 Avoid stateful lambdas in hot processing of JdbcValuesResul…
Browse files Browse the repository at this point in the history
…tSetImpl
  • Loading branch information
Sanne committed Nov 29, 2022
1 parent a91e46a commit c7bd022
Showing 1 changed file with 59 additions and 94 deletions.
Expand Up @@ -82,58 +82,26 @@ private static QueryCachePutManager resolveQueryCachePutManager(

@Override
protected final boolean processNext(RowProcessingState rowProcessingState) {
return advance(
() -> {
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().next() ) {
return false;
}

return true;
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (next) ResultSet position", e );
}
}
);
return advance( advanceNext() );
}

@Override
protected boolean processPrevious(RowProcessingState rowProcessingState) {
return advance(
() -> {
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().previous() ) {
return false;
}
return true;
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (previous) ResultSet position", e );
}
}
);
return advance( advancePrevious() );
}

@Override
protected boolean processScroll(int numberOfRows, RowProcessingState rowProcessingState) {
return advance(
() -> {
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().relative( numberOfRows ) ) {
return false;
}

return true;
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (scroll) ResultSet position", e );
}
}
);
return advance( scrollRows( numberOfRows ) );
}

private boolean scrollRows(final int numberOfRows) {
try {
return resultSetAccess.getResultSet().relative( numberOfRows );
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (scroll) ResultSet position", e );
}
}

@Override
Expand All @@ -148,21 +116,16 @@ public int getPosition() {

@Override
protected boolean processPosition(int position, RowProcessingState rowProcessingState) {
return advance(
() -> {
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().absolute( position ) ) {
return false;
}

return true;
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (scroll) ResultSet position", e );
}
}
);
return advance( advanceToPosition( position ) );
}

private boolean advanceToPosition(final int position) {
try {
return resultSetAccess.getResultSet().absolute( position );
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (scroll) ResultSet position", e );
}
}

@Override
Expand Down Expand Up @@ -198,21 +161,7 @@ public boolean isFirst(RowProcessingState rowProcessingState) {

@Override
public boolean first(RowProcessingState rowProcessingState) {
return advance(
() -> {
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().first() ) {
return false;
}

return true;
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (first) ResultSet position", e );
}
}
);
return advance( advanceToFirst() );
}

@Override
Expand Down Expand Up @@ -248,30 +197,46 @@ public boolean isLast(RowProcessingState rowProcessingState) {

@Override
public boolean last(RowProcessingState rowProcessingState) {
return advance(
() -> {
try {
//noinspection RedundantIfStatement
if ( ! resultSetAccess.getResultSet().last() ) {
return false;
}

return true;
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (last) ResultSet position", e );
}
}
);
return advance( advanceToLast() );
}

private boolean advanceNext() {
try {
return resultSetAccess.getResultSet().next();
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (next) ResultSet position", e );
}
}

private boolean advanceToLast() {
try {
return resultSetAccess.getResultSet().last();
}
catch (SQLException e) {
throw makeExecutionException( "Error advancing (last) ResultSet position", e );
}
}

@FunctionalInterface
private interface Advancer {
boolean advance();
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(Advancer advancer) {
final boolean hasResult = advancer.advance();
private boolean advance(final boolean hasResult) {
if ( ! hasResult ) {
return false;
}
Expand Down

0 comments on commit c7bd022

Please sign in to comment.