SOLR-8652: Implement Statement.setMaxRows()

This commit is contained in:
jbernste 2016-02-06 21:03:45 -05:00
parent dc6b1a68d2
commit ba20faa955
2 changed files with 10 additions and 4 deletions

View File

@ -45,6 +45,7 @@ class StatementImpl implements Statement {
private String currentSQL;
private ResultSetImpl currentResultSet;
private SQLWarning currentWarning;
private int maxRows;
StatementImpl(ConnectionImpl connection) {
this.connection = connection;
@ -58,6 +59,10 @@ class StatementImpl implements Statement {
this.currentResultSet = null;
}
if(maxRows > 0 && !(sql.toLowerCase()).contains("limit")) {
sql = sql + " limit "+Integer.toString(maxRows);
}
closed = false; // If closed reopen so Statement can be reused.
this.currentResultSet = new ResultSetImpl(this, constructStream(sql));
return this.currentResultSet;
@ -132,12 +137,12 @@ class StatementImpl implements Statement {
@Override
public int getMaxRows() throws SQLException {
throw new UnsupportedOperationException();
return this.maxRows;
}
@Override
public void setMaxRows(int max) throws SQLException {
throw new UnsupportedOperationException();
this.maxRows = max;
}
@Override

View File

@ -166,7 +166,8 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
stmt.close();
//Test statement reuse
rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i asc limit 2");
stmt.setMaxRows(2);
rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i asc");
assert(rs.next());
assert(rs.getLong("a_i") == 0);
assert(rs.getLong(2) == 0);
@ -176,7 +177,7 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
assert(!rs.next());
stmt.close();
//Test simple loop
//Test simple loop. Since limit is set it will override the statement maxRows
rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i asc limit 100");
int count = 0;
while(rs.next()) {