diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java index 0f93b5bb0d257d08af759b8a70d20614dd402669..4aa1ff8690a864aaf9c29266e6799ae04e33291d 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractStatement.java @@ -5,6 +5,7 @@ import java.sql.*; public abstract class AbstractStatement implements Statement { private volatile boolean closeOnCompletion; + private int fetchSize; @Override public abstract ResultSet executeQuery(String sql) throws SQLException; @@ -116,7 +117,11 @@ public abstract class AbstractStatement implements Statement { } @Override - public abstract int getFetchDirection() throws SQLException; + public int getFetchDirection() throws SQLException { + if (isClosed()) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); + return ResultSet.FETCH_FORWARD; + } @Override public void setFetchSize(int rows) throws SQLException { @@ -125,16 +130,29 @@ public abstract class AbstractStatement implements Statement { if (rows < 0) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); //nothing to do + this.fetchSize = rows; } @Override - public abstract int getFetchSize() throws SQLException; + public int getFetchSize() throws SQLException { + if (isClosed()) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); + return this.fetchSize; + } @Override - public abstract int getResultSetConcurrency() throws SQLException; + public int getResultSetConcurrency() throws SQLException { + if (isClosed()) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); + return ResultSet.CONCUR_READ_ONLY; + } @Override - public abstract int getResultSetType() throws SQLException; + public int getResultSetType() throws SQLException { + if (isClosed()) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); + return ResultSet.TYPE_FORWARD_ONLY; + } @Override public abstract void addBatch(String sql) throws SQLException; @@ -149,7 +167,11 @@ public abstract class AbstractStatement implements Statement { public abstract Connection getConnection() throws SQLException; @Override - public abstract boolean getMoreResults(int current) throws SQLException; + public boolean getMoreResults(int current) throws SQLException { + if (isClosed()) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); + return false; + } @Override public ResultSet getGeneratedKeys() throws SQLException { @@ -187,7 +209,11 @@ public abstract class AbstractStatement implements Statement { } @Override - public abstract int getResultSetHoldability() throws SQLException; + public int getResultSetHoldability() throws SQLException { + if (isClosed()) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); + return ResultSet.HOLD_CURSORS_OVER_COMMIT; + } @Override public abstract boolean isClosed() throws SQLException; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index 7955a2557ddd3bec8d20431d3eef574ea9d7f2b1..0f62bdc661292e0ba41d516a9244034dff3542ea 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -21,12 +21,10 @@ import java.util.List; public class TSDBStatement extends AbstractStatement { private TSDBJNIConnector connector; - /** * To store batched commands */ protected List batchedArgs; -// private Long pSql = 0l; /** * Status of current statement */ @@ -107,7 +105,6 @@ public class TSDBStatement extends AbstractStatement { public ResultSet getResultSet() throws SQLException { if (isClosed()) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - // long resultSetPointer = connector.getResultSet(); // TSDBResultSet resSet = null; // if (resultSetPointer != TSDBConstants.JNI_NULL_POINTER) { @@ -122,33 +119,6 @@ public class TSDBStatement extends AbstractStatement { return this.affectedRows; } - public int getFetchDirection() throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - return this.resultSet.getFetchDirection(); - } - - /* - * used by spark - */ - public int getFetchSize() throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - return this.resultSet.getFetchSize(); - } - - public int getResultSetConcurrency() throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - return this.resultSet.getConcurrency(); - } - - public int getResultSetType() throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - return this.resultSet.getType(); - } - public void addBatch(String sql) throws SQLException { if (isClosed()) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); @@ -192,18 +162,6 @@ public class TSDBStatement extends AbstractStatement { return this.connection; } - public boolean getMoreResults(int current) throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - throw new SQLException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG); - } - - public int getResultSetHoldability() throws SQLException { - if (isClosed()) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - return this.resultSet.getHoldability(); - } - public boolean isClosed() throws SQLException { return isClosed; } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java index f0e2882aa2ed65f4552bfa5de8f1aab531fb3d86..8a38690d600f669c8b9cb43ff969508cc53828e8 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java @@ -192,32 +192,6 @@ public class RestfulStatement extends AbstractStatement { return this.affectedRows; } - @Override - public int getFetchDirection() throws SQLException { - return this.resultSet.getFetchDirection(); - } - - @Override - public int getFetchSize() throws SQLException { - if (isClosed()) - throw new SQLException(TSDBConstants.STATEMENT_CLOSED); - return 0; - } - - @Override - public int getResultSetConcurrency() throws SQLException { - if (isClosed()) - throw new SQLException(TSDBConstants.STATEMENT_CLOSED); - return this.resultSet.getConcurrency(); - } - - @Override - public int getResultSetType() throws SQLException { - if (isClosed()) - throw new SQLException(TSDBConstants.STATEMENT_CLOSED); - return this.resultSet.getType(); - } - @Override public void addBatch(String sql) throws SQLException { if (isClosed()) @@ -243,36 +217,6 @@ public class RestfulStatement extends AbstractStatement { return this.conn; } - @Override - public boolean getMoreResults(int current) throws SQLException { - if (isClosed()) - throw new SQLException(TSDBConstants.STATEMENT_CLOSED); - if (resultSet == null) - return false; - -// switch (current) { -// case CLOSE_CURRENT_RESULT: -// resultSet.close(); -// break; -// case KEEP_CURRENT_RESULT: -// break; -// case CLOSE_ALL_RESULTS: -// resultSet.close(); -// break; -// default: -// throw new SQLException(TSDBConstants.INVALID_VARIABLES); -// } -// return next; - return false; - } - - @Override - public int getResultSetHoldability() throws SQLException { - if (isClosed()) - throw new SQLException(TSDBConstants.STATEMENT_CLOSED); - return this.resultSet.getHoldability(); - } - @Override public boolean isClosed() throws SQLException { return closed; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java index ce5e4eb2c9904796da2187f84821de2760021f0e..3c70a07ef34ec37d28c32e749d8ae1981424b4ba 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBStatementTest.java @@ -1,11 +1,13 @@ package com.taosdata.jdbc; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import java.sql.*; import java.util.Properties; +import java.util.UUID; public class TSDBStatementTest { private static final String host = "127.0.0.1"; @@ -16,6 +18,7 @@ public class TSDBStatementTest { public void executeQuery() { try { ResultSet rs = stmt.executeQuery("show databases"); + Assert.assertNotNull(rs); ResultSetMetaData meta = rs.getMetaData(); while (rs.next()) { for (int i = 1; i <= meta.getColumnCount(); i++) { @@ -31,6 +34,15 @@ public class TSDBStatementTest { @Test public void executeUpdate() { + final String dbName = "test_" + UUID.randomUUID(); + try { + int affectRows = stmt.executeUpdate("create database " + dbName); + Assert.assertEquals(0, affectRows); + affectRows = stmt.executeUpdate("drop database " + dbName); + Assert.assertEquals(0, affectRows); + } catch (SQLException e) { + e.printStackTrace(); + } } @Test @@ -39,6 +51,7 @@ public class TSDBStatementTest { @Test public void execute() { + } @Test @@ -49,14 +62,6 @@ public class TSDBStatementTest { public void getUpdateCount() { } - @Test - public void getFetchDirection() { - } - - @Test - public void getFetchSize() { - } - @Test public void getResultSetConcurrency() { }