Skip to content

Commit 1e20a32

Browse files
committed
Polishing.
Tweak naming. Refine methods to static ones and collapse into a single method. See #1615
1 parent bc644aa commit 1e20a32

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/RowDocumentResultSetExtractor.java

+10-31
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,9 @@ private class RowDocumentIterator implements Iterator<RowDocument> {
155155
private final AggregateContext<ResultSet> aggregateContext;
156156

157157
/**
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.
161159
*/
162-
private boolean pointsAtRow;
160+
private boolean hasNext;
163161

164162
RowDocumentIterator(RelationalPersistentEntity<?> entity, ResultSet resultSet) throws SQLException {
165163

@@ -174,11 +172,10 @@ private class RowDocumentIterator implements Iterator<RowDocument> {
174172

175173
this.resultSet = resultSet;
176174
this.identifierIndex = columns.get(idColumn);
177-
178-
pointsAtRow = pointAtInitialRow();
175+
this.hasNext = hasRow(resultSet);
179176
}
180177

181-
private boolean pointAtInitialRow() throws SQLException {
178+
private static boolean hasRow(ResultSet resultSet) {
182179

183180
// If we are before the first row we need to advance to the first row.
184181
try {
@@ -202,13 +199,11 @@ private boolean pointAtInitialRow() throws SQLException {
202199
// maybe isBeforeFirst or isBeforeLast aren't implemented
203200
// or the ResultSet is empty.
204201

205-
206-
boolean peek = peek(resultSet);
207-
if (peek) {
202+
try {
203+
resultSet.getObject(1);
208204
// we can see actual data, so we are looking at a current row.
209205
return true;
210-
}
211-
206+
} catch (SQLException ignored) {}
212207

213208
try {
214209
return resultSet.next();
@@ -219,25 +214,9 @@ private boolean pointAtInitialRow() throws SQLException {
219214
}
220215
}
221216

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-
238217
@Override
239218
public boolean hasNext() {
240-
return pointsAtRow;
219+
return hasNext;
241220
}
242221

243222
@Override
@@ -257,8 +236,8 @@ public RowDocument next() {
257236
}
258237

259238
reader.accept(resultSet);
260-
pointsAtRow = resultSet.next();
261-
} while (pointsAtRow);
239+
hasNext = resultSet.next();
240+
} while (hasNext);
262241
} catch (SQLException e) {
263242
throw new DataRetrievalFailureException("Cannot advance ResultSet", e);
264243
}

0 commit comments

Comments
 (0)