change
This commit is contained in:
parent
f52b5fe423
commit
b76d0ddc35
|
@ -0,0 +1,388 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public abstract class AbstractConnection extends WrapperImpl implements Connection {
|
||||
|
||||
protected volatile boolean isClosed;
|
||||
protected volatile String catalog;
|
||||
protected volatile Properties clientInfoProps = new Properties();
|
||||
|
||||
@Override
|
||||
public abstract Statement createStatement() throws SQLException;
|
||||
|
||||
@Override
|
||||
public abstract PreparedStatement prepareStatement(String sql) throws SQLException;
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nativeSQL(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
// do nothing
|
||||
return sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAutoCommit() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void close() throws SQLException;
|
||||
|
||||
@Override
|
||||
public abstract boolean isClosed() throws SQLException;
|
||||
|
||||
@Override
|
||||
public abstract DatabaseMetaData getMetaData() throws SQLException;
|
||||
|
||||
@Override
|
||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCatalog(String catalog) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCatalog() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
return this.catalog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransactionIsolation(int level) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransactionIsolation() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
return Connection.TRANSACTION_NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWarnings() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException;
|
||||
|
||||
@Override
|
||||
public abstract PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException;
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHoldability(int holdability) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHoldability() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint(String name) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(Savepoint savepoint) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException;
|
||||
|
||||
@Override
|
||||
public abstract PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException;
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
switch (autoGeneratedKeys) {
|
||||
case Statement.RETURN_GENERATED_KEYS:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
case Statement.NO_GENERATED_KEYS:
|
||||
break;
|
||||
}
|
||||
|
||||
return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clob createClob() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Blob createBlob() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NClob createNClob() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLXML createSQLXML() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract boolean isValid(int timeout) throws SQLException;
|
||||
|
||||
@Override
|
||||
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
||||
if (isClosed)
|
||||
throw TSDBError.createSQLClientInfoException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
if (clientInfoProps == null)
|
||||
clientInfoProps = new Properties();
|
||||
clientInfoProps.setProperty(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientInfo(Properties properties) throws SQLClientInfoException {
|
||||
if (isClosed)
|
||||
throw TSDBError.createSQLClientInfoException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
for (Enumeration<Object> enumer = properties.keys(); enumer.hasMoreElements(); ) {
|
||||
String name = (String) enumer.nextElement();
|
||||
clientInfoProps.put(name, properties.getProperty(name));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClientInfo(String name) throws SQLException {
|
||||
if (isClosed)
|
||||
throw TSDBError.createSQLClientInfoException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
return clientInfoProps.getProperty(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties getClientInfo() throws SQLException {
|
||||
if (isClosed)
|
||||
throw TSDBError.createSQLClientInfoException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
return clientInfoProps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSchema(String schema) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
//do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchema() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abort(Executor executor) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
if (milliseconds < 0)
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNetworkTimeout() throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
}
|
|
@ -1067,6 +1067,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrap
|
|||
}
|
||||
|
||||
public ResultSet getClientInfoProperties() throws SQLException {
|
||||
//TODO: see https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#setClientInfo-java.lang.String-java.lang.String-
|
||||
return getEmptyResultSet();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,41 +14,17 @@
|
|||
*****************************************************************************/
|
||||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.Array;
|
||||
import java.sql.Blob;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.Clob;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.NClob;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLClientInfoException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLWarning;
|
||||
import java.sql.SQLXML;
|
||||
import java.sql.Savepoint;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Struct;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TSDBConnection implements Connection {
|
||||
public class TSDBConnection extends AbstractConnection {
|
||||
|
||||
private TSDBJNIConnector connector = null;
|
||||
|
||||
private String catalog = null;
|
||||
|
||||
private TSDBDatabaseMetaData dbMetaData;
|
||||
|
||||
private Properties clientInfoProps = new Properties();
|
||||
|
||||
private int timeoutMilliseconds = 0;
|
||||
|
||||
private boolean batchFetch = false;
|
||||
private TSDBJNIConnector connector;
|
||||
private TSDBDatabaseMetaData databaseMetaData;
|
||||
private boolean batchFetch;
|
||||
|
||||
public TSDBConnection(Properties info, TSDBDatabaseMetaData meta) throws SQLException {
|
||||
this.dbMetaData = meta;
|
||||
this.databaseMetaData = meta;
|
||||
connect(info.getProperty(TSDBDriver.PROPERTY_KEY_HOST),
|
||||
Integer.parseInt(info.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "0")),
|
||||
info.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME),
|
||||
|
@ -64,8 +40,8 @@ public class TSDBConnection implements Connection {
|
|||
private void connect(String host, int port, String dbName, String user, String password) throws SQLException {
|
||||
this.connector = new TSDBJNIConnector();
|
||||
this.connector.connect(host, port, dbName, user, password);
|
||||
this.setCatalog(dbName);
|
||||
this.dbMetaData.setConnection(this);
|
||||
this.catalog = dbName;
|
||||
this.databaseMetaData.setConnection(this);
|
||||
}
|
||||
|
||||
public TSDBJNIConnector getConnection() {
|
||||
|
@ -102,52 +78,11 @@ public class TSDBConnection implements Connection {
|
|||
return new TSDBPreparedStatement(this, this.connector, sql);
|
||||
}
|
||||
|
||||
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public String nativeSQL(String sql) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean getAutoCommit() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void commit() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_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.isClosed = true;
|
||||
this.connector.closeConnection();
|
||||
}
|
||||
|
||||
|
@ -155,105 +90,11 @@ public class TSDBConnection implements Connection {
|
|||
return this.connector != null && this.connector.isClosed();
|
||||
}
|
||||
|
||||
/**
|
||||
* A connection's database is able to provide information describing its tables,
|
||||
* its supported SQL grammar, its stored procedures, the capabilities of this
|
||||
* connection, etc. This information is made available through a
|
||||
* DatabaseMetaData object.
|
||||
*
|
||||
* @return a DatabaseMetaData object for this connection
|
||||
* @throws SQLException if a database access error occurs
|
||||
*/
|
||||
public DatabaseMetaData getMetaData() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
return this.dbMetaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* This readOnly option is not supported by TDengine. However, the method is intentionally left blank here to
|
||||
* support HikariCP connection.
|
||||
*
|
||||
* @param readOnly
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isReadOnly() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setCatalog(String catalog) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
this.catalog = catalog;
|
||||
}
|
||||
|
||||
public String getCatalog() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
return this.catalog;
|
||||
}
|
||||
|
||||
/**
|
||||
* The transaction isolation level option is not supported by TDengine.
|
||||
* This method is intentionally left empty to support HikariCP connection.
|
||||
*
|
||||
* @param 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The transaction isolation level option is not supported by TDengine.
|
||||
*
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public int getTransactionIsolation() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
return Connection.TRANSACTION_NONE;
|
||||
}
|
||||
|
||||
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
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clearWarnings() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
//todo: implement clearWarnings according to the warning messages returned from TDengine
|
||||
return this.databaseMetaData;
|
||||
}
|
||||
|
||||
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
|
@ -285,74 +126,6 @@ public class TSDBConnection implements Connection {
|
|||
this.batchFetch = batchFetch;
|
||||
}
|
||||
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||
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 {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public void setHoldability(int holdability) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* the transaction is not supported by TDengine, so the opened ResultSet Objects will remain open
|
||||
*
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public int getHoldability() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
|
||||
}
|
||||
|
||||
public Savepoint setSavepoint() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public Savepoint setSavepoint(String name) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public void rollback(Savepoint savepoint) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
||||
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)
|
||||
throws SQLException {
|
||||
if (isClosed()) {
|
||||
|
@ -369,147 +142,8 @@ public class TSDBConnection implements Connection {
|
|||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
|
||||
int resultSetHoldability) throws SQLException {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public Clob createClob() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public Blob createBlob() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public NClob createNClob() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public SQLXML createSQLXML() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public boolean isValid(int timeout) throws SQLException {
|
||||
return !this.isClosed();
|
||||
}
|
||||
|
||||
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
||||
clientInfoProps.setProperty(name, value);
|
||||
}
|
||||
|
||||
public void setClientInfo(Properties properties) throws SQLClientInfoException {
|
||||
for (Enumeration<Object> enumer = properties.keys(); enumer.hasMoreElements(); ) {
|
||||
String name = (String) enumer.nextElement();
|
||||
clientInfoProps.put(name, properties.getProperty(name));
|
||||
}
|
||||
}
|
||||
|
||||
public String getClientInfo(String name) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
return clientInfoProps.getProperty(name);
|
||||
}
|
||||
|
||||
public Properties getClientInfo() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
return clientInfoProps;
|
||||
}
|
||||
|
||||
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
|
||||
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 {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public void setSchema(String schema) throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public String getSchema() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public void abort(Executor executor) throws SQLException {
|
||||
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 {
|
||||
this.timeoutMilliseconds = milliseconds;
|
||||
}
|
||||
|
||||
public int getNetworkTimeout() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
return this.timeoutMilliseconds;
|
||||
}
|
||||
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
try {
|
||||
return iface.cast(this);
|
||||
} catch (ClassCastException cce) {
|
||||
throw new SQLException("Unable to unwrap to " + iface.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return iface.isInstance(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.SQLClientInfoException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.util.HashMap;
|
||||
|
@ -58,4 +59,8 @@ public class TSDBError {
|
|||
// JNI exception's error number is large than 0x2350
|
||||
return new SQLException("TDengine ERROR (" + Integer.toHexString(errorNumber) + "): " + message);
|
||||
}
|
||||
|
||||
public static SQLClientInfoException createSQLClientInfoException(int errorNumber) {
|
||||
return new SQLClientInfoException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,284 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TSDBConnectionTest {
|
||||
|
||||
private static final String host = "127.0.0.1";
|
||||
private static Connection conn;
|
||||
|
||||
@Test
|
||||
public void getConnection() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createStatement() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subscribe() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareStatement() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareCall() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nativeSQL() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAutoCommit() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAutoCommit() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commit() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rollback() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void close() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isClosed() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetaData() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setReadOnly() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReadOnly() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCatalog() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCatalog() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTransactionIsolation() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTransactionIsolation() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWarnings() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearWarnings() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateStatement() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareStatement() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBatchFetch() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBatchFetch() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareCall() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTypeMap() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTypeMap() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHoldability() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHoldability() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSavepoint() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSavepoint() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRollback() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releaseSavepoint() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateStatement1() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareStatement1() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareCall1() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareStatement2() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareStatement3() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrepareStatement4() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createClob() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createBlob() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createNClob() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSQLXML() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isValid() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setClientInfo() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetClientInfo() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getClientInfo() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClientInfo() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createArrayOf() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createStruct() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSchema() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchema() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void abort() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNetworkTimeout() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNetworkTimeout() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unwrap() {
|
||||
try {
|
||||
TSDBConnection tsdbConnection = conn.unwrap(TSDBConnection.class);
|
||||
Assert.assertNotNull(tsdbConnection);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isWrapperFor() throws SQLException {
|
||||
Assert.assertTrue(conn.isWrapperFor(TSDBConnection.class));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties);
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
try {
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue