You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2016/04/27 20:21:46 UTC
[02/50] [abbrv] lucene-solr:solr-5750: SOLR-9020: Implement
StatementImpl/ResultSetImpl get/set fetch* methods and proper errors for
traversal methods
SOLR-9020: Implement StatementImpl/ResultSetImpl get/set fetch* methods and proper errors for traversal methods
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/a9a842f0
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/a9a842f0
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/a9a842f0
Branch: refs/heads/solr-5750
Commit: a9a842f05dcebb6b86a6f47354aa760a83763e6c
Parents: b44ca08
Author: Kevin Risden <kr...@apache.org>
Authored: Wed Apr 20 13:40:59 2016 -0500
Committer: Kevin Risden <kr...@apache.org>
Committed: Wed Apr 20 14:48:23 2016 -0500
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +
.../solr/client/solrj/io/sql/ResultSetImpl.java | 76 +++++++++++++++-----
.../solr/client/solrj/io/sql/StatementImpl.java | 46 +++++++-----
.../solr/client/solrj/io/sql/JdbcTest.java | 53 ++++++++------
4 files changed, 124 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a9a842f0/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 8630ea4..31ae74c 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -109,6 +109,8 @@ New Features
* 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
----------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a9a842f0/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/ResultSetImpl.java
----------------------------------------------------------------------
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 e4dcaed..91b99b9 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
@@ -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
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a9a842f0/solr/solrj/src/java/org/apache/solr/client/solrj/io/sql/StatementImpl.java
----------------------------------------------------------------------
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 24b20a4..1b1200d 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
@@ -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
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a9a842f0/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java
----------------------------------------------------------------------
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 40d14a1..9050092 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
@@ -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());
+ try (Statement statement = con.createStatement()) {
+ 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"));