Merge pull request #5184 from taosdata/feature/TD-2133
[TD-2133]<feature>: add queryService in java taosdemo
This commit is contained in:
commit
c4fb50281b
|
@ -128,6 +128,7 @@
|
|||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/AppMemoryLeakTest.java</exclude>
|
||||
<exclude>**/AuthenticationTest.java</exclude>
|
||||
<exclude>**/TaosInfoMonitorTest.java</exclude>
|
||||
<exclude>**/FailOverTest.java</exclude>
|
||||
<exclude>**/InvalidResultSetPointerTest.java</exclude>
|
||||
|
|
|
@ -0,0 +1,529 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
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);
|
||||
/*
|
||||
try (Statement stmt = createStatement()) {
|
||||
boolean execute = stmt.execute("use " + catalog);
|
||||
if (execute)
|
||||
this.catalog = catalog;
|
||||
} catch (SQLException e) {
|
||||
// do nothing
|
||||
}
|
||||
*/
|
||||
|
||||
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);
|
||||
|
||||
switch (level) {
|
||||
case Connection.TRANSACTION_NONE:
|
||||
break;
|
||||
case Connection.TRANSACTION_READ_UNCOMMITTED:
|
||||
case Connection.TRANSACTION_READ_COMMITTED:
|
||||
case Connection.TRANSACTION_REPEATABLE_READ:
|
||||
case Connection.TRANSACTION_SERIALIZABLE:
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
default:
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
}
|
||||
//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 Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
switch (resultSetType) {
|
||||
case ResultSet.TYPE_FORWARD_ONLY:
|
||||
break;
|
||||
case ResultSet.TYPE_SCROLL_INSENSITIVE:
|
||||
case ResultSet.TYPE_SCROLL_SENSITIVE:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
default:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
}
|
||||
|
||||
switch (resultSetConcurrency) {
|
||||
case ResultSet.CONCUR_READ_ONLY:
|
||||
break;
|
||||
case ResultSet.CONCUR_UPDATABLE:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
default:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
}
|
||||
|
||||
return createStatement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
switch (resultSetType) {
|
||||
case ResultSet.TYPE_FORWARD_ONLY:
|
||||
break;
|
||||
case ResultSet.TYPE_SCROLL_INSENSITIVE:
|
||||
case ResultSet.TYPE_SCROLL_SENSITIVE:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
default:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
}
|
||||
|
||||
switch (resultSetConcurrency) {
|
||||
case ResultSet.CONCUR_READ_ONLY:
|
||||
break;
|
||||
case ResultSet.CONCUR_UPDATABLE:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
default:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
}
|
||||
return prepareStatement(sql);
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
switch (holdability) {
|
||||
case ResultSet.HOLD_CURSORS_OVER_COMMIT:
|
||||
break;
|
||||
case ResultSet.CLOSE_CURSORS_AT_COMMIT:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
default:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
}
|
||||
//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 Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
switch (resultSetHoldability) {
|
||||
case ResultSet.HOLD_CURSORS_OVER_COMMIT:
|
||||
break;
|
||||
case ResultSet.CLOSE_CURSORS_AT_COMMIT:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
default:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
}
|
||||
|
||||
return createStatement(resultSetType, resultSetConcurrency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
|
||||
throws SQLException {
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
|
||||
switch (resultSetHoldability) {
|
||||
case ResultSet.HOLD_CURSORS_OVER_COMMIT:
|
||||
break;
|
||||
case ResultSet.CLOSE_CURSORS_AT_COMMIT:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
default:
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
}
|
||||
return prepareStatement(sql, resultSetType, resultSetConcurrency);
|
||||
}
|
||||
|
||||
@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, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
}
|
||||
|
||||
@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 boolean isValid(int timeout) throws SQLException {
|
||||
//true if the connection is valid, false otherwise
|
||||
if (isClosed())
|
||||
return false;
|
||||
if (timeout < 0) //SQLException - if the value supplied for timeout is less then 0
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
|
||||
ExecutorService executor = Executors.newCachedThreadPool();
|
||||
Future<Boolean> future = executor.submit(() -> {
|
||||
int status;
|
||||
try (Statement stmt = createStatement()) {
|
||||
ResultSet resultSet = stmt.executeQuery("select server_status()");
|
||||
resultSet.next();
|
||||
status = resultSet.getInt("server_status()");
|
||||
resultSet.close();
|
||||
}
|
||||
return status == 1 ? true : false;
|
||||
});
|
||||
|
||||
boolean status = false;
|
||||
try {
|
||||
if (timeout == 0)
|
||||
status = future.get();
|
||||
else
|
||||
status = future.get(timeout, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
} catch (TimeoutException e) {
|
||||
future.cancel(true);
|
||||
status = false;
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import java.sql.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrapper {
|
||||
public abstract class AbstractDatabaseMetaData extends WrapperImpl implements DatabaseMetaData {
|
||||
|
||||
private final static String PRODUCT_NAME = "TDengine";
|
||||
private final static String PRODUCT_VESION = "2.0.x.x";
|
||||
|
@ -981,9 +981,7 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrap
|
|||
return getEmptyResultSet();
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
return null;
|
||||
}
|
||||
public abstract Connection getConnection() throws SQLException;
|
||||
|
||||
public boolean supportsSavepoints() throws SQLException {
|
||||
return false;
|
||||
|
@ -1067,6 +1065,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();
|
||||
}
|
||||
|
||||
|
@ -1093,20 +1092,6 @@ public abstract class AbstractDatabaseMetaData implements DatabaseMetaData, Wrap
|
|||
return new EmptyResultSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return iface.isInstance(this);
|
||||
}
|
||||
|
||||
protected ResultSet getCatalogs(Connection conn) throws SQLException {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet();
|
||||
|
|
|
@ -14,41 +14,25 @@
|
|||
*****************************************************************************/
|
||||
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 TSDBJNIConnector connector;
|
||||
private TSDBDatabaseMetaData databaseMetaData;
|
||||
private boolean batchFetch;
|
||||
|
||||
private String catalog = null;
|
||||
public Boolean getBatchFetch() {
|
||||
return this.batchFetch;
|
||||
}
|
||||
|
||||
private TSDBDatabaseMetaData dbMetaData;
|
||||
|
||||
private Properties clientInfoProps = new Properties();
|
||||
|
||||
private int timeoutMilliseconds = 0;
|
||||
|
||||
private boolean batchFetch = false;
|
||||
public void setBatchFetch(Boolean batchFetch) {
|
||||
this.batchFetch = 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 +48,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 +86,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 +98,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 {
|
||||
|
@ -263,253 +112,4 @@ public class TSDBConnection implements Connection {
|
|||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
|
||||
throws SQLException {
|
||||
// This method is implemented in the current way to support Spark
|
||||
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
}
|
||||
|
||||
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
|
||||
}
|
||||
|
||||
return this.prepareStatement(sql);
|
||||
}
|
||||
|
||||
public Boolean getBatchFetch() {
|
||||
return this.batchFetch;
|
||||
}
|
||||
|
||||
public void setBatchFetch(Boolean batchFetch) {
|
||||
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()) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
|
||||
}
|
||||
|
||||
public PreparedStatement prepareStatement(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 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,39 +57,38 @@ public class TSDBDatabaseMetaData extends AbstractDatabaseMetaData {
|
|||
*/
|
||||
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
|
||||
if (conn == null || conn.isClosed()) {
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
return super.getTables(catalog, schemaPattern, tableNamePattern, types, conn);
|
||||
}
|
||||
|
||||
|
||||
public ResultSet getCatalogs() throws SQLException {
|
||||
if (conn == null || conn.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
return super.getCatalogs(conn);
|
||||
}
|
||||
|
||||
public ResultSet getTableTypes() throws SQLException {
|
||||
if (conn == null || conn.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
return super.getTableTypes();
|
||||
}
|
||||
|
||||
public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
|
||||
if (conn == null || conn.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
return super.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern, conn);
|
||||
}
|
||||
|
||||
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
|
||||
if (conn == null || conn.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
return super.getPrimaryKeys(catalog, schema, table, conn);
|
||||
}
|
||||
|
||||
public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
|
||||
if (conn == null || conn.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
return super.getSuperTables(catalog, schemaPattern, tableNamePattern, conn);
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ public class TSDBDriver extends AbstractDriver {
|
|||
* fetch data from native function in a batch model
|
||||
*/
|
||||
public static final String PROPERTY_KEY_BATCH_LOAD = "batchfetch";
|
||||
|
||||
|
||||
private TSDBDatabaseMetaData dbMetaData = null;
|
||||
|
||||
static {
|
||||
|
@ -179,18 +179,18 @@ public class TSDBDriver extends AbstractDriver {
|
|||
while (queryParams.hasMoreElements()) {
|
||||
String oneToken = queryParams.nextToken();
|
||||
String[] pair = oneToken.split("=");
|
||||
|
||||
|
||||
if ((pair[0] != null && pair[0].trim().length() > 0) && (pair[1] != null && pair[1].trim().length() > 0)) {
|
||||
urlProps.setProperty(pair[0].trim(), pair[1].trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// parse Product Name
|
||||
String dbProductName = url.substring(0, beginningOfSlashes);
|
||||
dbProductName = dbProductName.substring(dbProductName.indexOf(":") + 1);
|
||||
dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
|
||||
|
||||
|
||||
// parse database name
|
||||
url = url.substring(beginningOfSlashes + 2);
|
||||
int indexOfSlash = url.indexOf("/");
|
||||
|
@ -200,7 +200,7 @@ public class TSDBDriver extends AbstractDriver {
|
|||
}
|
||||
url = url.substring(0, indexOfSlash);
|
||||
}
|
||||
|
||||
|
||||
// parse port
|
||||
int indexOfColon = url.indexOf(":");
|
||||
if (indexOfColon != -1) {
|
||||
|
@ -209,11 +209,11 @@ public class TSDBDriver extends AbstractDriver {
|
|||
}
|
||||
url = url.substring(0, indexOfColon);
|
||||
}
|
||||
|
||||
|
||||
if (url != null && url.length() > 0 && url.trim().length() > 0) {
|
||||
urlProps.setProperty(TSDBDriver.PROPERTY_KEY_HOST, url);
|
||||
}
|
||||
|
||||
|
||||
this.dbMetaData = new TSDBDatabaseMetaData(urlForMeta, urlProps.getProperty(TSDBDriver.PROPERTY_KEY_USER));
|
||||
return urlProps;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.SQLClientInfoException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.util.HashMap;
|
||||
|
@ -17,6 +18,10 @@ public class TSDBError {
|
|||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_BATCH_IS_EMPTY, "Batch is empty!");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY, "Can not issue data manipulation statements with executeQuery()");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEUPDATE, "Can not issue SELECT via executeUpdate()");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "not a valid sql for executeQuery: (?)");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE, "Database not specified or available");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: (?)");
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "not a valid sql for execute: (?)");
|
||||
|
||||
/**************************************************/
|
||||
TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error");
|
||||
|
@ -58,4 +63,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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@ public class TSDBErrorNumbers {
|
|||
public static final int ERROR_BATCH_IS_EMPTY = 0x2306; //Batch is empty!
|
||||
public static final int ERROR_INVALID_WITH_EXECUTEQUERY = 0x2307; //Can not issue data manipulation statements with executeQuery()
|
||||
public static final int ERROR_INVALID_WITH_EXECUTEUPDATE = 0x2308; //Can not issue SELECT via executeUpdate()
|
||||
public static final int ERROR_INVALID_FOR_EXECUTE_QUERY = 0x2309; //not a valid sql for executeQuery: (SQL)
|
||||
public static final int ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE = 0x2310; //Database not specified or available
|
||||
public static final int ERROR_INVALID_FOR_EXECUTE_UPDATE = 0x2311; //not a valid sql for executeUpdate: (SQL)
|
||||
public static final int ERROR_INVALID_FOR_EXECUTE = 0x2312; //not a valid sql for execute: (SQL)
|
||||
|
||||
public static final int ERROR_UNKNOWN = 0x2350; //unknown error
|
||||
|
||||
|
@ -37,6 +41,11 @@ public class TSDBErrorNumbers {
|
|||
errorNumbers.add(ERROR_RESULTSET_CLOSED);
|
||||
errorNumbers.add(ERROR_INVALID_WITH_EXECUTEQUERY);
|
||||
errorNumbers.add(ERROR_INVALID_WITH_EXECUTEUPDATE);
|
||||
errorNumbers.add(ERROR_INVALID_FOR_EXECUTE_QUERY);
|
||||
errorNumbers.add(ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
||||
errorNumbers.add(ERROR_INVALID_FOR_EXECUTE_UPDATE);
|
||||
errorNumbers.add(ERROR_INVALID_FOR_EXECUTE);
|
||||
|
||||
/*****************************************************/
|
||||
errorNumbers.add(ERROR_SUBSCRIBE_FAILED);
|
||||
errorNumbers.add(ERROR_UNSUPPORTED_ENCODING);
|
||||
|
|
|
@ -16,9 +16,6 @@ package com.taosdata.jdbc;
|
|||
|
||||
import javax.management.OperationsException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class TSDBSubscribe {
|
||||
private TSDBJNIConnector connecter = null;
|
||||
|
@ -36,9 +33,8 @@ public class TSDBSubscribe {
|
|||
/**
|
||||
* consume
|
||||
*
|
||||
* @throws OperationsException, SQLException
|
||||
*/
|
||||
public TSDBResultSet consume() throws OperationsException, SQLException {
|
||||
public TSDBResultSet consume() throws SQLException {
|
||||
if (this.connecter.isClosed()) {
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
}
|
||||
|
|
|
@ -1,34 +1,23 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import com.taosdata.jdbc.TSDBConstants;
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import com.taosdata.jdbc.*;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class RestfulConnection implements Connection {
|
||||
public class RestfulConnection extends AbstractConnection {
|
||||
|
||||
private static final String CONNECTION_IS_CLOSED = "connection is closed.";
|
||||
private static final String AUTO_COMMIT_IS_TRUE = "auto commit is true";
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final Properties props;
|
||||
private volatile String database;
|
||||
private final String url;
|
||||
private volatile String database;
|
||||
/******************************************************/
|
||||
private boolean isClosed;
|
||||
private DatabaseMetaData metadata;
|
||||
private Map<String, Class<?>> typeMap;
|
||||
private Properties clientInfoProps = new Properties();
|
||||
private final DatabaseMetaData metadata;
|
||||
|
||||
public RestfulConnection(String host, String port, Properties props, String database, String url) {
|
||||
this.host = host;
|
||||
this.port = Integer.parseInt(port);
|
||||
this.props = props;
|
||||
this.database = database;
|
||||
this.url = url;
|
||||
this.metadata = new RestfulDatabaseMetaData(url, props.getProperty(TSDBDriver.PROPERTY_KEY_USER), this);
|
||||
|
@ -37,7 +26,7 @@ public class RestfulConnection implements Connection {
|
|||
@Override
|
||||
public Statement createStatement() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);;
|
||||
|
||||
return new RestfulStatement(this, database);
|
||||
}
|
||||
|
@ -45,61 +34,11 @@ public class RestfulConnection implements Connection {
|
|||
@Override
|
||||
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);;
|
||||
//TODO: prepareStatement
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nativeSQL(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
|
||||
//nothing did
|
||||
return sql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
if (!autoCommit)
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAutoCommit() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
if (getAutoCommit())
|
||||
throw new SQLException(AUTO_COMMIT_IS_TRUE);
|
||||
//nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
if (getAutoCommit())
|
||||
throw new SQLException(AUTO_COMMIT_IS_TRUE);
|
||||
//nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
if (isClosed)
|
||||
|
@ -116,356 +55,11 @@ public class RestfulConnection implements Connection {
|
|||
@Override
|
||||
public DatabaseMetaData getMetaData() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);;
|
||||
|
||||
return this.metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCatalog(String catalog) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
synchronized (RestfulConnection.class) {
|
||||
this.database = catalog;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCatalog() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
return this.database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransactionIsolation(int level) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
switch (level) {
|
||||
case Connection.TRANSACTION_NONE:
|
||||
break;
|
||||
case Connection.TRANSACTION_READ_UNCOMMITTED:
|
||||
case Connection.TRANSACTION_READ_COMMITTED:
|
||||
case Connection.TRANSACTION_REPEATABLE_READ:
|
||||
case Connection.TRANSACTION_SERIALIZABLE:
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
default:
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransactionIsolation() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
//Connection.TRANSACTION_NONE specifies that transactions are not supported.
|
||||
return Connection.TRANSACTION_NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLWarning getWarnings() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearWarnings() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
//nothing to do
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
|
||||
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
return createStatement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES);
|
||||
|
||||
return this.prepareStatement(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES);
|
||||
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
|
||||
synchronized (RestfulConnection.class) {
|
||||
if (this.typeMap == null) {
|
||||
this.typeMap = new HashMap<>();
|
||||
}
|
||||
return this.typeMap;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
|
||||
synchronized (RestfulConnection.class) {
|
||||
this.typeMap = map;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHoldability(int holdability) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
if (holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT)
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHoldability() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
if (getAutoCommit())
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
//nothing to do
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Savepoint setSavepoint(String name) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
if (getAutoCommit())
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
//nothing to do
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(Savepoint savepoint) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
if (getAutoCommit())
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
//nothing to do
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
|
||||
if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT)
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
return createStatement(resultSetType, resultSetConcurrency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
|
||||
if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT)
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
return prepareStatement(sql, resultSetType, resultSetConcurrency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clob createClob() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Blob createBlob() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NClob createNClob() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLXML createSQLXML() throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(int timeout) throws SQLException {
|
||||
if (timeout < 0)
|
||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||
// TODO:
|
||||
/* The driver shall submit a query on the connection or use some other mechanism that positively verifies
|
||||
the connection is still valid when this method is called.*/
|
||||
return !isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
||||
if (isClosed)
|
||||
throw new SQLClientInfoException();
|
||||
clientInfoProps.setProperty(name, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientInfo(Properties properties) throws SQLClientInfoException {
|
||||
if (isClosed)
|
||||
throw new SQLClientInfoException();
|
||||
|
||||
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 new SQLClientInfoException();
|
||||
|
||||
return clientInfoProps.getProperty(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties getClientInfo() throws SQLException {
|
||||
if (isClosed)
|
||||
throw new SQLClientInfoException();
|
||||
|
||||
return clientInfoProps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSchema(String schema) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
synchronized (RestfulConnection.class) {
|
||||
this.database = schema;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSchema() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
return this.database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abort(Executor executor) throws SQLException {
|
||||
if (executor == null) {
|
||||
throw new SQLException("Executor can not be null");
|
||||
}
|
||||
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORTED_METHOD_EXCEPTION_MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNetworkTimeout() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return iface.isInstance(this);
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
@ -474,10 +68,6 @@ public class RestfulConnection implements Connection {
|
|||
return port;
|
||||
}
|
||||
|
||||
public Properties getProps() {
|
||||
return props;
|
||||
}
|
||||
|
||||
public String getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
@ -485,4 +75,4 @@ public class RestfulConnection implements Connection {
|
|||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import com.taosdata.jdbc.*;
|
||||
import com.taosdata.jdbc.AbstractDatabaseMetaData;
|
||||
import com.taosdata.jdbc.TSDBError;
|
||||
import com.taosdata.jdbc.TSDBErrorNumbers;
|
||||
|
||||
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 RestfulDatabaseMetaData extends AbstractDatabaseMetaData {
|
||||
|
||||
|
@ -33,11 +35,10 @@ public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData {
|
|||
return RestfulDriver.class.getName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
|
||||
if (connection == null || connection.isClosed()) {
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
return super.getTables(catalog, schemaPattern, tableNamePattern, types, connection);
|
||||
}
|
||||
|
@ -45,14 +46,14 @@ public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData {
|
|||
@Override
|
||||
public ResultSet getCatalogs() throws SQLException {
|
||||
if (connection == null || connection.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
return super.getCatalogs(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getTableTypes() throws SQLException {
|
||||
if (connection == null || connection.isClosed()) {
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
}
|
||||
return super.getTableTypes();
|
||||
}
|
||||
|
@ -60,21 +61,26 @@ public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData {
|
|||
@Override
|
||||
public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
|
||||
if (connection == null || connection.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
return super.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern, connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
|
||||
if (connection == null || connection.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
return super.getPrimaryKeys(catalog, schema, table, connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
|
||||
if (connection == null || connection.isClosed())
|
||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
|
||||
return super.getSuperTables(catalog, schemaPattern, tableNamePattern, connection);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.taosdata.jdbc.AbstractStatement;
|
||||
import com.taosdata.jdbc.TSDBConstants;
|
||||
import com.taosdata.jdbc.TSDBError;
|
||||
import com.taosdata.jdbc.TSDBErrorNumbers;
|
||||
import com.taosdata.jdbc.rs.util.HttpClientPoolUtil;
|
||||
import com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
||||
|
||||
|
@ -63,9 +65,9 @@ public class RestfulStatement extends AbstractStatement {
|
|||
@Override
|
||||
public ResultSet executeQuery(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException("statement already closed");
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
if (!SqlSyntaxValidator.isValidForExecuteQuery(sql))
|
||||
throw new SQLException("not a valid sql for executeQuery: " + sql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "not a valid sql for executeQuery: " + sql);
|
||||
|
||||
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
||||
if (SqlSyntaxValidator.isDatabaseUnspecifiedQuery(sql)) {
|
||||
|
@ -73,7 +75,7 @@ public class RestfulStatement extends AbstractStatement {
|
|||
}
|
||||
|
||||
if (this.database == null || this.database.isEmpty())
|
||||
throw new SQLException("Database not specified or available");
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||
return executeOneQuery(url, sql);
|
||||
}
|
||||
|
@ -81,9 +83,9 @@ public class RestfulStatement extends AbstractStatement {
|
|||
@Override
|
||||
public int executeUpdate(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException("statement already closed");
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql))
|
||||
throw new SQLException("not a valid sql for executeUpdate: " + sql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: " + sql);
|
||||
|
||||
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
||||
if (SqlSyntaxValidator.isDatabaseUnspecifiedUpdate(sql)) {
|
||||
|
@ -91,7 +93,8 @@ public class RestfulStatement extends AbstractStatement {
|
|||
}
|
||||
|
||||
if (this.database == null || this.database.isEmpty())
|
||||
throw new SQLException("Database not specified or available");
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
|
||||
|
||||
HttpClientPoolUtil.execute(url, "use " + this.database);
|
||||
return executeOneUpdate(url, sql);
|
||||
}
|
||||
|
@ -107,9 +110,9 @@ public class RestfulStatement extends AbstractStatement {
|
|||
@Override
|
||||
public boolean execute(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException("Invalid method call on a closed statement.");
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
if (!SqlSyntaxValidator.isValidForExecute(sql))
|
||||
throw new SQLException("not a valid sql for execute: " + sql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "not a valid sql for execute: " + sql);
|
||||
|
||||
//如果执行了use操作应该将当前Statement的catalog设置为新的database
|
||||
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
||||
|
@ -134,7 +137,7 @@ public class RestfulStatement extends AbstractStatement {
|
|||
|
||||
private ResultSet executeOneQuery(String url, String sql) throws SQLException {
|
||||
if (!SqlSyntaxValidator.isValidForExecuteQuery(sql))
|
||||
throw new SQLException("not a select sql for executeQuery: " + sql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "not a valid sql for executeQuery: " + sql);
|
||||
|
||||
// row data
|
||||
String result = HttpClientPoolUtil.execute(url, sql);
|
||||
|
@ -165,7 +168,7 @@ public class RestfulStatement extends AbstractStatement {
|
|||
|
||||
private int executeOneUpdate(String url, String sql) throws SQLException {
|
||||
if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql))
|
||||
throw new SQLException("not a valid sql for executeUpdate: " + sql);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: " + sql);
|
||||
|
||||
String result = HttpClientPoolUtil.execute(url, sql);
|
||||
JSONObject jsonObject = JSON.parseObject(result);
|
||||
|
@ -186,16 +189,16 @@ public class RestfulStatement extends AbstractStatement {
|
|||
|
||||
@Override
|
||||
public int getUpdateCount() throws SQLException {
|
||||
if (isClosed()) {
|
||||
throw new SQLException("Invalid method call on a closed statement.");
|
||||
}
|
||||
if (isClosed())
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
|
||||
return this.affectedRows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBatch(String sql) throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
//TODO:
|
||||
}
|
||||
|
||||
|
@ -213,7 +216,7 @@ public class RestfulStatement extends AbstractStatement {
|
|||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
if (isClosed())
|
||||
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
|
||||
return this.conn;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
public class ConnectionTest {
|
||||
private Connection connection;
|
||||
private Statement statement;
|
||||
private static String host = "127.0.0.1";
|
||||
|
||||
@Test
|
||||
public void testConnection() {
|
||||
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");
|
||||
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
Assert.assertTrue(null != connection);
|
||||
statement = connection.createStatement();
|
||||
Assert.assertTrue(null != statement);
|
||||
statement.close();
|
||||
connection.close();
|
||||
} catch (ClassNotFoundException e) {
|
||||
return;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,423 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.management.OperationsException;
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class TSDBConnectionTest {
|
||||
|
||||
private static final String host = "127.0.0.1";
|
||||
private static Connection conn;
|
||||
|
||||
@Test
|
||||
public void getConnection() {
|
||||
// already test in beforeClass method
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createStatement() {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
ResultSet rs = stmt.executeQuery("select server_status()");
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subscribe() {
|
||||
try {
|
||||
TSDBConnection unwrap = conn.unwrap(TSDBConnection.class);
|
||||
TSDBSubscribe subscribe = unwrap.subscribe("topic1", "select * from log.log", false);
|
||||
TSDBResultSet rs = subscribe.consume();
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
for (int count = 0; count < 10 && rs.next(); count++) {
|
||||
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
||||
String value = rs.getString(i);
|
||||
System.out.print(metaData.getColumnLabel(i) + ":" + value + "\t");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
Assert.assertNotNull(rs);
|
||||
subscribe.close(false);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareStatement() throws SQLException {
|
||||
PreparedStatement pstmt = conn.prepareStatement("select server_status()");
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void prepareCall() throws SQLException {
|
||||
conn.prepareCall("select server_status()");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nativeSQL() throws SQLException {
|
||||
String nativeSQL = conn.nativeSQL("select * from log.log");
|
||||
Assert.assertEquals("select * from log.log", nativeSQL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAutoCommit() throws SQLException {
|
||||
conn.setAutoCommit(true);
|
||||
conn.setAutoCommit(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAutoCommit() throws SQLException {
|
||||
Assert.assertTrue(conn.getAutoCommit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commit() throws SQLException {
|
||||
conn.commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rollback() throws SQLException {
|
||||
conn.rollback();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void close() {
|
||||
// connection will close in afterClass method
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isClosed() throws SQLException {
|
||||
Assert.assertFalse(conn.isClosed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetaData() throws SQLException {
|
||||
DatabaseMetaData meta = conn.getMetaData();
|
||||
Assert.assertNotNull(meta);
|
||||
Assert.assertEquals("com.taosdata.jdbc.TSDBDriver", meta.getDriverName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setReadOnly() throws SQLException {
|
||||
conn.setReadOnly(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReadOnly() throws SQLException {
|
||||
Assert.assertTrue(conn.isReadOnly());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCatalog() throws SQLException {
|
||||
conn.setCatalog("test");
|
||||
Assert.assertEquals("test", conn.getCatalog());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCatalog() throws SQLException {
|
||||
conn.setCatalog("log");
|
||||
Assert.assertEquals("log", conn.getCatalog());
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void setTransactionIsolation() throws SQLException {
|
||||
conn.setTransactionIsolation(Connection.TRANSACTION_NONE);
|
||||
Assert.assertEquals(Connection.TRANSACTION_NONE, conn.getTransactionIsolation());
|
||||
conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTransactionIsolation() throws SQLException {
|
||||
Assert.assertEquals(Connection.TRANSACTION_NONE, conn.getTransactionIsolation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWarnings() throws SQLException {
|
||||
Assert.assertNull(conn.getWarnings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearWarnings() throws SQLException {
|
||||
conn.clearWarnings();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testCreateStatement() throws SQLException {
|
||||
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
ResultSet rs = stmt.executeQuery("select server_status()");
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
|
||||
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareStatement() throws SQLException {
|
||||
PreparedStatement pstmt = conn.prepareStatement("select server_status()",
|
||||
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
|
||||
conn.prepareStatement("select server_status", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareCall() throws SQLException {
|
||||
conn.prepareCall("", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getTypeMap() throws SQLException {
|
||||
conn.getTypeMap();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void setTypeMap() throws SQLException {
|
||||
conn.setTypeMap(null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void setHoldability() throws SQLException {
|
||||
conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
Assert.assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn.getHoldability());
|
||||
conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHoldability() throws SQLException {
|
||||
Assert.assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn.getHoldability());
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void setSavepoint() throws SQLException {
|
||||
conn.setSavepoint();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testSetSavepoint() throws SQLException {
|
||||
conn.setSavepoint(null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testRollback() throws SQLException {
|
||||
conn.rollback(null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void releaseSavepoint() throws SQLException {
|
||||
conn.releaseSavepoint(null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testCreateStatement1() throws SQLException {
|
||||
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
ResultSet rs = stmt.executeQuery("select server_status()");
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
|
||||
conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareStatement1() throws SQLException {
|
||||
PreparedStatement pstmt = conn.prepareStatement("select server_status()",
|
||||
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
|
||||
conn.prepareStatement("select server_status", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareCall1() throws SQLException {
|
||||
conn.prepareCall("", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareStatement2() throws SQLException {
|
||||
Assert.assertNotNull("", Statement.NO_GENERATED_KEYS);
|
||||
conn.prepareStatement("", Statement.RETURN_GENERATED_KEYS);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareStatement3() throws SQLException {
|
||||
conn.prepareStatement("", new int[]{});
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareStatement4() throws SQLException {
|
||||
conn.prepareStatement("", new String[]{});
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createClob() throws SQLException {
|
||||
conn.createClob();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createBlob() throws SQLException {
|
||||
conn.createBlob();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createNClob() throws SQLException {
|
||||
conn.createNClob();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createSQLXML() throws SQLException {
|
||||
conn.createSQLXML();
|
||||
}
|
||||
|
||||
@Test(expected = SQLException.class)
|
||||
public void isValid() throws SQLException {
|
||||
Assert.assertTrue(conn.isValid(10));
|
||||
Assert.assertTrue(conn.isValid(0));
|
||||
conn.isValid(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setClientInfo() throws SQLClientInfoException {
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET, "en_US.UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET, "UTC-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetClientInfo() throws SQLClientInfoException {
|
||||
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.setClientInfo(properties);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getClientInfo() throws SQLException {
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
|
||||
Properties info = conn.getClientInfo();
|
||||
String charset = info.getProperty(TSDBDriver.PROPERTY_KEY_CHARSET);
|
||||
Assert.assertEquals("UTF-8", charset);
|
||||
String locale = info.getProperty(TSDBDriver.PROPERTY_KEY_LOCALE);
|
||||
Assert.assertEquals("en_US.UTF-8", locale);
|
||||
String timezone = info.getProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE);
|
||||
Assert.assertEquals("UTC-8", timezone);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClientInfo() throws SQLException {
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
|
||||
String charset = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET);
|
||||
Assert.assertEquals("UTF-8", charset);
|
||||
String locale = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_LOCALE);
|
||||
Assert.assertEquals("en_US.UTF-8", locale);
|
||||
String timezone = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIME_ZONE);
|
||||
Assert.assertEquals("UTC-8", timezone);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createArrayOf() throws SQLException {
|
||||
conn.createArrayOf("", null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createStruct() throws SQLException {
|
||||
conn.createStruct("", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSchema() throws SQLException {
|
||||
conn.setSchema("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchema() throws SQLException {
|
||||
Assert.assertNull(conn.getSchema());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void abort() throws SQLException {
|
||||
conn.abort(null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void setNetworkTimeout() throws SQLException {
|
||||
conn.setNetworkTimeout(null, 1000);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getNetworkTimeout() throws SQLException {
|
||||
conn.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/log?user=root&password=taosdata", properties);
|
||||
// create test database for test cases
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
stmt.execute("create database if not exists test");
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
try {
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -24,11 +24,10 @@ public class TSDBDriverTest {
|
|||
"jdbc:TAOS://:/test",
|
||||
"jdbc:TAOS://localhost:0/?user=root&password=taosdata"
|
||||
};
|
||||
|
||||
private Connection conn;
|
||||
|
||||
@Test
|
||||
public void testConnectWithJdbcURL() {
|
||||
public void connectWithJdbcURL() {
|
||||
final String url = "jdbc:TAOS://localhost:6030/log?user=root&password=taosdata";
|
||||
try {
|
||||
conn = DriverManager.getConnection(url);
|
||||
|
@ -40,7 +39,7 @@ public class TSDBDriverTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testConnectWithProperties() {
|
||||
public void connectWithProperties() {
|
||||
final String jdbcUrl = "jdbc:TAOS://localhost:6030/log?user=root&password=taosdata";
|
||||
Properties connProps = new Properties();
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
|
@ -56,7 +55,7 @@ public class TSDBDriverTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testConnectWithConfigFile() {
|
||||
public void connectWithConfigFile() {
|
||||
String jdbcUrl = "jdbc:TAOS://:/log?user=root&password=taosdata";
|
||||
Properties connProps = new Properties();
|
||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
|
@ -71,16 +70,6 @@ public class TSDBDriverTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(expected = SQLException.class)
|
||||
public void testAcceptsURL() throws SQLException {
|
||||
Driver driver = new TSDBDriver();
|
||||
for (String url : validURLs) {
|
||||
assertTrue("failure - acceptsURL(\" " + url + " \") should be true", driver.acceptsURL(url));
|
||||
}
|
||||
driver.acceptsURL(null);
|
||||
fail("acceptsURL throws exception when parameter is null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseURL() {
|
||||
TSDBDriver driver = new TSDBDriver();
|
||||
|
@ -121,8 +110,19 @@ public class TSDBDriverTest {
|
|||
assertNull("failure - dbname should be null", actual.getProperty("dbname"));
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = SQLException.class)
|
||||
public void acceptsURL() throws SQLException {
|
||||
Driver driver = new TSDBDriver();
|
||||
for (String url : validURLs) {
|
||||
assertTrue("failure - acceptsURL(\" " + url + " \") should be true", driver.acceptsURL(url));
|
||||
}
|
||||
driver.acceptsURL(null);
|
||||
fail("acceptsURL throws exception when parameter is null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPropertyInfo() throws SQLException {
|
||||
public void getPropertyInfo() throws SQLException {
|
||||
Driver driver = new TSDBDriver();
|
||||
final String url = "jdbc:TAOS://localhost:6030/log?user=root&password=taosdata";
|
||||
Properties connProps = new Properties();
|
||||
|
@ -142,23 +142,23 @@ public class TSDBDriverTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetMajorVersion() {
|
||||
assertEquals("failure - getMajorVersion should be 2", 2, new TSDBDriver().getMajorVersion());
|
||||
public void getMajorVersion() {
|
||||
assertEquals(2, new TSDBDriver().getMajorVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMinorVersion() {
|
||||
assertEquals("failure - getMinorVersion should be 0", 0, new TSDBDriver().getMinorVersion());
|
||||
public void getMinorVersion() {
|
||||
assertEquals(0, new TSDBDriver().getMinorVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbcCompliant() {
|
||||
assertFalse("failure - jdbcCompliant should be false", new TSDBDriver().jdbcCompliant());
|
||||
public void jdbcCompliant() {
|
||||
assertFalse(new TSDBDriver().jdbcCompliant());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParentLogger() throws SQLFeatureNotSupportedException {
|
||||
assertNull("failure - getParentLogger should be be null", new TSDBDriver().getParentLogger());
|
||||
public void getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
assertNull(new TSDBDriver().getParentLogger());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
@ -169,6 +169,4 @@ public class TSDBDriverTest {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
package com.taosdata.jdbc.cases;
|
||||
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import org.junit.*;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
package com.taosdata.jdbc.cases;
|
||||
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
package com.taosdata.jdbc.cases;
|
||||
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
|
@ -1,5 +1,6 @@
|
|||
package com.taosdata.jdbc;
|
||||
package com.taosdata.jdbc.cases;
|
||||
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.FixMethodOrder;
|
|
@ -0,0 +1,406 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import com.taosdata.jdbc.TSDBConnection;
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import com.taosdata.jdbc.TSDBResultSet;
|
||||
import com.taosdata.jdbc.TSDBSubscribe;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.management.OperationsException;
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class RestfulConnectionTest {
|
||||
|
||||
// private static final String host = "127.0.0.1";
|
||||
private static final String host = "master";
|
||||
private static Connection conn;
|
||||
|
||||
@Test
|
||||
public void getConnection() {
|
||||
// already test in beforeClass method
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createStatement() {
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
ResultSet rs = stmt.executeQuery("select server_status()");
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prepareStatement() throws SQLException {
|
||||
PreparedStatement pstmt = conn.prepareStatement("select server_status()");
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void prepareCall() throws SQLException {
|
||||
conn.prepareCall("select server_status()");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nativeSQL() throws SQLException {
|
||||
String nativeSQL = conn.nativeSQL("select * from log.log");
|
||||
Assert.assertEquals("select * from log.log", nativeSQL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAutoCommit() throws SQLException {
|
||||
conn.setAutoCommit(true);
|
||||
conn.setAutoCommit(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAutoCommit() throws SQLException {
|
||||
Assert.assertTrue(conn.getAutoCommit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void commit() throws SQLException {
|
||||
conn.commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rollback() throws SQLException {
|
||||
conn.rollback();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void close() {
|
||||
// connection will close in afterClass method
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isClosed() throws SQLException {
|
||||
Assert.assertFalse(conn.isClosed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetaData() throws SQLException {
|
||||
DatabaseMetaData meta = conn.getMetaData();
|
||||
Assert.assertNotNull(meta);
|
||||
Assert.assertEquals("com.taosdata.jdbc.rs.RestfulDriver", meta.getDriverName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setReadOnly() throws SQLException {
|
||||
conn.setReadOnly(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReadOnly() throws SQLException {
|
||||
Assert.assertTrue(conn.isReadOnly());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCatalog() throws SQLException {
|
||||
conn.setCatalog("test");
|
||||
Assert.assertEquals("test", conn.getCatalog());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCatalog() throws SQLException {
|
||||
conn.setCatalog("log");
|
||||
Assert.assertEquals("log", conn.getCatalog());
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void setTransactionIsolation() throws SQLException {
|
||||
conn.setTransactionIsolation(Connection.TRANSACTION_NONE);
|
||||
Assert.assertEquals(Connection.TRANSACTION_NONE, conn.getTransactionIsolation());
|
||||
conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTransactionIsolation() throws SQLException {
|
||||
Assert.assertEquals(Connection.TRANSACTION_NONE, conn.getTransactionIsolation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWarnings() throws SQLException {
|
||||
Assert.assertNull(conn.getWarnings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearWarnings() throws SQLException {
|
||||
conn.clearWarnings();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testCreateStatement() throws SQLException {
|
||||
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
ResultSet rs = stmt.executeQuery("select server_status()");
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
|
||||
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareStatement() throws SQLException {
|
||||
PreparedStatement pstmt = conn.prepareStatement("select server_status()",
|
||||
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
|
||||
conn.prepareStatement("select server_status", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareCall() throws SQLException {
|
||||
conn.prepareCall("", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getTypeMap() throws SQLException {
|
||||
conn.getTypeMap();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void setTypeMap() throws SQLException {
|
||||
conn.setTypeMap(null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void setHoldability() throws SQLException {
|
||||
conn.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
Assert.assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn.getHoldability());
|
||||
conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHoldability() throws SQLException {
|
||||
Assert.assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, conn.getHoldability());
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void setSavepoint() throws SQLException {
|
||||
conn.setSavepoint();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testSetSavepoint() throws SQLException {
|
||||
conn.setSavepoint(null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testRollback() throws SQLException {
|
||||
conn.rollback(null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void releaseSavepoint() throws SQLException {
|
||||
conn.releaseSavepoint(null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testCreateStatement1() throws SQLException {
|
||||
Statement stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
ResultSet rs = stmt.executeQuery("select server_status()");
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
|
||||
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareStatement1() throws SQLException {
|
||||
PreparedStatement pstmt = conn.prepareStatement("select server_status()",
|
||||
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
rs.next();
|
||||
int status = rs.getInt("server_status()");
|
||||
Assert.assertEquals(1, status);
|
||||
|
||||
conn.prepareStatement("select server_status", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareCall1() throws SQLException {
|
||||
conn.prepareCall("", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareStatement2() throws SQLException {
|
||||
Assert.assertNotNull("", Statement.NO_GENERATED_KEYS);
|
||||
conn.prepareStatement("", Statement.RETURN_GENERATED_KEYS);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareStatement3() throws SQLException {
|
||||
conn.prepareStatement("", new int[]{});
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void testPrepareStatement4() throws SQLException {
|
||||
conn.prepareStatement("", new String[]{});
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createClob() throws SQLException {
|
||||
conn.createClob();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createBlob() throws SQLException {
|
||||
conn.createBlob();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createNClob() throws SQLException {
|
||||
conn.createNClob();
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createSQLXML() throws SQLException {
|
||||
conn.createSQLXML();
|
||||
}
|
||||
|
||||
@Test(expected = SQLException.class)
|
||||
public void isValid() throws SQLException {
|
||||
Assert.assertTrue(conn.isValid(10));
|
||||
Assert.assertTrue(conn.isValid(0));
|
||||
conn.isValid(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setClientInfo() throws SQLClientInfoException {
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET, "en_US.UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET, "UTC-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetClientInfo() throws SQLClientInfoException {
|
||||
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.setClientInfo(properties);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getClientInfo() throws SQLException {
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
|
||||
Properties info = conn.getClientInfo();
|
||||
String charset = info.getProperty(TSDBDriver.PROPERTY_KEY_CHARSET);
|
||||
Assert.assertEquals("UTF-8", charset);
|
||||
String locale = info.getProperty(TSDBDriver.PROPERTY_KEY_LOCALE);
|
||||
Assert.assertEquals("en_US.UTF-8", locale);
|
||||
String timezone = info.getProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE);
|
||||
Assert.assertEquals("UTC-8", timezone);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetClientInfo() throws SQLException {
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
conn.setClientInfo(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
|
||||
String charset = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_CHARSET);
|
||||
Assert.assertEquals("UTF-8", charset);
|
||||
String locale = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_LOCALE);
|
||||
Assert.assertEquals("en_US.UTF-8", locale);
|
||||
String timezone = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIME_ZONE);
|
||||
Assert.assertEquals("UTC-8", timezone);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createArrayOf() throws SQLException {
|
||||
conn.createArrayOf("", null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void createStruct() throws SQLException {
|
||||
conn.createStruct("", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSchema() throws SQLException {
|
||||
conn.setSchema("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchema() throws SQLException {
|
||||
Assert.assertNull(conn.getSchema());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void abort() throws SQLException {
|
||||
conn.abort(null);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void setNetworkTimeout() throws SQLException {
|
||||
conn.setNetworkTimeout(null, 1000);
|
||||
}
|
||||
|
||||
@Test(expected = SQLFeatureNotSupportedException.class)
|
||||
public void getNetworkTimeout() throws SQLException {
|
||||
conn.getNetworkTimeout();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unwrap() {
|
||||
try {
|
||||
RestfulConnection restfulConnection = conn.unwrap(RestfulConnection.class);
|
||||
Assert.assertNotNull(restfulConnection);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isWrapperFor() throws SQLException {
|
||||
Assert.assertTrue(conn.isWrapperFor(RestfulConnection.class));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
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-RS://" + host + ":6041/log?user=root&password=taosdata", properties);
|
||||
// create test database for test cases
|
||||
try (Statement stmt = conn.createStatement()) {
|
||||
stmt.execute("create database if not exists test");
|
||||
}
|
||||
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
try {
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,984 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import com.taosdata.jdbc.TSDBDriver;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class RestfulDatabaseMetaDataTest {
|
||||
// private static final String host = "master";
|
||||
private static final String host = "127.0.0.1";
|
||||
private static final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
|
||||
private static Connection connection;
|
||||
private static RestfulDatabaseMetaData metaData;
|
||||
|
||||
@Test
|
||||
public void unwrap() throws SQLException {
|
||||
RestfulDatabaseMetaData unwrap = metaData.unwrap(RestfulDatabaseMetaData.class);
|
||||
Assert.assertNotNull(unwrap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isWrapperFor() throws SQLException {
|
||||
Assert.assertTrue(metaData.isWrapperFor(RestfulDatabaseMetaData.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allProceduresAreCallable() throws SQLException {
|
||||
Assert.assertFalse(metaData.allProceduresAreCallable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allTablesAreSelectable() throws SQLException {
|
||||
Assert.assertFalse(metaData.allTablesAreSelectable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getURL() throws SQLException {
|
||||
Assert.assertEquals(url, metaData.getURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUserName() throws SQLException {
|
||||
Assert.assertEquals("root", metaData.getUserName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReadOnly() throws SQLException {
|
||||
Assert.assertFalse(metaData.isReadOnly());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullsAreSortedHigh() throws SQLException {
|
||||
Assert.assertFalse(metaData.nullsAreSortedHigh());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullsAreSortedLow() throws SQLException {
|
||||
Assert.assertTrue(metaData.nullsAreSortedLow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullsAreSortedAtStart() throws SQLException {
|
||||
Assert.assertTrue(metaData.nullsAreSortedAtStart());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullsAreSortedAtEnd() throws SQLException {
|
||||
Assert.assertFalse(metaData.nullsAreSortedAtEnd());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDatabaseProductName() throws SQLException {
|
||||
Assert.assertEquals("TDengine", metaData.getDatabaseProductName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDatabaseProductVersion() throws SQLException {
|
||||
Assert.assertEquals("2.0.x.x", metaData.getDatabaseProductVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDriverName() throws SQLException {
|
||||
Assert.assertEquals("com.taosdata.jdbc.rs.RestfulDriver", metaData.getDriverName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDriverVersion() throws SQLException {
|
||||
Assert.assertEquals("2.0.x", metaData.getDriverVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDriverMajorVersion() {
|
||||
Assert.assertEquals(2, metaData.getDriverMajorVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDriverMinorVersion() {
|
||||
Assert.assertEquals(0, metaData.getDriverMinorVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesLocalFiles() throws SQLException {
|
||||
Assert.assertFalse(metaData.usesLocalFiles());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usesLocalFilePerTable() throws SQLException {
|
||||
Assert.assertFalse(metaData.usesLocalFilePerTable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsMixedCaseIdentifiers() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsMixedCaseIdentifiers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storesUpperCaseIdentifiers() throws SQLException {
|
||||
Assert.assertFalse(metaData.storesUpperCaseIdentifiers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storesLowerCaseIdentifiers() throws SQLException {
|
||||
Assert.assertTrue(metaData.storesLowerCaseIdentifiers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storesMixedCaseIdentifiers() throws SQLException {
|
||||
Assert.assertFalse(metaData.storesMixedCaseIdentifiers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsMixedCaseQuotedIdentifiers() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsMixedCaseQuotedIdentifiers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storesUpperCaseQuotedIdentifiers() throws SQLException {
|
||||
Assert.assertFalse(metaData.storesUpperCaseQuotedIdentifiers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storesLowerCaseQuotedIdentifiers() throws SQLException {
|
||||
Assert.assertFalse(metaData.storesLowerCaseQuotedIdentifiers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storesMixedCaseQuotedIdentifiers() throws SQLException {
|
||||
Assert.assertFalse(metaData.storesMixedCaseQuotedIdentifiers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIdentifierQuoteString() throws SQLException {
|
||||
Assert.assertEquals(" ", metaData.getIdentifierQuoteString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSQLKeywords() throws SQLException {
|
||||
Assert.assertEquals(null, metaData.getSQLKeywords());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNumericFunctions() throws SQLException {
|
||||
Assert.assertEquals(null, metaData.getNumericFunctions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStringFunctions() throws SQLException {
|
||||
Assert.assertEquals(null, metaData.getStringFunctions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSystemFunctions() throws SQLException {
|
||||
Assert.assertEquals(null, metaData.getSystemFunctions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTimeDateFunctions() throws SQLException {
|
||||
Assert.assertEquals(null, metaData.getTimeDateFunctions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSearchStringEscape() throws SQLException {
|
||||
Assert.assertEquals(null, metaData.getSearchStringEscape());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExtraNameCharacters() throws SQLException {
|
||||
Assert.assertEquals(null, metaData.getExtraNameCharacters());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsAlterTableWithAddColumn() throws SQLException {
|
||||
Assert.assertTrue(metaData.supportsAlterTableWithAddColumn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsAlterTableWithDropColumn() throws SQLException {
|
||||
Assert.assertTrue(metaData.supportsAlterTableWithDropColumn());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsColumnAliasing() throws SQLException {
|
||||
Assert.assertTrue(metaData.supportsColumnAliasing());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullPlusNonNullIsNull() throws SQLException {
|
||||
Assert.assertFalse(metaData.nullPlusNonNullIsNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsConvert() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsConvert());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportsConvert() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsConvert(1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsTableCorrelationNames() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsTableCorrelationNames());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsDifferentTableCorrelationNames() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsDifferentTableCorrelationNames());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsExpressionsInOrderBy() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsExpressionsInOrderBy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsOrderByUnrelated() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsOrderByUnrelated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsGroupBy() throws SQLException {
|
||||
Assert.assertTrue(metaData.supportsGroupBy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsGroupByUnrelated() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsGroupByUnrelated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsGroupByBeyondSelect() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsGroupByBeyondSelect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsLikeEscapeClause() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsLikeEscapeClause());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsMultipleResultSets() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsMultipleResultSets());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsMultipleTransactions() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsMultipleTransactions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsNonNullableColumns() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsNonNullableColumns());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsMinimumSQLGrammar() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsMinimumSQLGrammar());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsCoreSQLGrammar() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsCoreSQLGrammar());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsExtendedSQLGrammar() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsExtendedSQLGrammar());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsANSI92EntryLevelSQL() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsANSI92EntryLevelSQL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsANSI92IntermediateSQL() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsANSI92IntermediateSQL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsANSI92FullSQL() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsANSI92FullSQL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsIntegrityEnhancementFacility() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsIntegrityEnhancementFacility());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsOuterJoins() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsOuterJoins());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsFullOuterJoins() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsFullOuterJoins());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsLimitedOuterJoins() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsLimitedOuterJoins());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemaTerm() throws SQLException {
|
||||
Assert.assertNull(metaData.getSchemaTerm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProcedureTerm() throws SQLException {
|
||||
Assert.assertNull(metaData.getProcedureTerm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCatalogTerm() throws SQLException {
|
||||
Assert.assertEquals("database", metaData.getCatalogTerm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isCatalogAtStart() throws SQLException {
|
||||
Assert.assertTrue(metaData.isCatalogAtStart());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCatalogSeparator() throws SQLException {
|
||||
Assert.assertEquals(".", metaData.getCatalogSeparator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSchemasInDataManipulation() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsSchemasInDataManipulation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSchemasInProcedureCalls() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsSchemasInProcedureCalls());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSchemasInTableDefinitions() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsSchemasInTableDefinitions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSchemasInIndexDefinitions() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsSchemasInIndexDefinitions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSchemasInPrivilegeDefinitions() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsSchemasInPrivilegeDefinitions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsCatalogsInDataManipulation() throws SQLException {
|
||||
Assert.assertTrue(metaData.supportsCatalogsInDataManipulation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsCatalogsInProcedureCalls() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsCatalogsInProcedureCalls());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsCatalogsInTableDefinitions() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsCatalogsInTableDefinitions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsCatalogsInIndexDefinitions() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsCatalogsInIndexDefinitions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsCatalogsInPrivilegeDefinitions() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsCatalogsInPrivilegeDefinitions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsPositionedDelete() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsPositionedDelete());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsPositionedUpdate() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsPositionedUpdate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSelectForUpdate() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsSelectForUpdate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsStoredProcedures() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsStoredProcedures());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSubqueriesInComparisons() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsSubqueriesInComparisons());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSubqueriesInExists() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsSubqueriesInExists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSubqueriesInIns() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsSubqueriesInIns());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSubqueriesInQuantifieds() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsSubqueriesInQuantifieds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsCorrelatedSubqueries() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsCorrelatedSubqueries());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsUnion() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsUnion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsUnionAll() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsUnionAll());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsOpenCursorsAcrossCommit() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsOpenCursorsAcrossCommit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsOpenCursorsAcrossRollback() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsOpenCursorsAcrossRollback());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsOpenStatementsAcrossCommit() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsOpenStatementsAcrossCommit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsOpenStatementsAcrossRollback() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsOpenStatementsAcrossRollback());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxBinaryLiteralLength() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxBinaryLiteralLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxCharLiteralLength() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxCharLiteralLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxColumnNameLength() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxColumnNameLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxColumnsInGroupBy() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxColumnsInGroupBy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxColumnsInIndex() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxColumnsInIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxColumnsInOrderBy() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxColumnsInOrderBy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxColumnsInSelect() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxColumnsInSelect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxColumnsInTable() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxColumnsInTable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxConnections() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxConnections());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxCursorNameLength() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxCursorNameLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxIndexLength() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxIndexLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxSchemaNameLength() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxSchemaNameLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxProcedureNameLength() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxProcedureNameLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxCatalogNameLength() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxCatalogNameLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxRowSize() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxRowSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesMaxRowSizeIncludeBlobs() throws SQLException {
|
||||
Assert.assertFalse(metaData.doesMaxRowSizeIncludeBlobs());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxStatementLength() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxStatementLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxStatements() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxStatements());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxTableNameLength() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxTableNameLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxTablesInSelect() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxTablesInSelect());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMaxUserNameLength() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getMaxUserNameLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultTransactionIsolation() throws SQLException {
|
||||
Assert.assertEquals(Connection.TRANSACTION_NONE, metaData.getDefaultTransactionIsolation());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsTransactions() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsTransactions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsTransactionIsolationLevel() throws SQLException {
|
||||
Assert.assertTrue(metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_NONE));
|
||||
Assert.assertFalse(metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED));
|
||||
Assert.assertFalse(metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED));
|
||||
Assert.assertFalse(metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ));
|
||||
Assert.assertFalse(metaData.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsDataDefinitionAndDataManipulationTransactions() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsDataDefinitionAndDataManipulationTransactions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsDataManipulationTransactionsOnly() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsDataManipulationTransactionsOnly());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dataDefinitionCausesTransactionCommit() throws SQLException {
|
||||
Assert.assertFalse(metaData.dataDefinitionCausesTransactionCommit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dataDefinitionIgnoredInTransactions() throws SQLException {
|
||||
Assert.assertFalse(metaData.dataDefinitionIgnoredInTransactions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProcedures() throws SQLException {
|
||||
Assert.assertNull(metaData.getProcedures("*", "*", "*"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProcedureColumns() throws SQLException {
|
||||
Assert.assertNull(metaData.getProcedureColumns("*", "*", "*", "*"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTables() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
ResultSet tables = metaData.getTables("log", "", null, null);
|
||||
ResultSetMetaData metaData = tables.getMetaData();
|
||||
while (tables.next()) {
|
||||
System.out.print(metaData.getColumnLabel(1) + ":" + tables.getString(1) + "\t");
|
||||
System.out.print(metaData.getColumnLabel(3) + ":" + tables.getString(3) + "\t");
|
||||
System.out.print(metaData.getColumnLabel(4) + ":" + tables.getString(4) + "\t");
|
||||
System.out.print(metaData.getColumnLabel(5) + ":" + tables.getString(5) + "\n");
|
||||
}
|
||||
System.out.println();
|
||||
Assert.assertNotNull(tables);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSchemas() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getSchemas());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCatalogs() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
|
||||
ResultSet catalogs = metaData.getCatalogs();
|
||||
ResultSetMetaData meta = catalogs.getMetaData();
|
||||
while (catalogs.next()) {
|
||||
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||
System.out.print(meta.getColumnLabel(i) + ": " + catalogs.getString(i));
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTableTypes() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
|
||||
ResultSet tableTypes = metaData.getTableTypes();
|
||||
while (tableTypes.next()) {
|
||||
System.out.println(tableTypes.getString("TABLE_TYPE"));
|
||||
}
|
||||
Assert.assertNotNull(metaData.getTableTypes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getColumns() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
|
||||
ResultSet columns = metaData.getColumns("log", "", "dn", "");
|
||||
ResultSetMetaData meta = columns.getMetaData();
|
||||
while (columns.next()) {
|
||||
System.out.print(meta.getColumnLabel(1) + ": " + columns.getString(1) + "\t");
|
||||
System.out.print(meta.getColumnLabel(3) + ": " + columns.getString(3) + "\t");
|
||||
System.out.print(meta.getColumnLabel(4) + ": " + columns.getString(4) + "\t");
|
||||
System.out.print(meta.getColumnLabel(5) + ": " + columns.getString(5) + "\t");
|
||||
System.out.print(meta.getColumnLabel(6) + ": " + columns.getString(6) + "\t");
|
||||
System.out.print(meta.getColumnLabel(7) + ": " + columns.getString(7) + "\t");
|
||||
System.out.print(meta.getColumnLabel(9) + ": " + columns.getString(9) + "\t");
|
||||
System.out.print(meta.getColumnLabel(10) + ": " + columns.getString(10) + "\t");
|
||||
System.out.print(meta.getColumnLabel(11) + ": " + columns.getString(11) + "\n");
|
||||
System.out.print(meta.getColumnLabel(12) + ": " + columns.getString(12) + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getColumnPrivileges() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getColumnPrivileges("", "", "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTablePrivileges() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getTablePrivileges("", "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBestRowIdentifier() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getBestRowIdentifier("", "", "", 0, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVersionColumns() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getVersionColumns("", "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPrimaryKeys() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
|
||||
ResultSet rs = metaData.getPrimaryKeys("log", "", "dn1");
|
||||
while (rs.next()) {
|
||||
System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME"));
|
||||
System.out.println("COLUMN_NAME: " + rs.getString("COLUMN_NAME"));
|
||||
System.out.println("KEY_SEQ: " + rs.getString("KEY_SEQ"));
|
||||
System.out.println("PK_NAME: " + rs.getString("PK_NAME"));
|
||||
}
|
||||
|
||||
Assert.assertNotNull(rs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getImportedKeys() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getImportedKeys("", "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExportedKeys() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getExportedKeys("", "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCrossReference() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getCrossReference("", "", "", "", "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTypeInfo() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getTypeInfo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIndexInfo() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getIndexInfo("", "", "", false, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsResultSetType() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsResultSetType(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsResultSetConcurrency() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsResultSetConcurrency(0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ownUpdatesAreVisible() throws SQLException {
|
||||
Assert.assertFalse(metaData.ownUpdatesAreVisible(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ownDeletesAreVisible() throws SQLException {
|
||||
Assert.assertFalse(metaData.ownDeletesAreVisible(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ownInsertsAreVisible() throws SQLException {
|
||||
Assert.assertFalse(metaData.ownInsertsAreVisible(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void othersUpdatesAreVisible() throws SQLException {
|
||||
Assert.assertFalse(metaData.othersUpdatesAreVisible(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void othersDeletesAreVisible() throws SQLException {
|
||||
Assert.assertFalse(metaData.othersDeletesAreVisible(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void othersInsertsAreVisible() throws SQLException {
|
||||
Assert.assertFalse(metaData.othersInsertsAreVisible(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatesAreDetected() throws SQLException {
|
||||
Assert.assertFalse(metaData.updatesAreDetected(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deletesAreDetected() throws SQLException {
|
||||
Assert.assertFalse(metaData.deletesAreDetected(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertsAreDetected() throws SQLException {
|
||||
Assert.assertFalse(metaData.insertsAreDetected(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsBatchUpdates() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsBatchUpdates());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUDTs() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getUDTs("", "", "", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getConnection() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getConnection());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsSavepoints() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsSavepoints());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsNamedParameters() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsNamedParameters());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsMultipleOpenResults() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsMultipleOpenResults());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsGetGeneratedKeys() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsGetGeneratedKeys());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSuperTypes() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getSuperTypes("", "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSuperTables() throws SQLException {
|
||||
System.out.println("****************************************************");
|
||||
|
||||
ResultSet rs = metaData.getSuperTables("log", "", "dn1");
|
||||
while (rs.next()) {
|
||||
System.out.println("TABLE_NAME: " + rs.getString("TABLE_NAME"));
|
||||
System.out.println("SUPERTABLE_NAME: " + rs.getString("SUPERTABLE_NAME"));
|
||||
}
|
||||
Assert.assertNotNull(rs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAttributes() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getAttributes("", "", "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsResultSetHoldability() throws SQLException {
|
||||
Assert.assertTrue(metaData.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT));
|
||||
Assert.assertFalse(metaData.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResultSetHoldability() throws SQLException {
|
||||
Assert.assertEquals(1, metaData.getResultSetHoldability());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDatabaseMajorVersion() throws SQLException {
|
||||
Assert.assertEquals(2, metaData.getDatabaseMajorVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDatabaseMinorVersion() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getDatabaseMinorVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getJDBCMajorVersion() throws SQLException {
|
||||
Assert.assertEquals(2, metaData.getJDBCMajorVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getJDBCMinorVersion() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getJDBCMinorVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSQLStateType() throws SQLException {
|
||||
Assert.assertEquals(0, metaData.getSQLStateType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locatorsUpdateCopy() throws SQLException {
|
||||
Assert.assertFalse(metaData.locatorsUpdateCopy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsStatementPooling() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsStatementPooling());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRowIdLifetime() throws SQLException {
|
||||
Assert.assertNull(metaData.getRowIdLifetime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportsStoredFunctionsUsingCallSyntax() throws SQLException {
|
||||
Assert.assertFalse(metaData.supportsStoredFunctionsUsingCallSyntax());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoCommitFailureClosesAllResultSets() throws SQLException {
|
||||
Assert.assertFalse(metaData.autoCommitFailureClosesAllResultSets());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getClientInfoProperties() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getClientInfoProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFunctions() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getFunctions("", "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFunctionColumns() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getFunctionColumns("", "", "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPseudoColumns() throws SQLException {
|
||||
Assert.assertNotNull(metaData.getPseudoColumns("", "", "", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatedKeyAlwaysReturned() throws SQLException {
|
||||
Assert.assertFalse(metaData.generatedKeyAlwaysReturned());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
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");
|
||||
connection = DriverManager.getConnection(url, properties);
|
||||
metaData = connection.getMetaData().unwrap(RestfulDatabaseMetaData.class);
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
try {
|
||||
if (connection != null)
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -67,7 +67,7 @@
|
|||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>2.0.18</version>
|
||||
<version>2.0.19</version>
|
||||
<!-- <scope>system</scope>-->
|
||||
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
|
||||
</dependency>
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.taosdata.taosdemo.components.DataSourceFactory;
|
|||
import com.taosdata.taosdemo.components.JdbcTaosdemoConfig;
|
||||
import com.taosdata.taosdemo.domain.SuperTableMeta;
|
||||
import com.taosdata.taosdemo.service.DatabaseService;
|
||||
import com.taosdata.taosdemo.service.QueryService;
|
||||
import com.taosdata.taosdemo.service.SubTableService;
|
||||
import com.taosdata.taosdemo.service.SuperTableService;
|
||||
import com.taosdata.taosdemo.service.data.SuperTableMetaGenerator;
|
||||
|
@ -34,6 +35,7 @@ public class TaosDemoApplication {
|
|||
final DatabaseService databaseService = new DatabaseService(dataSource);
|
||||
final SuperTableService superTableService = new SuperTableService(dataSource);
|
||||
final SubTableService subTableService = new SubTableService(dataSource);
|
||||
final QueryService queryService = new QueryService(dataSource);
|
||||
// 创建数据库
|
||||
long start = System.currentTimeMillis();
|
||||
Map<String, String> databaseParam = new HashMap<>();
|
||||
|
@ -90,6 +92,11 @@ public class TaosDemoApplication {
|
|||
int affectedRows = subTableService.insertMultiThreads(superTableMeta, threadSize, tableSize, startTime, gap, config);
|
||||
end = System.currentTimeMillis();
|
||||
logger.info("insert " + affectedRows + " rows, time cost: " + (end - start) + " ms");
|
||||
/**********************************************************************************/
|
||||
// 查询
|
||||
|
||||
|
||||
|
||||
/**********************************************************************************/
|
||||
// 删除表
|
||||
if (config.dropTable) {
|
||||
|
|
|
@ -23,7 +23,6 @@ public class DataSourceFactory {
|
|||
properties.load(is);
|
||||
|
||||
HikariConfig config = new HikariConfig();
|
||||
|
||||
if (properties.containsKey("jdbc.driver")) {
|
||||
// String driverName = properties.getProperty("jdbc.driver");
|
||||
// System.out.println(">>> load driver : " + driverName);
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
package com.taosdata.taosdemo.service;
|
||||
|
||||
import com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class QueryService {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
public QueryService(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
/* only select or show SQL Statement is valid for executeQuery */
|
||||
public Boolean[] areValidQueries(String[] sqls) {
|
||||
Boolean[] ret = new Boolean[sqls.length];
|
||||
for (int i = 0; i < sqls.length; i++) {
|
||||
ret[i] = true;
|
||||
if (!SqlSyntaxValidator.isValidForExecuteQuery(sqls[i])) {
|
||||
ret[i] = false;
|
||||
continue;
|
||||
}
|
||||
try (Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement()) {
|
||||
stmt.executeQuery(sqls[i]);
|
||||
} catch (SQLException e) {
|
||||
ret[i] = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String[] generateSuperTableQueries(String dbName) {
|
||||
List<String> sqls = new ArrayList<>();
|
||||
try (Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement()) {
|
||||
stmt.execute("use " + dbName);
|
||||
ResultSet rs = stmt.executeQuery("show stables");
|
||||
while (rs.next()) {
|
||||
String name = rs.getString("name");
|
||||
sqls.add("select count(*) from " + dbName + "." + name);
|
||||
sqls.add("select first(*) from " + dbName + "." + name);
|
||||
sqls.add("select last(*) from " + dbName + "." + name);
|
||||
sqls.add("select last_row(*) from " + dbName + "." + name);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String[] sqlArr = new String[sqls.size()];
|
||||
return sqls.toArray(sqlArr);
|
||||
}
|
||||
|
||||
public void querySuperTable(String[] sqls, int interval, int threadCount, long queryTimes) {
|
||||
List<Thread> threads = IntStream.range(0, threadCount).mapToObj(i -> new Thread(() -> {
|
||||
// do query
|
||||
try (Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement()) {
|
||||
long count = queryTimes;
|
||||
if (count == 0)
|
||||
count = Long.MAX_VALUE;
|
||||
while (count > 0) {
|
||||
for (String sql : sqls) {
|
||||
long start = System.currentTimeMillis();
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
printResultSet(rs);
|
||||
long end = System.currentTimeMillis();
|
||||
long timecost = end - start;
|
||||
if (interval - timecost > 0) {
|
||||
TimeUnit.MILLISECONDS.sleep(interval - timecost);
|
||||
}
|
||||
}
|
||||
count--;
|
||||
}
|
||||
|
||||
} catch (SQLException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
})).collect(Collectors.toList());
|
||||
threads.stream().forEach(Thread::start);
|
||||
for (Thread thread : threads) {
|
||||
try {
|
||||
thread.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printResultSet(ResultSet rs) throws SQLException {
|
||||
ResultSetMetaData meta = rs.getMetaData();
|
||||
while (rs.next()) {
|
||||
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ package com.taosdata.taosdemo.service;
|
|||
|
||||
import com.taosdata.taosdemo.dao.TableMapper;
|
||||
import com.taosdata.taosdemo.domain.TableMeta;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
"password": "taosdata",
|
||||
"databases": "db01",
|
||||
"super_table_query":
|
||||
{"rate":1, "concurrent":1,
|
||||
{"rate":1, "concurrent":1,"time":10000,
|
||||
"sqls": [{"sql": "select count(*) from stb01", "result": "./query_res0.txt"}]
|
||||
},
|
||||
"sub_table_query":
|
||||
"sub_table_query":
|
||||
{"stblname": "stb01", "rate":1, "threads":1,
|
||||
"sqls": [{"sql": "select count(*) from xxxx", "result": "./query_res1.txt"}]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package com.taosdata.taosdemo.service;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class QueryServiceTest {
|
||||
private static QueryService queryService;
|
||||
|
||||
@Test
|
||||
public void areValidQueries() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateSuperTableQueries() {
|
||||
String[] sqls = queryService.generateSuperTableQueries("restful_test");
|
||||
for (String sql : sqls) {
|
||||
System.out.println(sql);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void querySuperTable() {
|
||||
String[] sqls = queryService.generateSuperTableQueries("restful_test");
|
||||
queryService.querySuperTable(sqls, 1000, 10, 10);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws ClassNotFoundException {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setJdbcUrl("jdbc:TAOS://127.0.0.1:6030/?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8");
|
||||
config.setUsername("root");
|
||||
config.setPassword("taosdata");
|
||||
HikariDataSource dataSource = new HikariDataSource(config);
|
||||
queryService = new QueryService(dataSource);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue