提交 f146ada4 编写于 作者: Z zyyang

change

上级 d719810b
......@@ -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;
......
......@@ -21,12 +21,10 @@ import java.util.List;
public class TSDBStatement extends AbstractStatement {
private TSDBJNIConnector connector;
/**
* To store batched commands
*/
protected List<String> 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;
}
......
......@@ -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;
......
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() {
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册