org.elasticsearch.xpack.sql.jdbc.DefaultCursor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of galen Show documentation
Show all versions of galen Show documentation
A library for layout testing of websites
The newest version!
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.sql.jdbc;
import org.elasticsearch.xpack.sql.proto.core.Tuple;
import java.sql.SQLException;
import java.util.List;
class DefaultCursor implements Cursor {
private final JdbcHttpClient client;
private final RequestMeta meta;
private final List columnInfos;
private List> rows;
private final List warnings;
private int row = -1;
private String cursor;
DefaultCursor(
JdbcHttpClient client,
String cursor,
List columnInfos,
List> rows,
RequestMeta meta,
List warnings
) {
this.client = client;
this.meta = meta;
this.cursor = cursor;
this.columnInfos = columnInfos;
this.rows = rows;
this.warnings = warnings;
}
@Override
public List columns() {
return columnInfos;
}
@Override
public boolean next() throws SQLException {
if (row < rows.size() - 1) {
row++;
return true;
} else {
if (cursor.isEmpty() == false) {
Tuple>> nextPage = client.nextPage(cursor, meta);
cursor = nextPage.v1();
rows = nextPage.v2();
row = -1;
return next();
}
return false;
}
}
@Override
public Object column(int column) {
return rows.get(row).get(column);
}
@Override
public int batchSize() {
return rows.size();
}
@Override
public void close() throws SQLException {
if (cursor.isEmpty() == false) {
client.queryClose(cursor);
}
}
public List warnings() {
return warnings;
}
@Override
public void clearWarnings() {
warnings.clear();
}
}
© 2015 - 2026 Weber Informatics LLC | Privacy Policy