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.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

View File

@ -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);
}

View File

@ -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());
}
}
}
}