@@ -155,11 +155,9 @@ private class RowDocumentIterator implements Iterator<RowDocument> {
155
155
private final AggregateContext <ResultSet > aggregateContext ;
156
156
157
157
/**
158
- * Answers the question if the internal {@link ResultSet} points at an actual row. Since when not currently
159
- * extracting a document the {@link ResultSet} points at the next row to be read (or behind all rows), this is
160
- * equivalent to {@literal hasNext()} from the outside.
158
+ * Answers the question if the internal {@link ResultSet} points at an actual row.
161
159
*/
162
- private boolean pointsAtRow ;
160
+ private boolean hasNext ;
163
161
164
162
RowDocumentIterator (RelationalPersistentEntity <?> entity , ResultSet resultSet ) throws SQLException {
165
163
@@ -174,11 +172,10 @@ private class RowDocumentIterator implements Iterator<RowDocument> {
174
172
175
173
this .resultSet = resultSet ;
176
174
this .identifierIndex = columns .get (idColumn );
177
-
178
- pointsAtRow = pointAtInitialRow ();
175
+ this .hasNext = hasRow (resultSet );
179
176
}
180
177
181
- private boolean pointAtInitialRow () throws SQLException {
178
+ private static boolean hasRow ( ResultSet resultSet ) {
182
179
183
180
// If we are before the first row we need to advance to the first row.
184
181
try {
@@ -202,13 +199,11 @@ private boolean pointAtInitialRow() throws SQLException {
202
199
// maybe isBeforeFirst or isBeforeLast aren't implemented
203
200
// or the ResultSet is empty.
204
201
205
-
206
- boolean peek = peek (resultSet );
207
- if (peek ) {
202
+ try {
203
+ resultSet .getObject (1 );
208
204
// we can see actual data, so we are looking at a current row.
209
205
return true ;
210
- }
211
-
206
+ } catch (SQLException ignored ) {}
212
207
213
208
try {
214
209
return resultSet .next ();
@@ -219,25 +214,9 @@ private boolean pointAtInitialRow() throws SQLException {
219
214
}
220
215
}
221
216
222
- /**
223
- * Tries ot access values of the passed in {@link ResultSet} in order to check if it is pointing at an actual row.
224
- *
225
- * @param resultSet to check.
226
- * @return true if values of the {@literal ResultSet} can be accessed and it therefore points to an actual row.
227
- */
228
- private boolean peek (ResultSet resultSet ) {
229
-
230
- try {
231
- resultSet .getObject (1 );
232
- return true ;
233
- } catch (SQLException e ) {
234
- return false ;
235
- }
236
- }
237
-
238
217
@ Override
239
218
public boolean hasNext () {
240
- return pointsAtRow ;
219
+ return hasNext ;
241
220
}
242
221
243
222
@ Override
@@ -257,8 +236,8 @@ public RowDocument next() {
257
236
}
258
237
259
238
reader .accept (resultSet );
260
- pointsAtRow = resultSet .next ();
261
- } while (pointsAtRow );
239
+ hasNext = resultSet .next ();
240
+ } while (hasNext );
262
241
} catch (SQLException e ) {
263
242
throw new DataRetrievalFailureException ("Cannot advance ResultSet" , e );
264
243
}
0 commit comments