SOLR-8516, SOLR-8502: Implement ResultSetImpl.getStatement

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1725616 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joel Bernstein 2016-01-19 21:25:36 +00:00
parent 4d445b7235
commit cecb9f4e25
3 changed files with 18 additions and 9 deletions

View File

@ -39,29 +39,29 @@ import java.sql.Timestamp;
import java.util.Calendar; import java.util.Calendar;
import java.util.Map; 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.Tuple;
import org.apache.solr.client.solrj.io.stream.SolrStream;
class ResultSetImpl implements ResultSet { class ResultSetImpl implements ResultSet {
private final StatementImpl statement;
private SolrStream solrStream; private final SolrStream solrStream;
private Tuple tuple; private Tuple tuple;
private boolean done; private boolean done;
private boolean closed; private boolean closed;
ResultSetImpl(SolrStream solrStream) { ResultSetImpl(StatementImpl statement) {
this.solrStream = solrStream; this.statement = statement;
this.solrStream = statement.getSolrStream();
} }
@Override @Override
public boolean next() throws SQLException { public boolean next() throws SQLException {
try { try {
if(done) { if(done) {
return false; return false;
} }
tuple = solrStream.read(); tuple = this.solrStream.read();
if(tuple.EOF) { if(tuple.EOF) {
done = true; done = true;
return false; return false;
@ -640,7 +640,7 @@ class ResultSetImpl implements ResultSet {
@Override @Override
public Statement getStatement() throws SQLException { public Statement getStatement() throws SQLException {
throw new UnsupportedOperationException(); return this.statement;
} }
@Override @Override

View File

@ -50,6 +50,10 @@ class StatementImpl implements Statement {
this.connection = connection; this.connection = connection;
} }
public SolrStream getSolrStream() {
return this.solrStream;
}
@Override @Override
public ResultSet executeQuery(String sql) throws SQLException { public ResultSet executeQuery(String sql) throws SQLException {
try { try {
@ -59,7 +63,7 @@ class StatementImpl implements Statement {
context.setSolrClientCache(this.connection.getSolrClientCache()); context.setSolrClientCache(this.connection.getSolrClientCache());
this.solrStream.setStreamContext(context); this.solrStream.setStreamContext(context);
this.solrStream.open(); this.solrStream.open();
return new ResultSetImpl(this.solrStream); return new ResultSetImpl(this);
} catch(Exception e) { } catch(Exception e) {
throw new SQLException(e); throw new SQLException(e);
} }

View File

@ -309,6 +309,7 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
String collection = DEFAULT_COLLECTION; String collection = DEFAULT_COLLECTION;
String connectionString = "jdbc:solr://" + zkServer.getZkAddress() + "?collection=" + collection + String connectionString = "jdbc:solr://" + zkServer.getZkAddress() + "?collection=" + collection +
"&username=&password=&testKey1=testValue&testKey2"; "&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)) { try (Connection con = DriverManager.getConnection(connectionString)) {
assertEquals(collection, con.getCatalog()); assertEquals(collection, con.getCatalog());
@ -320,6 +321,10 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
try (Statement statement = con.createStatement()) { try (Statement statement = con.createStatement()) {
assertEquals(con, statement.getConnection()); assertEquals(con, statement.getConnection());
try (ResultSet rs = statement.executeQuery(sql)) {
assertEquals(statement, rs.getStatement());
}
} }
} }
} }