From b9da747d2d85c0c825dbc0fe252ca9ee525e7b85 Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 15:25:14 +0800 Subject: [PATCH] change --- .../java/com/taosdata/jdbc/TSDBConstants.java | 1 + .../java/com/taosdata/jdbc/TSDBStatement.java | 5 ++ .../taosdata/jdbc/rs/RestfulStatement.java | 47 +++++++++---------- .../java/com/taosdata/jdbc/StatementTest.java | 2 +- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java index 4f4911aad9..da297810fe 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java @@ -19,6 +19,7 @@ import java.util.Map; public abstract class TSDBConstants { + public static final String STATEMENT_CLOSED = "Statement already closed."; public static final String DEFAULT_PORT = "6200"; public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!"; public static final String INVALID_VARIABLES = "invalid variables"; 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 4c900b5fdc..e7317b8e1d 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 @@ -136,10 +136,15 @@ public class TSDBStatement implements Statement { } public void setMaxFieldSize(int max) throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } public int getMaxRows() throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); // always set maxRows to zero, meaning unlimitted rows in a resultSet return 0; } 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 8b2276fbb0..93712875b3 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 @@ -14,7 +14,6 @@ import java.util.stream.Collectors; public class RestfulStatement implements Statement { - private static final String STATEMENT_CLOSED = "Statement already closed."; private boolean closed; private String database; private final RestfulConnection conn; @@ -131,14 +130,14 @@ public class RestfulStatement implements Statement { @Override public int getMaxFieldSize() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return TSDBConstants.maxFieldSize; } @Override public void setMaxFieldSize(int max) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); if (max < 0) throw new SQLException(TSDBConstants.INVALID_VARIABLES); // nothing to do @@ -147,14 +146,14 @@ public class RestfulStatement implements Statement { @Override public int getMaxRows() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return 0; } @Override public void setMaxRows(int max) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); if (max < 0) throw new SQLException(TSDBConstants.INVALID_VARIABLES); // nothing to do @@ -163,20 +162,20 @@ public class RestfulStatement implements Statement { @Override public void setEscapeProcessing(boolean enable) throws SQLException { if (isClosed()) - throw new SQLException(RestfulStatement.STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); } @Override public int getQueryTimeout() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return 0; } @Override public void setQueryTimeout(int seconds) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); if (seconds < 0) throw new SQLException(TSDBConstants.INVALID_VARIABLES); } @@ -189,7 +188,7 @@ public class RestfulStatement implements Statement { @Override public SQLWarning getWarnings() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return null; } @@ -197,13 +196,13 @@ public class RestfulStatement implements Statement { public void clearWarnings() throws SQLException { // nothing to do if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); } @Override public void setCursorName(String name) throws SQLException { if (isClosed()) - throw new SQLException(RestfulStatement.STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -243,7 +242,7 @@ public class RestfulStatement implements Statement { @Override public ResultSet getResultSet() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return resultSet; } @@ -275,7 +274,7 @@ public class RestfulStatement implements Statement { @Override public void setFetchSize(int rows) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); if (rows < 0) throw new SQLException(TSDBConstants.INVALID_VARIABLES); //nothing to do @@ -284,28 +283,28 @@ public class RestfulStatement implements Statement { @Override public int getFetchSize() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return 0; } @Override public int getResultSetConcurrency() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return this.resultSet.getConcurrency(); } @Override public int getResultSetType() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return this.resultSet.getType(); } @Override public void addBatch(String sql) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); //TODO: } @@ -323,14 +322,14 @@ public class RestfulStatement implements Statement { @Override public Connection getConnection() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return this.conn; } @Override public boolean getMoreResults(int current) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); if (resultSet == null) return false; @@ -388,7 +387,7 @@ public class RestfulStatement implements Statement { @Override public int getResultSetHoldability() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return this.resultSet.getHoldability(); } @@ -400,28 +399,28 @@ public class RestfulStatement implements Statement { @Override public void setPoolable(boolean poolable) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); //nothing to do } @Override public boolean isPoolable() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return false; } @Override public void closeOnCompletion() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); this.closeOnCompletion = true; } @Override public boolean isCloseOnCompletion() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return this.closeOnCompletion; } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java index 4ce29af020..7a9bc57dfa 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java @@ -66,7 +66,7 @@ public class StatementTest { assertEquals(false, isClosed); } - @Test(expected = SQLFeatureNotSupportedException.class) + @Test(expected = SQLException.class) public void testUnsupport() { try { Assert.assertNotNull(statement.unwrap(TSDBStatement.class)); -- GitLab