提交 f146ada4 编写于 作者: Z zyyang

change

上级 d719810b
...@@ -5,6 +5,7 @@ import java.sql.*; ...@@ -5,6 +5,7 @@ import java.sql.*;
public abstract class AbstractStatement implements Statement { public abstract class AbstractStatement implements Statement {
private volatile boolean closeOnCompletion; private volatile boolean closeOnCompletion;
private int fetchSize;
@Override @Override
public abstract ResultSet executeQuery(String sql) throws SQLException; public abstract ResultSet executeQuery(String sql) throws SQLException;
...@@ -116,7 +117,11 @@ public abstract class AbstractStatement implements Statement { ...@@ -116,7 +117,11 @@ public abstract class AbstractStatement implements Statement {
} }
@Override @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 @Override
public void setFetchSize(int rows) throws SQLException { public void setFetchSize(int rows) throws SQLException {
...@@ -125,16 +130,29 @@ public abstract class AbstractStatement implements Statement { ...@@ -125,16 +130,29 @@ public abstract class AbstractStatement implements Statement {
if (rows < 0) if (rows < 0)
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
//nothing to do //nothing to do
this.fetchSize = rows;
} }
@Override @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 @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 @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 @Override
public abstract void addBatch(String sql) throws SQLException; public abstract void addBatch(String sql) throws SQLException;
...@@ -149,7 +167,11 @@ public abstract class AbstractStatement implements Statement { ...@@ -149,7 +167,11 @@ public abstract class AbstractStatement implements Statement {
public abstract Connection getConnection() throws SQLException; public abstract Connection getConnection() throws SQLException;
@Override @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 @Override
public ResultSet getGeneratedKeys() throws SQLException { public ResultSet getGeneratedKeys() throws SQLException {
...@@ -187,7 +209,11 @@ public abstract class AbstractStatement implements Statement { ...@@ -187,7 +209,11 @@ public abstract class AbstractStatement implements Statement {
} }
@Override @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 @Override
public abstract boolean isClosed() throws SQLException; public abstract boolean isClosed() throws SQLException;
......
...@@ -21,12 +21,10 @@ import java.util.List; ...@@ -21,12 +21,10 @@ import java.util.List;
public class TSDBStatement extends AbstractStatement { public class TSDBStatement extends AbstractStatement {
private TSDBJNIConnector connector; private TSDBJNIConnector connector;
/** /**
* To store batched commands * To store batched commands
*/ */
protected List<String> batchedArgs; protected List<String> batchedArgs;
// private Long pSql = 0l;
/** /**
* Status of current statement * Status of current statement
*/ */
...@@ -107,7 +105,6 @@ public class TSDBStatement extends AbstractStatement { ...@@ -107,7 +105,6 @@ public class TSDBStatement extends AbstractStatement {
public ResultSet getResultSet() throws SQLException { public ResultSet getResultSet() throws SQLException {
if (isClosed()) if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
// long resultSetPointer = connector.getResultSet(); // long resultSetPointer = connector.getResultSet();
// TSDBResultSet resSet = null; // TSDBResultSet resSet = null;
// if (resultSetPointer != TSDBConstants.JNI_NULL_POINTER) { // if (resultSetPointer != TSDBConstants.JNI_NULL_POINTER) {
...@@ -122,33 +119,6 @@ public class TSDBStatement extends AbstractStatement { ...@@ -122,33 +119,6 @@ public class TSDBStatement extends AbstractStatement {
return this.affectedRows; 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 { public void addBatch(String sql) throws SQLException {
if (isClosed()) if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
...@@ -192,18 +162,6 @@ public class TSDBStatement extends AbstractStatement { ...@@ -192,18 +162,6 @@ public class TSDBStatement extends AbstractStatement {
return this.connection; 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 { public boolean isClosed() throws SQLException {
return isClosed; return isClosed;
} }
......
...@@ -192,32 +192,6 @@ public class RestfulStatement extends AbstractStatement { ...@@ -192,32 +192,6 @@ public class RestfulStatement extends AbstractStatement {
return this.affectedRows; 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 @Override
public void addBatch(String sql) throws SQLException { public void addBatch(String sql) throws SQLException {
if (isClosed()) if (isClosed())
...@@ -243,36 +217,6 @@ public class RestfulStatement extends AbstractStatement { ...@@ -243,36 +217,6 @@ public class RestfulStatement extends AbstractStatement {
return this.conn; 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 @Override
public boolean isClosed() throws SQLException { public boolean isClosed() throws SQLException {
return closed; return closed;
......
package com.taosdata.jdbc; package com.taosdata.jdbc;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.sql.*; import java.sql.*;
import java.util.Properties; import java.util.Properties;
import java.util.UUID;
public class TSDBStatementTest { public class TSDBStatementTest {
private static final String host = "127.0.0.1"; private static final String host = "127.0.0.1";
...@@ -16,6 +18,7 @@ public class TSDBStatementTest { ...@@ -16,6 +18,7 @@ public class TSDBStatementTest {
public void executeQuery() { public void executeQuery() {
try { try {
ResultSet rs = stmt.executeQuery("show databases"); ResultSet rs = stmt.executeQuery("show databases");
Assert.assertNotNull(rs);
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) { while (rs.next()) {
for (int i = 1; i <= meta.getColumnCount(); i++) { for (int i = 1; i <= meta.getColumnCount(); i++) {
...@@ -31,6 +34,15 @@ public class TSDBStatementTest { ...@@ -31,6 +34,15 @@ public class TSDBStatementTest {
@Test @Test
public void executeUpdate() { 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 @Test
...@@ -39,6 +51,7 @@ public class TSDBStatementTest { ...@@ -39,6 +51,7 @@ public class TSDBStatementTest {
@Test @Test
public void execute() { public void execute() {
} }
@Test @Test
...@@ -49,14 +62,6 @@ public class TSDBStatementTest { ...@@ -49,14 +62,6 @@ public class TSDBStatementTest {
public void getUpdateCount() { public void getUpdateCount() {
} }
@Test
public void getFetchDirection() {
}
@Test
public void getFetchSize() {
}
@Test @Test
public void getResultSetConcurrency() { public void getResultSetConcurrency() {
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册