diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java index 6acdbc506ae1..4753c5427b13 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java @@ -44,7 +44,6 @@ public AbstractScrollableResults( this.persistenceContext = persistenceContext; } - @Override public final R get() throws HibernateException { if ( closed ) { @@ -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; } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/EmptyScrollableResults.java b/hibernate-core/src/main/java/org/hibernate/internal/EmptyScrollableResults.java index 7f164ed35658..085e8b99041e 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/EmptyScrollableResults.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/EmptyScrollableResults.java @@ -19,14 +19,8 @@ public boolean isClosed() { return true; } -// @Override -// public int getNumberOfTypes() { -// return 0; -// } - @Override public void close() { - } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/internal/FetchingScrollableResultsImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/FetchingScrollableResultsImpl.java index c72ad9e1269f..60c998324cbe 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/FetchingScrollableResultsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/FetchingScrollableResultsImpl.java @@ -73,7 +73,7 @@ else if ( beforeFirst ) { } } - boolean last = prepareCurrentRow(); + final boolean last = prepareCurrentRow(); beforeFirst = false; currentPosition++; @@ -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; } @@ -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; } @@ -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 @@ -243,10 +238,8 @@ public boolean last() { @Override public boolean first() { beforeFirst(); - boolean more = next(); - + final boolean more = next(); afterScrollOperation(); - return more; } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java index eb1285373af3..94030a34779d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java @@ -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(); } }