Skip to content

Commit

Permalink
cleanups in implementations of ScrollableResults
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Jan 17, 2025
1 parent a9ea918 commit ae3ca3f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public AbstractScrollableResults(
this.persistenceContext = persistenceContext;
}


@Override
public final R get() throws HibernateException {
if ( closed ) {
Expand Down Expand Up @@ -90,21 +89,19 @@ public void setFetchSize(int fetchSize) {

@Override
public final void close() {
if ( this.closed ) {
// noop if already closed
return;
}
if ( !closed ) {
rowReader.finishUp( rowProcessingState );
jdbcValues.finishUp( persistenceContext );

rowReader.finishUp( rowProcessingState );
jdbcValues.finishUp( persistenceContext );
getPersistenceContext().getJdbcCoordinator().afterStatementExecution();

getPersistenceContext().getJdbcCoordinator().afterStatementExecution();

this.closed = true;
closed = true;
}
// noop if already closed
}

@Override
public boolean isClosed() {
return this.closed;
return closed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ public boolean isClosed() {
return true;
}

// @Override
// public int getNumberOfTypes() {
// return 0;
// }

@Override
public void close() {

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ else if ( beforeFirst ) {
}
}

boolean last = prepareCurrentRow();
final boolean last = prepareCurrentRow();

beforeFirst = false;
currentPosition++;
Expand Down Expand Up @@ -130,15 +130,12 @@ else if ( currentPosition == 1 ) {
// we are interested in processing
boolean firstPass = true;
final EntityKey lastKey = getEntityKey();

while ( getRowProcessingState().previous() ) {
EntityKey checkKey = getEntityKey();

final EntityKey checkKey = getEntityKey();
if ( firstPass ) {
firstPass = false;
keyToRead = checkKey;
}

if ( !lastKey.equals( checkKey ) ) {
break;
}
Expand All @@ -148,8 +145,7 @@ else if ( currentPosition == 1 ) {
// Read backwards until we read past the first physical sequential
// row with the key we are interested in loading
while ( getRowProcessingState().previous() ) {
EntityKey checkKey = getEntityKey();

final EntityKey checkKey = getEntityKey();
if ( !keyToRead.equals( checkKey ) ) {
break;
}
Expand Down Expand Up @@ -223,7 +219,6 @@ public boolean last() {
}
}
else {
final RowProcessingStateStandardImpl rowProcessingState = getRowProcessingState();
if ( isResultSetEmpty() || afterLast ) {
// should not be able to reach last without maxPosition being set
// unless there are no results
Expand All @@ -243,10 +238,8 @@ public boolean last() {
@Override
public boolean first() {
beforeFirst();
boolean more = next();

final boolean more = next();
afterScrollOperation();

return more;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,32 +117,30 @@ public boolean setRowNumber(int rowNumber) throws HibernateException {
}

private void prepareCurrentRow(boolean underlyingScrollSuccessful) {
if ( !underlyingScrollSuccessful ) {
currentRow = null;
return;
}

final PersistenceContext persistenceContext = getPersistenceContext().getPersistenceContext();
final LoadContexts loadContexts = persistenceContext.getLoadContexts();
loadContexts.register( getJdbcValuesSourceProcessingState() );
persistenceContext.beforeLoad();
try {
if ( underlyingScrollSuccessful ) {
final PersistenceContext persistenceContext = getPersistenceContext().getPersistenceContext();
final LoadContexts loadContexts = persistenceContext.getLoadContexts();
loadContexts.register( getJdbcValuesSourceProcessingState() );
persistenceContext.beforeLoad();
try {
currentRow = getRowReader().readRow( getRowProcessingState() );

getRowProcessingState().finishRowProcessing( true );
getJdbcValuesSourceProcessingState().finishUp( false );
try {
currentRow = getRowReader().readRow( getRowProcessingState() );
getRowProcessingState().finishRowProcessing( true );
getJdbcValuesSourceProcessingState().finishUp( false );
}
finally {
persistenceContext.afterLoad();
}
persistenceContext.initializeNonLazyCollections();
}
finally {
persistenceContext.afterLoad();
loadContexts.deregister( getJdbcValuesSourceProcessingState() );
}
persistenceContext.initializeNonLazyCollections();
afterScrollOperation();
}
finally {
loadContexts.deregister( getJdbcValuesSourceProcessingState() );
else {
currentRow = null;
}

afterScrollOperation();
}

}

0 comments on commit ae3ca3f

Please sign in to comment.