Skip to content

Commit 9b776f9

Browse files
committed
cleanups in implementations of ScrollableResults
1 parent 4ab240a commit 9b776f9

File tree

4 files changed

+30
-48
lines changed

4 files changed

+30
-48
lines changed

hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public AbstractScrollableResults(
4444
this.persistenceContext = persistenceContext;
4545
}
4646

47-
4847
@Override
4948
public final R get() throws HibernateException {
5049
if ( closed ) {
@@ -90,21 +89,19 @@ public void setFetchSize(int fetchSize) {
9089

9190
@Override
9291
public final void close() {
93-
if ( this.closed ) {
94-
// noop if already closed
95-
return;
96-
}
92+
if ( !closed ) {
93+
rowReader.finishUp( rowProcessingState );
94+
jdbcValues.finishUp( persistenceContext );
9795

98-
rowReader.finishUp( rowProcessingState );
99-
jdbcValues.finishUp( persistenceContext );
96+
getPersistenceContext().getJdbcCoordinator().afterStatementExecution();
10097

101-
getPersistenceContext().getJdbcCoordinator().afterStatementExecution();
102-
103-
this.closed = true;
98+
closed = true;
99+
}
100+
// noop if already closed
104101
}
105102

106103
@Override
107104
public boolean isClosed() {
108-
return this.closed;
105+
return closed;
109106
}
110107
}

hibernate-core/src/main/java/org/hibernate/internal/EmptyScrollableResults.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@ public boolean isClosed() {
1919
return true;
2020
}
2121

22-
// @Override
23-
// public int getNumberOfTypes() {
24-
// return 0;
25-
// }
26-
2722
@Override
2823
public void close() {
29-
3024
}
3125

3226
@Override

hibernate-core/src/main/java/org/hibernate/internal/FetchingScrollableResultsImpl.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ else if ( beforeFirst ) {
7373
}
7474
}
7575

76-
boolean last = prepareCurrentRow();
76+
final boolean last = prepareCurrentRow();
7777

7878
beforeFirst = false;
7979
currentPosition++;
@@ -130,15 +130,12 @@ else if ( currentPosition == 1 ) {
130130
// we are interested in processing
131131
boolean firstPass = true;
132132
final EntityKey lastKey = getEntityKey();
133-
134133
while ( getRowProcessingState().previous() ) {
135-
EntityKey checkKey = getEntityKey();
136-
134+
final EntityKey checkKey = getEntityKey();
137135
if ( firstPass ) {
138136
firstPass = false;
139137
keyToRead = checkKey;
140138
}
141-
142139
if ( !lastKey.equals( checkKey ) ) {
143140
break;
144141
}
@@ -148,8 +145,7 @@ else if ( currentPosition == 1 ) {
148145
// Read backwards until we read past the first physical sequential
149146
// row with the key we are interested in loading
150147
while ( getRowProcessingState().previous() ) {
151-
EntityKey checkKey = getEntityKey();
152-
148+
final EntityKey checkKey = getEntityKey();
153149
if ( !keyToRead.equals( checkKey ) ) {
154150
break;
155151
}
@@ -223,7 +219,6 @@ public boolean last() {
223219
}
224220
}
225221
else {
226-
final RowProcessingStateStandardImpl rowProcessingState = getRowProcessingState();
227222
if ( isResultSetEmpty() || afterLast ) {
228223
// should not be able to reach last without maxPosition being set
229224
// unless there are no results
@@ -243,10 +238,8 @@ public boolean last() {
243238
@Override
244239
public boolean first() {
245240
beforeFirst();
246-
boolean more = next();
247-
241+
final boolean more = next();
248242
afterScrollOperation();
249-
250243
return more;
251244
}
252245

hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,32 +117,30 @@ public boolean setRowNumber(int rowNumber) throws HibernateException {
117117
}
118118

119119
private void prepareCurrentRow(boolean underlyingScrollSuccessful) {
120-
if ( !underlyingScrollSuccessful ) {
121-
currentRow = null;
122-
return;
123-
}
124-
125-
final PersistenceContext persistenceContext = getPersistenceContext().getPersistenceContext();
126-
final LoadContexts loadContexts = persistenceContext.getLoadContexts();
127-
loadContexts.register( getJdbcValuesSourceProcessingState() );
128-
persistenceContext.beforeLoad();
129-
try {
120+
if ( underlyingScrollSuccessful ) {
121+
final PersistenceContext persistenceContext = getPersistenceContext().getPersistenceContext();
122+
final LoadContexts loadContexts = persistenceContext.getLoadContexts();
123+
loadContexts.register( getJdbcValuesSourceProcessingState() );
124+
persistenceContext.beforeLoad();
130125
try {
131-
currentRow = getRowReader().readRow( getRowProcessingState() );
132-
133-
getRowProcessingState().finishRowProcessing( true );
134-
getJdbcValuesSourceProcessingState().finishUp( false );
126+
try {
127+
currentRow = getRowReader().readRow( getRowProcessingState() );
128+
getRowProcessingState().finishRowProcessing( true );
129+
getJdbcValuesSourceProcessingState().finishUp( false );
130+
}
131+
finally {
132+
persistenceContext.afterLoad();
133+
}
134+
persistenceContext.initializeNonLazyCollections();
135135
}
136136
finally {
137-
persistenceContext.afterLoad();
137+
loadContexts.deregister( getJdbcValuesSourceProcessingState() );
138138
}
139-
persistenceContext.initializeNonLazyCollections();
139+
afterScrollOperation();
140140
}
141-
finally {
142-
loadContexts.deregister( getJdbcValuesSourceProcessingState() );
141+
else {
142+
currentRow = null;
143143
}
144-
145-
afterScrollOperation();
146144
}
147145

148146
}

0 commit comments

Comments
 (0)