in hugegraph-loader/src/main/java/org/apache/hugegraph/loader/reader/jdbc/RowFetcher.java [126:170]
public List<Line> nextBatch() throws SQLException {
if (this.fullyFetched) {
return null;
}
String select = this.source.existsCustomSQL() ?
this.source.customSQL() :
this.source.vendor().buildSelectSql(this.source, this.nextStartRow);
LOG.debug("The sql for select is: {}", select);
List<Line> batch = new ArrayList<>(this.source.batchSize() + 1);
try (Statement stmt = this.conn.createStatement();
ResultSet result = stmt.executeQuery(select)) {
if (this.source.existsCustomSQL()) {
this.readHeader(result);
}
while (result.next()) {
Object[] values = new Object[this.columns.length];
for (int i = 1, n = this.columns.length; i <= n; i++) {
Object value = result.getObject(i);
if (value == null) {
value = Constants.NULL_STR;
}
values[i - 1] = value;
}
String rawLine = StringUtils.join(values, Constants.COMMA_STR);
Line line = new Line(rawLine, this.columns, values);
batch.add(line);
}
} catch (SQLException e) {
this.close();
throw e;
}
if (this.source.existsCustomSQL() || batch.size() != this.source.batchSize() + 1) {
this.fullyFetched = true;
} else {
// Remove the last one
Line lastLine = batch.remove(batch.size() - 1);
lastLine.retainAll(this.primaryKeys);
this.nextStartRow = lastLine;
}
return batch;
}