change
This commit is contained in:
parent
a3d87f8864
commit
293524b4b9
|
@ -1,9 +1,12 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractStatement extends WrapperImpl implements Statement {
|
||||
|
||||
protected List<String> batchedArgs;
|
||||
private int fetchSize;
|
||||
|
||||
@Override
|
||||
|
@ -168,13 +171,42 @@ public abstract class AbstractStatement extends WrapperImpl implements Statement
|
|||
}
|
||||
|
||||
@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
|
||||
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
|
||||
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
|
||||
public abstract Connection getConnection() throws SQLException;
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
*****************************************************************************/
|
||||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class TSDBStatement extends AbstractStatement {
|
||||
|
||||
|
@ -24,7 +24,6 @@ public class TSDBStatement extends AbstractStatement {
|
|||
/**
|
||||
* To store batched commands
|
||||
*/
|
||||
protected List<String> batchedArgs;
|
||||
/**
|
||||
* Status of current statement
|
||||
*/
|
||||
|
@ -119,41 +118,6 @@ public class TSDBStatement extends AbstractStatement {
|
|||
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 {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
|
|
|
@ -213,24 +213,6 @@ public class RestfulStatement extends AbstractStatement {
|
|||
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
|
||||
public Connection getConnection() throws SQLException {
|
||||
if (isClosed())
|
||||
|
|
|
@ -11,8 +11,8 @@ import java.util.Properties;
|
|||
import java.util.UUID;
|
||||
|
||||
public class RestfulStatementTest {
|
||||
private static final String host = "127.0.0.1";
|
||||
// private static final String host = "master";
|
||||
// private static final String host = "127.0.0.1";
|
||||
private static final String host = "master";
|
||||
private static Connection conn;
|
||||
private static Statement stmt;
|
||||
|
||||
|
|
Loading…
Reference in New Issue