diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/StatementImpl.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/StatementImpl.java index 77cebfe6149..1927029c78b 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/StatementImpl.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/StatementImpl.java @@ -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 diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java index ba2111404d3..b3d7ae92fc1 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java @@ -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()) {