mirror of https://github.com/apache/lucene.git
SOLR-9020: Implement StatementImpl/ResultSetImpl get/set fetch* methods and proper errors for traversal methods
This commit is contained in:
parent
b111bfda42
commit
d914ec4a67
|
@ -70,11 +70,13 @@ New Features
|
|||
|
||||
* SOLR-8349: Allow sharing of large in memory data structures across cores (Gus Heck, noble)
|
||||
|
||||
* SOLR-8809: Implement Connection.prepareStatement (Kevin Risden)
|
||||
|
||||
* SOLR-8913: When using a shared filesystem we should store data dir and tlog dir locations in
|
||||
the cluster state. (Mark Miller)
|
||||
|
||||
* SOLR-8809: Implement Connection.prepareStatement (Kevin Risden)
|
||||
|
||||
* SOLR-9020: Implement StatementImpl/ResultSetImpl get/set fetch* methods and proper errors for traversal methods (Kevin Risden)
|
||||
|
||||
Bug Fixes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.sql.ResultSet;
|
|||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.RowId;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.sql.SQLWarning;
|
||||
import java.sql.SQLXML;
|
||||
import java.sql.Statement;
|
||||
|
@ -480,92 +481,133 @@ class ResultSetImpl implements ResultSet {
|
|||
|
||||
@Override
|
||||
public boolean isBeforeFirst() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAfterLast() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFirst() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLast() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeFirst() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLException("beforeFirst() not supported on ResultSet with type TYPE_FORWARD_ONLY");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterLast() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLException("afterLast() not supported on ResultSet with type TYPE_FORWARD_ONLY");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean first() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLException("first() not supported on ResultSet with type TYPE_FORWARD_ONLY");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean last() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLException("last() not supported on ResultSet with type TYPE_FORWARD_ONLY");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRow() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLFeatureNotSupportedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean absolute(int row) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLException("absolute() not supported on ResultSet with type TYPE_FORWARD_ONLY");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean relative(int rows) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLException("relative() not supported on ResultSet with type TYPE_FORWARD_ONLY");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean previous() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
throw new SQLException("previous() not supported on ResultSet with type TYPE_FORWARD_ONLY");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFetchDirection(int direction) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
if(direction != ResultSet.FETCH_FORWARD) {
|
||||
throw new SQLException("Direction must be FETCH_FORWARD since ResultSet " +
|
||||
"type is TYPE_FORWARD_ONLY");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFetchDirection() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
return ResultSet.FETCH_FORWARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFetchSize(int rows) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
if(rows < 0) {
|
||||
throw new SQLException("Rows must be >= 0");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFetchSize() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() throws SQLException {
|
||||
checkClosed();
|
||||
|
||||
return ResultSet.TYPE_FORWARD_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConcurrency() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
return ResultSet.CONCUR_READ_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -51,6 +51,12 @@ class StatementImpl implements Statement {
|
|||
this.connection = connection;
|
||||
}
|
||||
|
||||
private void checkClosed() throws SQLException {
|
||||
if(isClosed()) {
|
||||
throw new SQLException("Statement is closed.");
|
||||
}
|
||||
}
|
||||
|
||||
private ResultSet executeQueryImpl(String sql) throws SQLException {
|
||||
try {
|
||||
if(this.currentResultSet != null) {
|
||||
|
@ -171,18 +177,14 @@ class StatementImpl implements Statement {
|
|||
|
||||
@Override
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
if(isClosed()) {
|
||||
throw new SQLException("Statement is closed.");
|
||||
}
|
||||
checkClosed();
|
||||
|
||||
return this.currentWarning;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWarnings() throws SQLException {
|
||||
if(isClosed()) {
|
||||
throw new SQLException("Statement is closed.");
|
||||
}
|
||||
checkClosed();
|
||||
|
||||
this.currentWarning = null;
|
||||
}
|
||||
|
@ -212,9 +214,7 @@ class StatementImpl implements Statement {
|
|||
|
||||
@Override
|
||||
public int getUpdateCount() throws SQLException {
|
||||
if(isClosed()) {
|
||||
throw new SQLException("Statement is closed");
|
||||
}
|
||||
checkClosed();
|
||||
|
||||
// TODO Add logic when update statements are added to JDBC.
|
||||
return -1;
|
||||
|
@ -222,9 +222,7 @@ class StatementImpl implements Statement {
|
|||
|
||||
@Override
|
||||
public boolean getMoreResults() throws SQLException {
|
||||
if(isClosed()) {
|
||||
throw new SQLException("Statement is closed");
|
||||
}
|
||||
checkClosed();
|
||||
|
||||
// Currently multiple result sets are not possible yet
|
||||
this.currentResultSet.close();
|
||||
|
@ -233,32 +231,48 @@ class StatementImpl implements Statement {
|
|||
|
||||
@Override
|
||||
public void setFetchDirection(int direction) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
if(direction != ResultSet.FETCH_FORWARD) {
|
||||
throw new SQLException("Direction must be ResultSet.FETCH_FORWARD currently");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFetchDirection() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
return ResultSet.FETCH_FORWARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFetchSize(int rows) throws SQLException {
|
||||
checkClosed();
|
||||
|
||||
if(rows < 0) {
|
||||
throw new SQLException("Rows must be >= 0");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFetchSize() throws SQLException {
|
||||
checkClosed();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResultSetConcurrency() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
return ResultSet.CONCUR_READ_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResultSetType() throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
checkClosed();
|
||||
|
||||
return ResultSet.TYPE_FORWARD_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -501,16 +501,9 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
|||
con.clearWarnings();
|
||||
assertNull(con.getWarnings());
|
||||
|
||||
|
||||
try (Statement statement = con.createStatement()) {
|
||||
assertEquals(con, statement.getConnection());
|
||||
|
||||
assertNull(statement.getWarnings());
|
||||
statement.clearWarnings();
|
||||
assertNull(statement.getWarnings());
|
||||
|
||||
assertEquals(0, statement.getFetchSize());
|
||||
statement.setFetchSize(0);
|
||||
assertEquals(0, statement.getFetchSize());
|
||||
checkStatement(con, statement);
|
||||
|
||||
try (ResultSet rs = statement.executeQuery(sql)) {
|
||||
assertEquals(statement, rs.getStatement());
|
||||
|
@ -533,15 +526,7 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
|||
}
|
||||
|
||||
try (PreparedStatement statement = con.prepareStatement(sql)) {
|
||||
assertEquals(con, statement.getConnection());
|
||||
|
||||
assertNull(statement.getWarnings());
|
||||
statement.clearWarnings();
|
||||
assertNull(statement.getWarnings());
|
||||
|
||||
assertEquals(0, statement.getFetchSize());
|
||||
statement.setFetchSize(0);
|
||||
assertEquals(0, statement.getFetchSize());
|
||||
checkStatement(con, statement);
|
||||
|
||||
try (ResultSet rs = statement.executeQuery()) {
|
||||
assertEquals(statement, rs.getStatement());
|
||||
|
@ -565,6 +550,25 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
private void checkStatement(Connection con, Statement statement) throws Exception {
|
||||
assertEquals(con, statement.getConnection());
|
||||
|
||||
assertNull(statement.getWarnings());
|
||||
statement.clearWarnings();
|
||||
assertNull(statement.getWarnings());
|
||||
|
||||
assertEquals(ResultSet.TYPE_FORWARD_ONLY, statement.getResultSetType());
|
||||
assertEquals(ResultSet.CONCUR_READ_ONLY, statement.getResultSetConcurrency());
|
||||
|
||||
assertEquals(ResultSet.FETCH_FORWARD, statement.getFetchDirection());
|
||||
statement.setFetchDirection(ResultSet.FETCH_FORWARD);
|
||||
assertEquals(ResultSet.FETCH_FORWARD, statement.getFetchDirection());
|
||||
|
||||
assertEquals(0, statement.getFetchSize());
|
||||
statement.setFetchSize(0);
|
||||
assertEquals(0, statement.getFetchSize());
|
||||
}
|
||||
|
||||
private void checkResultSetMetadata(ResultSet rs) throws Exception {
|
||||
ResultSetMetaData resultSetMetaData = rs.getMetaData();
|
||||
|
||||
|
@ -604,12 +608,21 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {
|
|||
}
|
||||
|
||||
private void checkResultSet(ResultSet rs) throws Exception {
|
||||
assertEquals(ResultSet.TYPE_FORWARD_ONLY, rs.getType());
|
||||
|
||||
assertNull(rs.getWarnings());
|
||||
rs.clearWarnings();
|
||||
assertNull(rs.getWarnings());
|
||||
|
||||
assertEquals(ResultSet.TYPE_FORWARD_ONLY, rs.getType());
|
||||
assertEquals(ResultSet.CONCUR_READ_ONLY, rs.getConcurrency());
|
||||
|
||||
assertEquals(ResultSet.FETCH_FORWARD, rs.getFetchDirection());
|
||||
rs.setFetchDirection(ResultSet.FETCH_FORWARD);
|
||||
assertEquals(ResultSet.FETCH_FORWARD, rs.getFetchDirection());
|
||||
|
||||
assertEquals(0, rs.getFetchSize());
|
||||
rs.setFetchSize(10);
|
||||
assertEquals(0, rs.getFetchSize());
|
||||
|
||||
assertTrue(rs.next());
|
||||
|
||||
assertEquals(14L, rs.getObject("a_i"));
|
||||
|
|
Loading…
Reference in New Issue