Skip to content

Commit 1198815

Browse files
committed
cleanups in implementations of ScrollableResults
1 parent b9d79d9 commit 1198815

File tree

7 files changed

+44
-167
lines changed

7 files changed

+44
-167
lines changed

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

Lines changed: 8 additions & 13 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 ) {
@@ -85,26 +84,22 @@ protected void afterScrollOperation() {
8584

8685
@Override
8786
public void setFetchSize(int fetchSize) {
88-
getJdbcValues().setFetchSize(fetchSize);
87+
getJdbcValues().setFetchSize( fetchSize );
8988
}
9089

9190
@Override
9291
public final void close() {
93-
if ( this.closed ) {
94-
// noop if already closed
95-
return;
92+
if ( !closed ) {
93+
rowReader.finishUp( rowProcessingState );
94+
jdbcValues.finishUp( persistenceContext );
95+
getPersistenceContext().getJdbcCoordinator().afterStatementExecution();
96+
closed = true;
9697
}
97-
98-
rowReader.finishUp( rowProcessingState );
99-
jdbcValues.finishUp( persistenceContext );
100-
101-
getPersistenceContext().getJdbcCoordinator().afterStatementExecution();
102-
103-
this.closed = true;
98+
// noop if already closed
10499
}
105100

106101
@Override
107102
public boolean isClosed() {
108-
return this.closed;
103+
return closed;
109104
}
110105
}

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

Lines changed: 11 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,28 @@
44
*/
55
package org.hibernate.internal;
66

7-
import org.hibernate.internal.util.collections.ArrayHelper;
87
import org.hibernate.query.spi.ScrollableResultsImplementor;
98

109
/**
1110
* @author Andrea Boriero
1211
*/
13-
public class EmptyScrollableResults implements ScrollableResultsImplementor {
12+
public class EmptyScrollableResults<R> implements ScrollableResultsImplementor<R> {
1413

15-
public static final ScrollableResultsImplementor INSTANCE = new EmptyScrollableResults();
14+
@SuppressWarnings("rawtypes")
15+
private static final ScrollableResultsImplementor INSTANCE = new EmptyScrollableResults();
16+
17+
@SuppressWarnings("unchecked")
18+
public static <R> EmptyScrollableResults<R> instance() {
19+
return (EmptyScrollableResults<R>) INSTANCE;
20+
}
1621

1722
@Override
1823
public boolean isClosed() {
1924
return true;
2025
}
2126

22-
// @Override
23-
// public int getNumberOfTypes() {
24-
// return 0;
25-
// }
26-
2727
@Override
2828
public void close() {
29-
3029
}
3130

3231
@Override
@@ -61,12 +60,10 @@ public boolean first() {
6160

6261
@Override
6362
public void beforeFirst() {
64-
6563
}
6664

6765
@Override
6866
public void afterLast() {
69-
7067
}
7168

7269
@Override
@@ -93,112 +90,7 @@ public boolean setRowNumber(int rowNumber) {
9390
public void setFetchSize(int fetchSize) {}
9491

9592
@Override
96-
public Object[] get() {
97-
return ArrayHelper.EMPTY_OBJECT_ARRAY;
98-
}
99-
100-
// @Override
101-
// public Object get(int i) {
102-
// return null;
103-
// }
104-
//
105-
// @Override
106-
// public Type getType(int i) {
107-
// return null;
108-
// }
109-
//
110-
// @Override
111-
// public Integer getInteger(int col) {
112-
// return null;
113-
// }
114-
//
115-
// @Override
116-
// public Long getLong(int col) {
117-
// return null;
118-
// }
119-
//
120-
// @Override
121-
// public Float getFloat(int col) {
122-
// return null;
123-
// }
124-
//
125-
// @Override
126-
// public Boolean getBoolean(int col) {
127-
// return null;
128-
// }
129-
//
130-
// @Override
131-
// public Double getDouble(int col) {
132-
// return null;
133-
// }
134-
//
135-
// @Override
136-
// public Short getShort(int col) {
137-
// return null;
138-
// }
139-
//
140-
// @Override
141-
// public Byte getByte(int col) {
142-
// return null;
143-
// }
144-
//
145-
// @Override
146-
// public Character getCharacter(int col) {
147-
// return null;
148-
// }
149-
//
150-
// @Override
151-
// public byte[] getBinary(int col) {
152-
// return new byte[0];
153-
// }
154-
//
155-
// @Override
156-
// public String getText(int col) {
157-
// return null;
158-
// }
159-
//
160-
// @Override
161-
// public Blob getBlob(int col) {
162-
// return null;
163-
// }
164-
//
165-
// @Override
166-
// public Clob getClob(int col) {
167-
// return null;
168-
// }
169-
//
170-
// @Override
171-
// public String getString(int col) {
172-
// return null;
173-
// }
174-
//
175-
// @Override
176-
// public BigDecimal getBigDecimal(int col) {
177-
// return null;
178-
// }
179-
//
180-
// @Override
181-
// public BigInteger getBigInteger(int col) {
182-
// return null;
183-
// }
184-
//
185-
// @Override
186-
// public Date getDate(int col) {
187-
// return null;
188-
// }
189-
//
190-
// @Override
191-
// public Locale getLocale(int col) {
192-
// return null;
193-
// }
194-
//
195-
// @Override
196-
// public Calendar getCalendar(int col) {
197-
// return null;
198-
// }
199-
//
200-
// @Override
201-
// public TimeZone getTimeZone(int col) {
202-
// return null;
203-
// }
93+
public R get() {
94+
throw new UnsupportedOperationException( "Empty result set" );
95+
}
20496
}

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
}

hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeSelectQueryPlanImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ public List<R> performList(DomainQueryExecutionContext executionContext) {
144144
@Override
145145
public ScrollableResultsImplementor<R> performScroll(ScrollMode scrollMode, DomainQueryExecutionContext executionContext) {
146146
if ( executionContext.getQueryOptions().getEffectiveLimit().getMaxRowsJpa() == 0 ) {
147-
//noinspection unchecked
148-
return EmptyScrollableResults.INSTANCE;
147+
return EmptyScrollableResults.instance();
149148
}
150149
final List<JdbcParameterBinder> jdbcParameterBinders;
151150
final JdbcParameterBindings jdbcParameterBindings;

hibernate-core/src/main/java/org/hibernate/query/sqm/internal/AggregatedSelectQueryPlanImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ else if ( elementsToSkip > 0 ) {
7676
@Override
7777
public ScrollableResultsImplementor<R> performScroll(ScrollMode scrollMode, DomainQueryExecutionContext executionContext) {
7878
if ( executionContext.getQueryOptions().getEffectiveLimit().getMaxRowsJpa() == 0 ) {
79-
return EmptyScrollableResults.INSTANCE;
79+
return EmptyScrollableResults.instance();
8080
}
8181
throw new UnsupportedOperationException();
8282
}

hibernate-core/src/main/java/org/hibernate/query/sqm/internal/ConcreteSqmSelectQueryPlan.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public List<R> performList(DomainQueryExecutionContext executionContext) {
371371
@Override
372372
public ScrollableResultsImplementor<R> performScroll(ScrollMode scrollMode, DomainQueryExecutionContext executionContext) {
373373
if ( executionContext.getQueryOptions().getEffectiveLimit().getMaxRowsJpa() == 0 ) {
374-
return EmptyScrollableResults.INSTANCE;
374+
return EmptyScrollableResults.instance();
375375
}
376376
return withCacheableSqmInterpretation( executionContext, scrollMode, scrollInterpreter );
377377
}

0 commit comments

Comments
 (0)