提交 293524b4 编写于 作者: Z zyyang

change

上级 a3d87f88
package com.taosdata.jdbc; package com.taosdata.jdbc;
import java.sql.*; import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public abstract class AbstractStatement extends WrapperImpl implements Statement { public abstract class AbstractStatement extends WrapperImpl implements Statement {
protected List<String> batchedArgs;
private int fetchSize; private int fetchSize;
@Override @Override
...@@ -168,13 +171,42 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement ...@@ -168,13 +171,42 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
} }
@Override @Override
public abstract void addBatch(String sql) throws SQLException; public void addBatch(String sql) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (batchedArgs == null) {
batchedArgs = new ArrayList<>();
}
batchedArgs.add(sql);
}
@Override @Override
public abstract void clearBatch() throws SQLException; public void clearBatch() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (batchedArgs != null)
batchedArgs.clear();
}
@Override @Override
public abstract int[] executeBatch() throws SQLException; public int[] executeBatch() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (batchedArgs == null || batchedArgs.isEmpty())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_BATCH_IS_EMPTY);
int[] res = new int[batchedArgs.size()];
for (int i = 0; i < batchedArgs.size(); i++) {
boolean isSelect = execute(batchedArgs.get(i));
if (isSelect) {
res[i] = SUCCESS_NO_INFO;
} else {
res[i] = getUpdateCount();
}
}
return res;
}
@Override @Override
public abstract Connection getConnection() throws SQLException; public abstract Connection getConnection() throws SQLException;
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
*****************************************************************************/ *****************************************************************************/
package com.taosdata.jdbc; package com.taosdata.jdbc;
import java.sql.*; import java.sql.Connection;
import java.util.ArrayList; import java.sql.ResultSet;
import java.util.List; import java.sql.SQLException;
public class TSDBStatement extends AbstractStatement { public class TSDBStatement extends AbstractStatement {
...@@ -24,7 +24,6 @@ public class TSDBStatement extends AbstractStatement { ...@@ -24,7 +24,6 @@ public class TSDBStatement extends AbstractStatement {
/** /**
* To store batched commands * To store batched commands
*/ */
protected List<String> batchedArgs;
/** /**
* Status of current statement * Status of current statement
*/ */
...@@ -119,41 +118,6 @@ public class TSDBStatement extends AbstractStatement { ...@@ -119,41 +118,6 @@ public class TSDBStatement extends AbstractStatement {
return this.affectedRows; return this.affectedRows;
} }
public void addBatch(String sql) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (batchedArgs == null) {
batchedArgs = new ArrayList<>();
}
batchedArgs.add(sql);
}
public void clearBatch() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (batchedArgs != null)
batchedArgs.clear();
}
public int[] executeBatch() throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
if (batchedArgs == null || batchedArgs.isEmpty())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_BATCH_IS_EMPTY);
int[] res = new int[batchedArgs.size()];
for (int i = 0; i < batchedArgs.size(); i++) {
boolean isSelect = execute(batchedArgs.get(i));
if (isSelect) {
res[i] = SUCCESS_NO_INFO;
} else {
res[i] = getUpdateCount();
}
}
return res;
}
public Connection getConnection() throws SQLException { public Connection getConnection() throws SQLException {
if (isClosed()) if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
......
...@@ -213,24 +213,6 @@ public class RestfulStatement extends AbstractStatement { ...@@ -213,24 +213,6 @@ public class RestfulStatement extends AbstractStatement {
return this.affectedRows; return this.affectedRows;
} }
@Override
public void addBatch(String sql) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
//TODO:
}
@Override
public void clearBatch() throws SQLException {
//TODO:
}
@Override
public int[] executeBatch() throws SQLException {
//TODO:
return new int[0];
}
@Override @Override
public Connection getConnection() throws SQLException { public Connection getConnection() throws SQLException {
if (isClosed()) if (isClosed())
......
...@@ -11,8 +11,8 @@ import java.util.Properties; ...@@ -11,8 +11,8 @@ import java.util.Properties;
import java.util.UUID; import java.util.UUID;
public class RestfulStatementTest { public class RestfulStatementTest {
private static final String host = "127.0.0.1"; // private static final String host = "127.0.0.1";
// private static final String host = "master"; private static final String host = "master";
private static Connection conn; private static Connection conn;
private static Statement stmt; private static Statement stmt;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册