commit
52e62cf166
|
@ -34,44 +34,37 @@ import java.util.*;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
public class TSDBConnection implements Connection {
|
public class TSDBConnection implements Connection {
|
||||||
protected Properties props = null;
|
|
||||||
|
|
||||||
private TSDBJNIConnector connector = null;
|
private TSDBJNIConnector connector = null;
|
||||||
|
|
||||||
private String catalog = null;
|
private String catalog = null;
|
||||||
|
|
||||||
private TSDBDatabaseMetaData dbMetaData = null;
|
private TSDBDatabaseMetaData dbMetaData;
|
||||||
|
|
||||||
private Properties clientInfoProps = new Properties();
|
private Properties clientInfoProps = new Properties();
|
||||||
|
|
||||||
private int timeoutMilliseconds = 0;
|
private int timeoutMilliseconds = 0;
|
||||||
|
|
||||||
private boolean batchFetch = false;
|
private boolean batchFetch = false;
|
||||||
|
|
||||||
public TSDBConnection(Properties info, TSDBDatabaseMetaData meta) throws SQLException {
|
public TSDBConnection(Properties info, TSDBDatabaseMetaData meta) throws SQLException {
|
||||||
this.dbMetaData = meta;
|
this.dbMetaData = meta;
|
||||||
connect(info.getProperty(TSDBDriver.PROPERTY_KEY_HOST),
|
connect(info.getProperty(TSDBDriver.PROPERTY_KEY_HOST),
|
||||||
Integer.parseInt(info.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "0")),
|
Integer.parseInt(info.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "0")),
|
||||||
info.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME),
|
info.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME),
|
||||||
info.getProperty(TSDBDriver.PROPERTY_KEY_USER),
|
info.getProperty(TSDBDriver.PROPERTY_KEY_USER),
|
||||||
info.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD));
|
info.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD));
|
||||||
|
|
||||||
String batchLoad = info.getProperty(TSDBDriver.PROPERTY_KEY_BATCH_LOAD);
|
String batchLoad = info.getProperty(TSDBDriver.PROPERTY_KEY_BATCH_LOAD);
|
||||||
if (batchLoad != null) {
|
if (batchLoad != null) {
|
||||||
this.batchFetch = Boolean.parseBoolean(batchLoad);
|
this.batchFetch = Boolean.parseBoolean(batchLoad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void connect(String host, int port, String dbName, String user, String password) throws SQLException {
|
private void connect(String host, int port, String dbName, String user, String password) throws SQLException {
|
||||||
this.connector = new TSDBJNIConnector();
|
this.connector = new TSDBJNIConnector();
|
||||||
this.connector.connect(host, port, dbName, user, password);
|
this.connector.connect(host, port, dbName, user, password);
|
||||||
|
this.setCatalog(dbName);
|
||||||
try {
|
|
||||||
this.setCatalog(dbName);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.dbMetaData.setConnection(this);
|
this.dbMetaData.setConnection(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,68 +73,86 @@ public class TSDBConnection implements Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Statement createStatement() throws SQLException {
|
public Statement createStatement() throws SQLException {
|
||||||
if (!this.connector.isClosed()) {
|
if (isClosed()) {
|
||||||
TSDBStatement statement = new TSDBStatement(this, this.connector);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
statement.setConnection(this);
|
|
||||||
return statement;
|
|
||||||
} else {
|
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TSDBStatement statement = new TSDBStatement(this, this.connector);
|
||||||
|
statement.setConnection(this);
|
||||||
|
return statement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TSDBSubscribe subscribe(String topic, String sql, boolean restart) throws SQLException {
|
public TSDBSubscribe subscribe(String topic, String sql, boolean restart) throws SQLException {
|
||||||
if (this.connector.isClosed()) {
|
if (isClosed()) {
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
long id = this.connector.subscribe(topic, sql, restart, 0);
|
long id = this.connector.subscribe(topic, sql, restart, 0);
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("failed to create subscription"));
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_SUBSCRIBE_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TSDBSubscribe(this.connector, id);
|
return new TSDBSubscribe(this.connector, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||||
if (!this.connector.isClosed()) {
|
if (isClosed()) {
|
||||||
return new TSDBPreparedStatement(this, this.connector, sql);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
} else {
|
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new TSDBPreparedStatement(this, this.connector, sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CallableStatement prepareCall(String sql) throws SQLException {
|
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String nativeSQL(String sql) throws SQLException {
|
public String nativeSQL(String sql) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getAutoCommit() throws SQLException {
|
public boolean getAutoCommit() throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void commit() throws SQLException {
|
public void commit() throws SQLException {
|
||||||
}
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
public void rollback() throws SQLException {
|
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() throws SQLException {
|
|
||||||
if (this.connector != null && !this.connector.isClosed()) {
|
|
||||||
this.connector.closeConnection();
|
|
||||||
} else {
|
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("connection is already closed!"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void rollback() throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
this.connector.closeConnection();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isClosed() throws SQLException {
|
public boolean isClosed() throws SQLException {
|
||||||
return this.connector.isClosed();
|
return this.connector != null && this.connector.isClosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,6 +165,9 @@ public class TSDBConnection implements Connection {
|
||||||
* @throws SQLException if a database access error occurs
|
* @throws SQLException if a database access error occurs
|
||||||
*/
|
*/
|
||||||
public DatabaseMetaData getMetaData() throws SQLException {
|
public DatabaseMetaData getMetaData() throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
return this.dbMetaData;
|
return this.dbMetaData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,17 +179,29 @@ public class TSDBConnection implements Connection {
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReadOnly() throws SQLException {
|
public boolean isReadOnly() throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCatalog(String catalog) throws SQLException {
|
public void setCatalog(String catalog) throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
this.catalog = catalog;
|
this.catalog = catalog;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCatalog() throws SQLException {
|
public String getCatalog() throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
return this.catalog;
|
return this.catalog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,6 +213,19 @@ public class TSDBConnection implements Connection {
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public void setTransactionIsolation(int level) throws SQLException {
|
public void setTransactionIsolation(int level) throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
switch (level) {
|
||||||
|
case Connection.TRANSACTION_NONE:
|
||||||
|
case Connection.TRANSACTION_READ_COMMITTED:
|
||||||
|
case Connection.TRANSACTION_READ_UNCOMMITTED:
|
||||||
|
case Connection.TRANSACTION_REPEATABLE_READ:
|
||||||
|
case Connection.TRANSACTION_SERIALIZABLE:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,60 +235,81 @@ public class TSDBConnection implements Connection {
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public int getTransactionIsolation() throws SQLException {
|
public int getTransactionIsolation() throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
return Connection.TRANSACTION_NONE;
|
return Connection.TRANSACTION_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SQLWarning getWarnings() throws SQLException {
|
public SQLWarning getWarnings() throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
//todo: implement getWarnings according to the warning messages returned from TDengine
|
//todo: implement getWarnings according to the warning messages returned from TDengine
|
||||||
return null;
|
return null;
|
||||||
// throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearWarnings() throws SQLException {
|
public void clearWarnings() throws SQLException {
|
||||||
// left blank to support HikariCP connection
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
//todo: implement clearWarnings according to the warning messages returned from TDengine
|
//todo: implement clearWarnings according to the warning messages returned from TDengine
|
||||||
}
|
}
|
||||||
|
|
||||||
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
|
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
// This method is implemented in the current way to support Spark
|
// This method is implemented in the current way to support Spark
|
||||||
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
|
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
|
||||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
|
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
|
||||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.prepareStatement(sql);
|
return this.prepareStatement(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getBatchFetch() {
|
public Boolean getBatchFetch() {
|
||||||
return this.batchFetch;
|
return this.batchFetch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBatchFetch(Boolean batchFetch) {
|
public void setBatchFetch(Boolean batchFetch) {
|
||||||
this.batchFetch = batchFetch;
|
this.batchFetch = batchFetch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHoldability(int holdability) throws SQLException {
|
public void setHoldability(int holdability) throws SQLException {
|
||||||
// intentionally left empty to support druid connection pool.
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -259,67 +319,111 @@ public class TSDBConnection implements Connection {
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public int getHoldability() throws SQLException {
|
public int getHoldability() throws SQLException {
|
||||||
//intentionally left empty to support HikariCP connection.
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
|
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Savepoint setSavepoint() throws SQLException {
|
public Savepoint setSavepoint() throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Savepoint setSavepoint(String name) throws SQLException {
|
public Savepoint setSavepoint(String name) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rollback(Savepoint savepoint) throws SQLException {
|
public void rollback(Savepoint savepoint) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
|
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
|
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
|
||||||
int resultSetHoldability) throws SQLException {
|
int resultSetHoldability) throws SQLException {
|
||||||
return this.prepareStatement(sql, resultSetType, resultSetConcurrency);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
|
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
|
||||||
int resultSetHoldability) throws SQLException {
|
int resultSetHoldability) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
|
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
|
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
|
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Clob createClob() throws SQLException {
|
public Clob createClob() throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Blob createBlob() throws SQLException {
|
public Blob createBlob() throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NClob createNClob() throws SQLException {
|
public NClob createNClob() throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SQLXML createSQLXML() throws SQLException {
|
public SQLXML createSQLXML() throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValid(int timeout) throws SQLException {
|
public boolean isValid(int timeout) throws SQLException {
|
||||||
|
@ -338,31 +442,52 @@ public class TSDBConnection implements Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClientInfo(String name) throws SQLException {
|
public String getClientInfo(String name) throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
return clientInfoProps.getProperty(name);
|
return clientInfoProps.getProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Properties getClientInfo() throws SQLException {
|
public Properties getClientInfo() throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
return clientInfoProps;
|
return clientInfoProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
|
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
|
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSchema(String schema) throws SQLException {
|
public void setSchema(String schema) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSchema() throws SQLException {
|
public String getSchema() throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void abort(Executor executor) throws SQLException {
|
public void abort(Executor executor) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
|
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
|
||||||
|
@ -370,14 +495,21 @@ public class TSDBConnection implements Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNetworkTimeout() throws SQLException {
|
public int getNetworkTimeout() throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||||
|
}
|
||||||
return this.timeoutMilliseconds;
|
return this.timeoutMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
try {
|
||||||
|
return iface.cast(this);
|
||||||
|
} catch (ClassCastException cce) {
|
||||||
|
throw new SQLException("Unable to unwrap to " + iface.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
return iface.isInstance(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,12 @@ import java.util.Map;
|
||||||
|
|
||||||
public abstract class TSDBConstants {
|
public abstract class TSDBConstants {
|
||||||
|
|
||||||
public static final String STATEMENT_CLOSED = "Statement already closed.";
|
public static final String STATEMENT_CLOSED = "statement is 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 UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!";
|
||||||
public static final String INVALID_VARIABLES = "invalid variables";
|
public static final String INVALID_VARIABLES = "invalid variables";
|
||||||
public static final String RESULT_SET_IS_CLOSED = "resultSet is closed.";
|
public static final String RESULT_SET_IS_CLOSED = "resultSet is closed";
|
||||||
|
|
||||||
|
public static final String DEFAULT_PORT = "6200";
|
||||||
public static Map<Integer, String> DATATYPE_MAP = null;
|
public static Map<Integer, String> DATATYPE_MAP = null;
|
||||||
|
|
||||||
public static final long JNI_NULL_POINTER = 0L;
|
public static final long JNI_NULL_POINTER = 0L;
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TSDBError {
|
||||||
|
private static Map<Integer, String> TSDBErrorMap = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED, "connection already closed");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD, "this operation is NOT supported currently!");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_VARIABLE, "invalid variables");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED, "statement is closed");
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED, "resultSet is closed");
|
||||||
|
/**************************************************/
|
||||||
|
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SUBSCRIBE_FAILED, "failed to create subscription");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String wrapErrMsg(String msg) {
|
||||||
|
return "TDengine Error: " + msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SQLException createSQLException(int errorNumber) {
|
||||||
|
// JDBC exception code is less than 0x2350
|
||||||
|
if (errorNumber <= 0x2350)
|
||||||
|
return new SQLException(TSDBErrorMap.get(errorNumber));
|
||||||
|
// JNI exception code is
|
||||||
|
return new SQLException(wrapErrMsg(TSDBErrorMap.get(errorNumber)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
|
public class TSDBErrorNumbers {
|
||||||
|
|
||||||
|
public static final int ERROR_CONNECTION_CLOSED = 0x2301; // connection already closed
|
||||||
|
public static final int ERROR_UNSUPPORTED_METHOD = 0x2302; //this operation is NOT supported currently!
|
||||||
|
public static final int ERROR_INVALID_VARIABLE = 0x2303; //invalid variables
|
||||||
|
public static final int ERROR_STATEMENT_CLOSED = 0x2304; //statement already closed
|
||||||
|
public static final int ERROR_RESULTSET_CLOSED = 0x2305; //resultSet is closed
|
||||||
|
|
||||||
|
public static final int ERROR_SUBSCRIBE_FAILED = 0x2350; //failed to create subscription
|
||||||
|
|
||||||
|
private TSDBErrorNumbers() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,6 @@ import java.util.List;
|
||||||
|
|
||||||
public class TSDBStatement implements Statement {
|
public class TSDBStatement implements Statement {
|
||||||
private TSDBJNIConnector connector;
|
private TSDBJNIConnector connector;
|
||||||
private TaosInfo taosInfo = TaosInfo.getInstance();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To store batched commands
|
* To store batched commands
|
||||||
|
@ -69,13 +68,12 @@ public class TSDBStatement implements Statement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultSet executeQuery(String sql) throws SQLException {
|
public ResultSet executeQuery(String sql) throws SQLException {
|
||||||
if (isClosed) {
|
if (isClosed()) {
|
||||||
throw new SQLException("Invalid method call on a closed statement.");
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO make sure it is not a update query
|
// TODO make sure it is not a update query
|
||||||
pSql = this.connector.executeQuery(sql);
|
pSql = this.connector.executeQuery(sql);
|
||||||
|
|
||||||
long resultSetPointer = this.connector.getResultSet();
|
long resultSetPointer = this.connector.getResultSet();
|
||||||
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
|
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
|
||||||
this.connector.freeResultSet(pSql);
|
this.connector.freeResultSet(pSql);
|
||||||
|
@ -100,8 +98,8 @@ public class TSDBStatement implements Statement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int executeUpdate(String sql) throws SQLException {
|
public int executeUpdate(String sql) throws SQLException {
|
||||||
if (isClosed) {
|
if (isClosed()) {
|
||||||
throw new SQLException("Invalid method call on a closed statement.");
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO check if current query is update query
|
// TODO check if current query is update query
|
||||||
|
@ -133,25 +131,33 @@ public class TSDBStatement implements Statement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxFieldSize() throws SQLException {
|
public int getMaxFieldSize() throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
// throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxFieldSize(int max) throws SQLException {
|
public void setMaxFieldSize(int max) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed()) {
|
||||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||||
|
}
|
||||||
|
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxRows() throws SQLException {
|
public int getMaxRows() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed()) {
|
||||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||||
|
}
|
||||||
// always set maxRows to zero, meaning unlimitted rows in a resultSet
|
// always set maxRows to zero, meaning unlimitted rows in a resultSet
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxRows(int max) throws SQLException {
|
public void setMaxRows(int max) throws SQLException {
|
||||||
|
if (isClosed()) {
|
||||||
|
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||||
|
}
|
||||||
// always set maxRows to zero, meaning unlimited rows in a resultSet
|
// always set maxRows to zero, meaning unlimited rows in a resultSet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue