public ResultSet executeQuery(String query) {
return session.call(query)
}
public List<Record> findRecords(String name) {
String query = prepareQuery(name);
return mapResultToRecord(executeQuery(query));
}
public List<Record> mapResultToRecord(ResultSet rs) {
try {
List<Record> list = new ArrayList<>();
while(rs.hasNext()) {
list.add(new Record(rs.next()));
}
} catch (Exception e) {
logger.warn("exception while iterating over the recall set", e);
} finally {
try {
rs.close();
} catch (Exception ex) {
logger.warn("exception while closing the result set", ex);
}
}
}
在上面的代码中,ResultSet 被打开executeQuery
但被关闭mapResultToRecord
。那是关闭它的理想场所还是应该由该findRecords
功能承担责任?