diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java index e0d00f04076..114a659fe57 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java @@ -39,29 +39,29 @@ import java.sql.Timestamp; import java.util.Calendar; import java.util.Map; -import org.apache.solr.client.solrj.io.stream.SolrStream; import org.apache.solr.client.solrj.io.Tuple; +import org.apache.solr.client.solrj.io.stream.SolrStream; class ResultSetImpl implements ResultSet { - - private SolrStream solrStream; + private final StatementImpl statement; + private final SolrStream solrStream; private Tuple tuple; private boolean done; private boolean closed; - ResultSetImpl(SolrStream solrStream) { - this.solrStream = solrStream; + ResultSetImpl(StatementImpl statement) { + this.statement = statement; + this.solrStream = statement.getSolrStream(); } @Override public boolean next() throws SQLException { try { - if(done) { return false; } - tuple = solrStream.read(); + tuple = this.solrStream.read(); if(tuple.EOF) { done = true; return false; @@ -640,7 +640,7 @@ class ResultSetImpl implements ResultSet { @Override public Statement getStatement() throws SQLException { - throw new UnsupportedOperationException(); + return this.statement; } @Override 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 a43f28a5be4..5d9acba9eb1 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 @@ -50,6 +50,10 @@ class StatementImpl implements Statement { this.connection = connection; } + public SolrStream getSolrStream() { + return this.solrStream; + } + @Override public ResultSet executeQuery(String sql) throws SQLException { try { @@ -59,7 +63,7 @@ class StatementImpl implements Statement { context.setSolrClientCache(this.connection.getSolrClientCache()); this.solrStream.setStreamContext(context); this.solrStream.open(); - return new ResultSetImpl(this.solrStream); + return new ResultSetImpl(this); } catch(Exception e) { throw new SQLException(e); } 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 6924729dfb1..98d32e9704f 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 @@ -309,6 +309,7 @@ public class JdbcTest extends AbstractFullDistribZkTestBase { String collection = DEFAULT_COLLECTION; String connectionString = "jdbc:solr://" + zkServer.getZkAddress() + "?collection=" + collection + "&username=&password=&testKey1=testValue&testKey2"; + String sql = "select id, a_i, a_s, a_f from " + collection + " order by a_i desc limit 2"; try (Connection con = DriverManager.getConnection(connectionString)) { assertEquals(collection, con.getCatalog()); @@ -320,6 +321,10 @@ public class JdbcTest extends AbstractFullDistribZkTestBase { try (Statement statement = con.createStatement()) { assertEquals(con, statement.getConnection()); + + try (ResultSet rs = statement.executeQuery(sql)) { + assertEquals(statement, rs.getStatement()); + } } } }