From 4c37daff3d9f0e06a6c08145df03073fe812d586 Mon Sep 17 00:00:00 2001 From: zyyang Date: Fri, 25 Dec 2020 16:54:40 +0800 Subject: [PATCH 1/5] change --- src/connector/jdbc/pom.xml | 6 + .../jdbc/AbstractDatabaseMetaData.java | 808 +++++++++++++++ .../java/com/taosdata/jdbc/TSDBConstants.java | 123 +-- .../taosdata/jdbc/rs/RestfulConnection.java | 157 ++- .../jdbc/rs/RestfulDatabaseMetaData.java | 958 +++--------------- .../com/taosdata/jdbc/rs/RestfulDriver.java | 2 +- .../taosdata/jdbc/rs/RestfulResultSet.java | 327 +++--- .../taosdata/jdbc/rs/RestfulStatement.java | 197 ++-- .../jdbc/utils/SqlSyntaxValidator.java | 3 +- .../com/taosdata/jdbc/rs/RestfulJDBCTest.java | 1 + .../java/com/taosdata/jdbc/rs/SQLTest.java | 98 ++ 11 files changed, 1526 insertions(+), 1154 deletions(-) create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 25a36e3a48..61f3f0c1d6 100755 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -73,6 +73,12 @@ 1.2.58 + + mysql + mysql-connector-java + 5.1.49 + + diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java new file mode 100644 index 0000000000..1445be1865 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractDatabaseMetaData.java @@ -0,0 +1,808 @@ +/*************************************************************************** + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + *****************************************************************************/ +package com.taosdata.jdbc; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + +public abstract class AbstractDatabaseMetaData implements DatabaseMetaData { + + private final static String PRODUCT_NAME = "TDengine"; + private final static String PRODUCT_VESION = "2.0.x.x"; + private final static String DRIVER_NAME = "taos-jdbcdriver"; + private final static String DRIVER_VERSION = "2.0.x"; + private final static int DRIVER_MAJAR_VERSION = 2; + private final static int DRIVER_MINOR_VERSION = 0; + + public boolean allProceduresAreCallable() throws SQLException { + return false; + } + + public boolean allTablesAreSelectable() throws SQLException { + return false; + } + + public abstract String getURL() throws SQLException; + + public abstract String getUserName() throws SQLException; + + public boolean isReadOnly() throws SQLException { + return false; + } + + public boolean nullsAreSortedHigh() throws SQLException { + return false; + } + + public boolean nullsAreSortedLow() throws SQLException { + return !nullsAreSortedHigh(); + } + + public boolean nullsAreSortedAtStart() throws SQLException { + return true; + } + + public boolean nullsAreSortedAtEnd() throws SQLException { + return !nullsAreSortedAtStart(); + } + + public String getDatabaseProductName() throws SQLException { + return PRODUCT_NAME; + } + + public String getDatabaseProductVersion() throws SQLException { + return PRODUCT_VESION; + } + + public String getDriverName() throws SQLException { + return DRIVER_NAME; + } + + public String getDriverVersion() throws SQLException { + return DRIVER_VERSION; + } + + public int getDriverMajorVersion() { + return DRIVER_MAJAR_VERSION; + } + + public int getDriverMinorVersion() { + return DRIVER_MINOR_VERSION; + } + + public boolean usesLocalFiles() throws SQLException { + return false; + } + + public boolean usesLocalFilePerTable() throws SQLException { + return false; + } + + public boolean supportsMixedCaseIdentifiers() throws SQLException { + return false; + } + + public boolean storesUpperCaseIdentifiers() throws SQLException { + return false; + } + + public boolean storesLowerCaseIdentifiers() throws SQLException { + return false; + } + + public boolean storesMixedCaseIdentifiers() throws SQLException { + return false; + } + + public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { + return false; + } + + public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { + return false; + } + + public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { + return false; + } + + public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { + return false; + } + + public String getIdentifierQuoteString() throws SQLException { + return " "; + } + + public String getSQLKeywords() throws SQLException { + return null; + } + + public String getNumericFunctions() throws SQLException { + return null; + } + + public String getStringFunctions() throws SQLException { + return null; + } + + public String getSystemFunctions() throws SQLException { + return null; + } + + public String getTimeDateFunctions() throws SQLException { + return null; + } + + public String getSearchStringEscape() throws SQLException { + return null; + } + + public String getExtraNameCharacters() throws SQLException { + return null; + } + + public boolean supportsAlterTableWithAddColumn() throws SQLException { + return true; + } + + public boolean supportsAlterTableWithDropColumn() throws SQLException { + return true; + } + + public boolean supportsColumnAliasing() throws SQLException { + return true; + } + + public boolean nullPlusNonNullIsNull() throws SQLException { + return false; + } + + public boolean supportsConvert() throws SQLException { + return false; + } + + public boolean supportsConvert(int fromType, int toType) throws SQLException { + return false; + } + + public boolean supportsTableCorrelationNames() throws SQLException { + return false; + } + + public boolean supportsDifferentTableCorrelationNames() throws SQLException { + return false; + } + + public boolean supportsExpressionsInOrderBy() throws SQLException { + return false; + } + + public boolean supportsOrderByUnrelated() throws SQLException { + return false; + } + + public boolean supportsGroupBy() throws SQLException { + return false; + } + + public boolean supportsGroupByUnrelated() throws SQLException { + return false; + } + + public boolean supportsGroupByBeyondSelect() throws SQLException { + return false; + } + + public boolean supportsLikeEscapeClause() throws SQLException { + return false; + } + + public boolean supportsMultipleResultSets() throws SQLException { + return false; + } + + public boolean supportsMultipleTransactions() throws SQLException { + return false; + } + + public boolean supportsNonNullableColumns() throws SQLException { + return false; + } + + public boolean supportsMinimumSQLGrammar() throws SQLException { + return false; + } + + public boolean supportsCoreSQLGrammar() throws SQLException { + return false; + } + + public boolean supportsExtendedSQLGrammar() throws SQLException { + return false; + } + + public boolean supportsANSI92EntryLevelSQL() throws SQLException { + return false; + } + + public boolean supportsANSI92IntermediateSQL() throws SQLException { + return false; + } + + public boolean supportsANSI92FullSQL() throws SQLException { + return false; + } + + public boolean supportsIntegrityEnhancementFacility() throws SQLException { + return false; + } + + public boolean supportsOuterJoins() throws SQLException { + return false; + } + + public boolean supportsFullOuterJoins() throws SQLException { + return false; + } + + public boolean supportsLimitedOuterJoins() throws SQLException { + return false; + } + + public String getSchemaTerm() throws SQLException { + return null; + } + + public String getProcedureTerm() throws SQLException { + return null; + } + + public String getCatalogTerm() throws SQLException { + return "database"; + } + + public boolean isCatalogAtStart() throws SQLException { + return true; + } + + public String getCatalogSeparator() throws SQLException { + return "."; + } + + public boolean supportsSchemasInDataManipulation() throws SQLException { + return false; + } + + public boolean supportsSchemasInProcedureCalls() throws SQLException { + return false; + } + + public boolean supportsSchemasInTableDefinitions() throws SQLException { + return false; + } + + public boolean supportsSchemasInIndexDefinitions() throws SQLException { + return false; + } + + public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { + return false; + } + + public boolean supportsCatalogsInDataManipulation() throws SQLException { + return true; + } + + public boolean supportsCatalogsInProcedureCalls() throws SQLException { + return false; + } + + public boolean supportsCatalogsInTableDefinitions() throws SQLException { + return false; + } + + public boolean supportsCatalogsInIndexDefinitions() throws SQLException { + return false; + } + + public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { + return false; + } + + public boolean supportsPositionedDelete() throws SQLException { + return false; + } + + public boolean supportsPositionedUpdate() throws SQLException { + return false; + } + + public boolean supportsSelectForUpdate() throws SQLException { + return false; + } + + public boolean supportsStoredProcedures() throws SQLException { + return false; + } + + public boolean supportsSubqueriesInComparisons() throws SQLException { + return false; + } + + public boolean supportsSubqueriesInExists() throws SQLException { + return false; + } + + public boolean supportsSubqueriesInIns() throws SQLException { + return false; + } + + public boolean supportsSubqueriesInQuantifieds() throws SQLException { + return false; + } + + public boolean supportsCorrelatedSubqueries() throws SQLException { + return false; + } + + public boolean supportsUnion() throws SQLException { + return false; + } + + public boolean supportsUnionAll() throws SQLException { + return false; + } + + public boolean supportsOpenCursorsAcrossCommit() throws SQLException { + return false; + } + + public boolean supportsOpenCursorsAcrossRollback() throws SQLException { + return false; + } + + public boolean supportsOpenStatementsAcrossCommit() throws SQLException { + return false; + } + + public boolean supportsOpenStatementsAcrossRollback() throws SQLException { + return false; + } + + public int getMaxBinaryLiteralLength() throws SQLException { + return 0; + } + + public int getMaxCharLiteralLength() throws SQLException { + return 0; + } + + public int getMaxColumnNameLength() throws SQLException { + return 0; + } + + public int getMaxColumnsInGroupBy() throws SQLException { + return 0; + } + + public int getMaxColumnsInIndex() throws SQLException { + return 0; + } + + public int getMaxColumnsInOrderBy() throws SQLException { + return 0; + } + + public int getMaxColumnsInSelect() throws SQLException { + return 0; + } + + public int getMaxColumnsInTable() throws SQLException { + return 0; + } + + public int getMaxConnections() throws SQLException { + return 0; + } + + public int getMaxCursorNameLength() throws SQLException { + return 0; + } + + public int getMaxIndexLength() throws SQLException { + return 0; + } + + public int getMaxSchemaNameLength() throws SQLException { + return 0; + } + + public int getMaxProcedureNameLength() throws SQLException { + return 0; + } + + public int getMaxCatalogNameLength() throws SQLException { + return 0; + } + + public int getMaxRowSize() throws SQLException { + return 0; + } + + public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { + return false; + } + + public int getMaxStatementLength() throws SQLException { + return 0; + } + + public int getMaxStatements() throws SQLException { + return 0; + } + + public int getMaxTableNameLength() throws SQLException { + return 0; + } + + public int getMaxTablesInSelect() throws SQLException { + return 0; + } + + public int getMaxUserNameLength() throws SQLException { + return 0; + } + + public int getDefaultTransactionIsolation() throws SQLException { + return 0; + } + + public boolean supportsTransactions() throws SQLException { + return false; + } + + public boolean supportsTransactionIsolationLevel(int level) throws SQLException { + return false; + } + + public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { + return false; + } + + public boolean supportsDataManipulationTransactionsOnly() throws SQLException { + return false; + } + + public boolean dataDefinitionCausesTransactionCommit() throws SQLException { + return false; + } + + public boolean dataDefinitionIgnoredInTransactions() throws SQLException { + return false; + } + + public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) + throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, + String columnNamePattern) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public abstract ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) + throws SQLException; + + public ResultSet getSchemas() throws SQLException { + return getEmptyResultSet(); + } + + public abstract ResultSet getCatalogs() throws SQLException; + + public ResultSet getTableTypes() throws SQLException { + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + + // set up ColumnMetaDataList + List columnMetaDataList = new ArrayList(1); + ColumnMetaData colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(0); + colMetaData.setColName("TABLE_TYPE"); + colMetaData.setColSize(10); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY); + columnMetaDataList.add(colMetaData); + + // set up rowDataList + List rowDataList = new ArrayList(2); + TSDBResultSetRowData rowData = new TSDBResultSetRowData(); + rowData.setString(0, "TABLE"); + rowDataList.add(rowData); + rowData = new TSDBResultSetRowData(); + rowData.setString(0, "STABLE"); + rowDataList.add(rowData); + + resultSet.setColumnMetaDataList(columnMetaDataList); + resultSet.setRowDataList(rowDataList); + return resultSet; + } + + public abstract ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException; + + protected int getNullable(int index, String typeName) { + if (index == 0 && "TIMESTAMP".equals(typeName)) + return DatabaseMetaData.columnNoNulls; + return DatabaseMetaData.columnNullable; + } + + protected int getColumnSize(String typeName, int length) { + switch (typeName) { + case "TIMESTAMP": + return 23; + + default: + return 0; + } + } + + protected int getDecimalDigits(String typeName) { + switch (typeName) { + case "FLOAT": + return 5; + case "DOUBLE": + return 9; + default: + return 0; + } + } + + protected int getDataType(String typeName) { + switch (typeName) { + case "TIMESTAMP": + return Types.TIMESTAMP; + case "INT": + return Types.INTEGER; + case "BIGINT": + return Types.BIGINT; + case "FLOAT": + return Types.FLOAT; + case "DOUBLE": + return Types.DOUBLE; + case "BINARY": + return Types.BINARY; + case "SMALLINT": + return Types.SMALLINT; + case "TINYINT": + return Types.TINYINT; + case "BOOL": + return Types.BOOLEAN; + case "NCHAR": + return Types.NCHAR; + default: + return Types.NULL; + } + } + + public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, + String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getTypeInfo() throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) + throws SQLException { + return getEmptyResultSet(); + } + + public boolean supportsResultSetType(int type) throws SQLException { + return false; + } + + public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { + return false; + } + + public boolean ownUpdatesAreVisible(int type) throws SQLException { + return false; + } + + public boolean ownDeletesAreVisible(int type) throws SQLException { + return false; + } + + public boolean ownInsertsAreVisible(int type) throws SQLException { + return false; + } + + public boolean othersUpdatesAreVisible(int type) throws SQLException { + return false; + } + + public boolean othersDeletesAreVisible(int type) throws SQLException { + return false; + } + + public boolean othersInsertsAreVisible(int type) throws SQLException { + return false; + } + + public boolean updatesAreDetected(int type) throws SQLException { + return false; + } + + public boolean deletesAreDetected(int type) throws SQLException { + return false; + } + + public boolean insertsAreDetected(int type) throws SQLException { + return false; + } + + public boolean supportsBatchUpdates() throws SQLException { + return false; + } + + public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) + throws SQLException { + return getEmptyResultSet(); + } + + public Connection getConnection() throws SQLException { + return null; + } + + public boolean supportsSavepoints() throws SQLException { + return false; + } + + public boolean supportsNamedParameters() throws SQLException { + return false; + } + + public boolean supportsMultipleOpenResults() throws SQLException { + return false; + } + + public boolean supportsGetGeneratedKeys() throws SQLException { + return false; + } + + public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, + String attributeNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public boolean supportsResultSetHoldability(int holdability) throws SQLException { + return false; + } + + public int getResultSetHoldability() throws SQLException { + return 0; + } + + public int getDatabaseMajorVersion() throws SQLException { + return 0; + } + + public int getDatabaseMinorVersion() throws SQLException { + return 0; + } + + public int getJDBCMajorVersion() throws SQLException { + return 0; + } + + public int getJDBCMinorVersion() throws SQLException { + return 0; + } + + public int getSQLStateType() throws SQLException { + return 0; + } + + public boolean locatorsUpdateCopy() throws SQLException { + return false; + } + + public boolean supportsStatementPooling() throws SQLException { + return false; + } + + public RowIdLifetime getRowIdLifetime() throws SQLException { + return null; + } + + public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { + return null; + } + + public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { + return false; + } + + public boolean autoCommitFailureClosesAllResultSets() throws SQLException { + return false; + } + + public ResultSet getClientInfoProperties() throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, + String columnNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, + String columnNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public boolean generatedKeyAlwaysReturned() throws SQLException { + return false; + } + + private ResultSet getEmptyResultSet() { + return new EmptyResultSet(); + } +} \ No newline at end of file diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java index 3940e80930..4f4911aad9 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java @@ -19,68 +19,71 @@ import java.util.Map; public abstract class TSDBConstants { - public static final String DEFAULT_PORT = "6200"; - public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!"; - public static final String INVALID_VARIABLES = "invalid variables"; - public static Map DATATYPE_MAP = null; + public static final String DEFAULT_PORT = "6200"; + public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!"; + public static final String INVALID_VARIABLES = "invalid variables"; + public static Map DATATYPE_MAP = null; - public static final long JNI_NULL_POINTER = 0L; + public static final long JNI_NULL_POINTER = 0L; - public static final int JNI_SUCCESS = 0; - public static final int JNI_TDENGINE_ERROR = -1; - public static final int JNI_CONNECTION_NULL = -2; - public static final int JNI_RESULT_SET_NULL = -3; - public static final int JNI_NUM_OF_FIELDS_0 = -4; - public static final int JNI_SQL_NULL = -5; - public static final int JNI_FETCH_END = -6; - - public static final int TSDB_DATA_TYPE_NULL = 0; - public static final int TSDB_DATA_TYPE_BOOL = 1; - public static final int TSDB_DATA_TYPE_TINYINT = 2; - public static final int TSDB_DATA_TYPE_SMALLINT = 3; - public static final int TSDB_DATA_TYPE_INT = 4; - public static final int TSDB_DATA_TYPE_BIGINT = 5; - public static final int TSDB_DATA_TYPE_FLOAT = 6; - public static final int TSDB_DATA_TYPE_DOUBLE = 7; - public static final int TSDB_DATA_TYPE_BINARY = 8; - public static final int TSDB_DATA_TYPE_TIMESTAMP = 9; - public static final int TSDB_DATA_TYPE_NCHAR = 10; - - public static String WrapErrMsg(String msg) { - return "TDengine Error: " + msg; - } + public static final int JNI_SUCCESS = 0; + public static final int JNI_TDENGINE_ERROR = -1; + public static final int JNI_CONNECTION_NULL = -2; + public static final int JNI_RESULT_SET_NULL = -3; + public static final int JNI_NUM_OF_FIELDS_0 = -4; + public static final int JNI_SQL_NULL = -5; + public static final int JNI_FETCH_END = -6; - public static String FixErrMsg(int code) { - switch (code) { - case JNI_TDENGINE_ERROR: - return WrapErrMsg("internal error of database!"); - case JNI_CONNECTION_NULL: - return WrapErrMsg("invalid tdengine connection!"); - case JNI_RESULT_SET_NULL: - return WrapErrMsg("invalid resultset pointer!"); - case JNI_NUM_OF_FIELDS_0: - return WrapErrMsg("invalid num of fields!"); - case JNI_SQL_NULL: - return WrapErrMsg("can't execute empty sql!"); - case JNI_FETCH_END: - return WrapErrMsg("fetch to the end of resultset"); - default: - break; - } - return WrapErrMsg("unkown error!"); - } + public static final int TSDB_DATA_TYPE_NULL = 0; + public static final int TSDB_DATA_TYPE_BOOL = 1; + public static final int TSDB_DATA_TYPE_TINYINT = 2; + public static final int TSDB_DATA_TYPE_SMALLINT = 3; + public static final int TSDB_DATA_TYPE_INT = 4; + public static final int TSDB_DATA_TYPE_BIGINT = 5; + public static final int TSDB_DATA_TYPE_FLOAT = 6; + public static final int TSDB_DATA_TYPE_DOUBLE = 7; + public static final int TSDB_DATA_TYPE_BINARY = 8; + public static final int TSDB_DATA_TYPE_TIMESTAMP = 9; + public static final int TSDB_DATA_TYPE_NCHAR = 10; - static { - DATATYPE_MAP = new HashMap(); - DATATYPE_MAP.put(1, "BOOL"); - DATATYPE_MAP.put(2, "TINYINT"); - DATATYPE_MAP.put(3, "SMALLINT"); - DATATYPE_MAP.put(4, "INT"); - DATATYPE_MAP.put(5, "BIGINT"); - DATATYPE_MAP.put(6, "FLOAT"); - DATATYPE_MAP.put(7, "DOUBLE"); - DATATYPE_MAP.put(8, "BINARY"); - DATATYPE_MAP.put(9, "TIMESTAMP"); - DATATYPE_MAP.put(10, "NCHAR"); - } + // nchar field's max length + public static final int maxFieldSize = 16 * 1024; + + public static String WrapErrMsg(String msg) { + return "TDengine Error: " + msg; + } + + public static String FixErrMsg(int code) { + switch (code) { + case JNI_TDENGINE_ERROR: + return WrapErrMsg("internal error of database!"); + case JNI_CONNECTION_NULL: + return WrapErrMsg("invalid tdengine connection!"); + case JNI_RESULT_SET_NULL: + return WrapErrMsg("invalid resultset pointer!"); + case JNI_NUM_OF_FIELDS_0: + return WrapErrMsg("invalid num of fields!"); + case JNI_SQL_NULL: + return WrapErrMsg("can't execute empty sql!"); + case JNI_FETCH_END: + return WrapErrMsg("fetch to the end of resultset"); + default: + break; + } + return WrapErrMsg("unkown error!"); + } + + static { + DATATYPE_MAP = new HashMap(); + DATATYPE_MAP.put(1, "BOOL"); + DATATYPE_MAP.put(2, "TINYINT"); + DATATYPE_MAP.put(3, "SMALLINT"); + DATATYPE_MAP.put(4, "INT"); + DATATYPE_MAP.put(5, "BIGINT"); + DATATYPE_MAP.put(6, "FLOAT"); + DATATYPE_MAP.put(7, "DOUBLE"); + DATATYPE_MAP.put(8, "BINARY"); + DATATYPE_MAP.put(9, "TIMESTAMP"); + DATATYPE_MAP.put(10, "NCHAR"); + } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java index 6b0937a9b7..125d948989 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java @@ -1,8 +1,11 @@ package com.taosdata.jdbc.rs; import com.taosdata.jdbc.TSDBConstants; +import com.taosdata.jdbc.TSDBDriver; import java.sql.*; +import java.util.Enumeration; +import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.concurrent.Executor; @@ -14,6 +17,11 @@ public class RestfulConnection implements Connection { private final Properties props; private final String database; private final String url; + /******************************************************/ + private boolean isClosed; + private DatabaseMetaData metadata; + private Map> typeMap; + private Properties clientInfoProps = new Properties(); public RestfulConnection(String host, String port, Properties props, String database, String url) { this.host = host; @@ -21,90 +29,94 @@ public class RestfulConnection implements Connection { this.props = props; this.database = database; this.url = url; + this.metadata = new RestfulDatabaseMetaData(url, props.getProperty(TSDBDriver.PROPERTY_KEY_USER), this); } @Override public Statement createStatement() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg("restful TDengine connection is closed.")); + throw new SQLException(TSDBConstants.WrapErrMsg("connection is closed.")); return new RestfulStatement(this, database); } @Override public PreparedStatement prepareStatement(String sql) throws SQLException { - return null; + //TODO: prepareStatement + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public CallableStatement prepareCall(String sql) throws SQLException { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public String nativeSQL(String sql) throws SQLException { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void setAutoCommit(boolean autoCommit) throws SQLException { - + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean getAutoCommit() throws SQLException { - return false; + return true; } @Override public void commit() throws SQLException { - + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void rollback() throws SQLException { - + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void close() throws SQLException { - + if (isClosed) + return; + //TODO: release all resources + isClosed = true; } @Override public boolean isClosed() throws SQLException { - return false; + return isClosed; } @Override public DatabaseMetaData getMetaData() throws SQLException { //TODO: RestfulDatabaseMetaData is not implemented - return new RestfulDatabaseMetaData(); + return this.metadata; } @Override public void setReadOnly(boolean readOnly) throws SQLException { - + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isReadOnly() throws SQLException { - return false; + return true; } @Override public void setCatalog(String catalog) throws SQLException { - + //nothing to do } @Override public String getCatalog() throws SQLException { - return null; + return this.database; } @Override public void setTransactionIsolation(int level) throws SQLException { - //transaction is not supported - throw new SQLFeatureNotSupportedException("transactions are not supported"); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } /** @@ -118,179 +130,212 @@ public class RestfulConnection implements Connection { @Override public SQLWarning getWarnings() throws SQLException { - //TODO: getWarnings not implemented return null; } @Override public void clearWarnings() throws SQLException { - throw new SQLFeatureNotSupportedException("clearWarnings not supported."); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { - return null; + if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) { + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return createStatement(); } @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - return null; + if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) { + throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES); + } + if (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 { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Map> getTypeMap() throws SQLException { - return null; + synchronized (RestfulConnection.class) { + if (this.typeMap == null) { + this.typeMap = new HashMap>(); + } + return this.typeMap; + } } @Override public void setTypeMap(Map> map) throws SQLException { - + synchronized (RestfulConnection.class) { + this.typeMap = map; + } } @Override public void setHoldability(int holdability) throws SQLException { - + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getHoldability() throws SQLException { - return 0; + return ResultSet.HOLD_CURSORS_OVER_COMMIT; } @Override public Savepoint setSavepoint() throws SQLException { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Savepoint setSavepoint(String name) throws SQLException { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void rollback(Savepoint savepoint) throws SQLException { - + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void releaseSavepoint(Savepoint savepoint) throws SQLException { - + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return null; + if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return createStatement(resultSetType, resultSetConcurrency); } @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return null; + if (resultSetHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT) + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return prepareStatement(sql, resultSetType, resultSetConcurrency); } @Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Clob createClob() throws SQLException { - //TODO: not supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Blob createBlob() throws SQLException { - //TODO: not supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public NClob createNClob() throws SQLException { - //TODO: not supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public SQLXML createSQLXML() throws SQLException { - //TODO: not supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isValid(int timeout) throws SQLException { - return false; + 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 { - + clientInfoProps.setProperty(name, value); } @Override public void setClientInfo(Properties properties) throws SQLClientInfoException { - + for (Enumeration enumer = properties.keys(); enumer.hasMoreElements(); ) { + String name = (String) enumer.nextElement(); + clientInfoProps.put(name, properties.getProperty(name)); + } } @Override public String getClientInfo(String name) throws SQLException { - return null; + return clientInfoProps.getProperty(name); } @Override public Properties getClientInfo() throws SQLException { - return null; + return clientInfoProps; } @Override public Array createArrayOf(String typeName, Object[] elements) throws SQLException { - //TODO: not supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { - //TODO: not supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void setSchema(String schema) throws SQLException { - + //nothing to do } @Override public String getSchema() throws SQLException { - return null; + 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 { - + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaData.java index 2b4d7899fa..21d2c6402f 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDatabaseMetaData.java @@ -1,307 +1,32 @@ package com.taosdata.jdbc.rs; +import com.taosdata.jdbc.*; + import java.sql.*; +import java.util.ArrayList; +import java.util.List; -public class RestfulDatabaseMetaData implements DatabaseMetaData { +public class RestfulDatabaseMetaData extends AbstractDatabaseMetaData { - @Override - public boolean allProceduresAreCallable() throws SQLException { - return false; - } - @Override - public boolean allTablesAreSelectable() throws SQLException { - return false; + private final String url; + private final String userName; + private final Connection connection; + + public RestfulDatabaseMetaData(String url, String userName, Connection connection) { + this.url = url; + this.userName = userName; + this.connection = connection; } @Override public String getURL() throws SQLException { - return null; + return this.url; } @Override public String getUserName() throws SQLException { - return null; - } - - @Override - public boolean isReadOnly() throws SQLException { - return false; - } - - @Override - public boolean nullsAreSortedHigh() throws SQLException { - return false; - } - - @Override - public boolean nullsAreSortedLow() throws SQLException { - return false; - } - - @Override - public boolean nullsAreSortedAtStart() throws SQLException { - return false; - } - - @Override - public boolean nullsAreSortedAtEnd() throws SQLException { - return false; - } - - @Override - public String getDatabaseProductName() throws SQLException { - return null; - } - - @Override - public String getDatabaseProductVersion() throws SQLException { - return null; - } - - @Override - public String getDriverName() throws SQLException { - return null; - } - - @Override - public String getDriverVersion() throws SQLException { - return null; - } - - @Override - public int getDriverMajorVersion() { - return 0; - } - - @Override - public int getDriverMinorVersion() { - return 0; - } - - @Override - public boolean usesLocalFiles() throws SQLException { - return false; - } - - @Override - public boolean usesLocalFilePerTable() throws SQLException { - return false; - } - - @Override - public boolean supportsMixedCaseIdentifiers() throws SQLException { - return false; - } - - @Override - public boolean storesUpperCaseIdentifiers() throws SQLException { - return false; - } - - @Override - public boolean storesLowerCaseIdentifiers() throws SQLException { - return false; - } - - @Override - public boolean storesMixedCaseIdentifiers() throws SQLException { - return false; - } - - @Override - public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { - return false; - } - - @Override - public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { - return false; - } - - @Override - public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { - return false; - } - - @Override - public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { - return false; - } - - @Override - public String getIdentifierQuoteString() throws SQLException { - return null; - } - - @Override - public String getSQLKeywords() throws SQLException { - return null; - } - - @Override - public String getNumericFunctions() throws SQLException { - return null; - } - - @Override - public String getStringFunctions() throws SQLException { - return null; - } - - @Override - public String getSystemFunctions() throws SQLException { - return null; - } - - @Override - public String getTimeDateFunctions() throws SQLException { - return null; - } - - @Override - public String getSearchStringEscape() throws SQLException { - return null; - } - - @Override - public String getExtraNameCharacters() throws SQLException { - return null; - } - - @Override - public boolean supportsAlterTableWithAddColumn() throws SQLException { - return false; - } - - @Override - public boolean supportsAlterTableWithDropColumn() throws SQLException { - return false; - } - - @Override - public boolean supportsColumnAliasing() throws SQLException { - return false; - } - - @Override - public boolean nullPlusNonNullIsNull() throws SQLException { - return false; - } - - @Override - public boolean supportsConvert() throws SQLException { - return false; - } - - @Override - public boolean supportsConvert(int fromType, int toType) throws SQLException { - return false; - } - - @Override - public boolean supportsTableCorrelationNames() throws SQLException { - return false; - } - - @Override - public boolean supportsDifferentTableCorrelationNames() throws SQLException { - return false; - } - - @Override - public boolean supportsExpressionsInOrderBy() throws SQLException { - return false; - } - - @Override - public boolean supportsOrderByUnrelated() throws SQLException { - return false; - } - - @Override - public boolean supportsGroupBy() throws SQLException { - return false; - } - - @Override - public boolean supportsGroupByUnrelated() throws SQLException { - return false; - } - - @Override - public boolean supportsGroupByBeyondSelect() throws SQLException { - return false; - } - - @Override - public boolean supportsLikeEscapeClause() throws SQLException { - return false; - } - - @Override - public boolean supportsMultipleResultSets() throws SQLException { - return false; - } - - @Override - public boolean supportsMultipleTransactions() throws SQLException { - return false; - } - - @Override - public boolean supportsNonNullableColumns() throws SQLException { - return false; - } - - @Override - public boolean supportsMinimumSQLGrammar() throws SQLException { - return false; - } - - @Override - public boolean supportsCoreSQLGrammar() throws SQLException { - return false; - } - - @Override - public boolean supportsExtendedSQLGrammar() throws SQLException { - return false; - } - - @Override - public boolean supportsANSI92EntryLevelSQL() throws SQLException { - return false; - } - - @Override - public boolean supportsANSI92IntermediateSQL() throws SQLException { - return false; - } - - @Override - public boolean supportsANSI92FullSQL() throws SQLException { - return false; - } - - @Override - public boolean supportsIntegrityEnhancementFacility() throws SQLException { - return false; - } - - @Override - public boolean supportsOuterJoins() throws SQLException { - return false; - } - - @Override - public boolean supportsFullOuterJoins() throws SQLException { - return false; - } - - @Override - public boolean supportsLimitedOuterJoins() throws SQLException { - return false; + return this.userName; } @Override @@ -324,555 +49,150 @@ public class RestfulDatabaseMetaData implements DatabaseMetaData { return false; } - @Override - public String getCatalogSeparator() throws SQLException { - return null; - } - - @Override - public boolean supportsSchemasInDataManipulation() throws SQLException { - return false; - } - - @Override - public boolean supportsSchemasInProcedureCalls() throws SQLException { - return false; - } - - @Override - public boolean supportsSchemasInTableDefinitions() throws SQLException { - return false; - } - - @Override - public boolean supportsSchemasInIndexDefinitions() throws SQLException { - return false; - } - - @Override - public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { - return false; - } - - @Override - public boolean supportsCatalogsInDataManipulation() throws SQLException { - return false; - } - - @Override - public boolean supportsCatalogsInProcedureCalls() throws SQLException { - return false; - } - - @Override - public boolean supportsCatalogsInTableDefinitions() throws SQLException { - return false; - } - - @Override - public boolean supportsCatalogsInIndexDefinitions() throws SQLException { - return false; - } - - @Override - public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { - return false; - } - - @Override - public boolean supportsPositionedDelete() throws SQLException { - return false; - } - - @Override - public boolean supportsPositionedUpdate() throws SQLException { - return false; - } - - @Override - public boolean supportsSelectForUpdate() throws SQLException { - return false; - } - - @Override - public boolean supportsStoredProcedures() throws SQLException { - return false; - } - - @Override - public boolean supportsSubqueriesInComparisons() throws SQLException { - return false; - } - - @Override - public boolean supportsSubqueriesInExists() throws SQLException { - return false; - } - - @Override - public boolean supportsSubqueriesInIns() throws SQLException { - return false; - } - - @Override - public boolean supportsSubqueriesInQuantifieds() throws SQLException { - return false; - } - - @Override - public boolean supportsCorrelatedSubqueries() throws SQLException { - return false; - } - - @Override - public boolean supportsUnion() throws SQLException { - return false; - } - - @Override - public boolean supportsUnionAll() throws SQLException { - return false; - } - - @Override - public boolean supportsOpenCursorsAcrossCommit() throws SQLException { - return false; - } - - @Override - public boolean supportsOpenCursorsAcrossRollback() throws SQLException { - return false; - } - - @Override - public boolean supportsOpenStatementsAcrossCommit() throws SQLException { - return false; - } - - @Override - public boolean supportsOpenStatementsAcrossRollback() throws SQLException { - return false; - } - - @Override - public int getMaxBinaryLiteralLength() throws SQLException { - return 0; - } - - @Override - public int getMaxCharLiteralLength() throws SQLException { - return 0; - } - - @Override - public int getMaxColumnNameLength() throws SQLException { - return 0; - } - - @Override - public int getMaxColumnsInGroupBy() throws SQLException { - return 0; - } - - @Override - public int getMaxColumnsInIndex() throws SQLException { - return 0; - } - - @Override - public int getMaxColumnsInOrderBy() throws SQLException { - return 0; - } - - @Override - public int getMaxColumnsInSelect() throws SQLException { - return 0; - } - - @Override - public int getMaxColumnsInTable() throws SQLException { - return 0; - } - - @Override - public int getMaxConnections() throws SQLException { - return 0; - } - - @Override - public int getMaxCursorNameLength() throws SQLException { - return 0; - } - - @Override - public int getMaxIndexLength() throws SQLException { - return 0; - } - - @Override - public int getMaxSchemaNameLength() throws SQLException { - return 0; - } - - @Override - public int getMaxProcedureNameLength() throws SQLException { - return 0; - } - - @Override - public int getMaxCatalogNameLength() throws SQLException { - return 0; - } - - @Override - public int getMaxRowSize() throws SQLException { - return 0; - } - - @Override - public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { - return false; - } - - @Override - public int getMaxStatementLength() throws SQLException { - return 0; - } - - @Override - public int getMaxStatements() throws SQLException { - return 0; - } - - @Override - public int getMaxTableNameLength() throws SQLException { - return 0; - } - - @Override - public int getMaxTablesInSelect() throws SQLException { - return 0; - } - - @Override - public int getMaxUserNameLength() throws SQLException { - return 0; - } - - @Override - public int getDefaultTransactionIsolation() throws SQLException { - return 0; - } - - @Override - public boolean supportsTransactions() throws SQLException { - return false; - } - - @Override - public boolean supportsTransactionIsolationLevel(int level) throws SQLException { - return false; - } - - @Override - public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { - return false; - } - - @Override - public boolean supportsDataManipulationTransactionsOnly() throws SQLException { - return false; - } - - @Override - public boolean dataDefinitionCausesTransactionCommit() throws SQLException { - return false; - } - - @Override - public boolean dataDefinitionIgnoredInTransactions() throws SQLException { - return false; - } - - @Override - public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) throws SQLException { - return null; - } - - @Override - public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, String columnNamePattern) throws SQLException { - return null; - } - @Override public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException { - return null; - } - - @Override - public ResultSet getSchemas() throws SQLException { - return null; + Statement stmt = null; + if (null != connection && !connection.isClosed()) { + stmt = connection.createStatement(); + if (catalog == null || catalog.length() < 1) { + catalog = connection.getCatalog(); + } + stmt.executeUpdate("use " + catalog); + ResultSet resultSet0 = stmt.executeQuery("show tables"); + GetTablesResultSet getTablesResultSet = new GetTablesResultSet(resultSet0, catalog, schemaPattern, tableNamePattern, types); + return getTablesResultSet; + } else { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } } @Override public ResultSet getCatalogs() throws SQLException { - return null; - } - - @Override - public ResultSet getTableTypes() throws SQLException { - return null; + if (connection != null && !connection.isClosed()) { + Statement stmt = connection.createStatement(); + ResultSet resultSet0 = stmt.executeQuery("show databases"); + CatalogResultSet resultSet = new CatalogResultSet(resultSet0); + return resultSet; + } else { + return new EmptyResultSet(); + } } @Override public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { - return null; + Statement stmt = null; + if (null != connection && !connection.isClosed()) { + stmt = connection.createStatement(); + if (catalog == null || catalog.length() < 1) { + catalog = connection.getCatalog(); + } + stmt.execute("use " + catalog); + + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + // set up ColumnMetaDataList + List columnMetaDataList = new ArrayList<>(24); + columnMetaDataList.add(null); + columnMetaDataList.add(null); + // add TABLE_NAME + ColumnMetaData colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(3); + colMetaData.setColName("TABLE_NAME"); + colMetaData.setColSize(193); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY); + columnMetaDataList.add(colMetaData); + // add COLUMN_NAME + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(4); + colMetaData.setColName("COLUMN_NAME"); + colMetaData.setColSize(65); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY); + columnMetaDataList.add(colMetaData); + // add DATA_TYPE + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(5); + colMetaData.setColName("DATA_TYPE"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); + columnMetaDataList.add(colMetaData); + // add TYPE_NAME + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(6); + colMetaData.setColName("TYPE_NAME"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY); + columnMetaDataList.add(colMetaData); + // add COLUMN_SIZE + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(7); + colMetaData.setColName("COLUMN_SIZE"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); + columnMetaDataList.add(colMetaData); + // add BUFFER_LENGTH ,not used + columnMetaDataList.add(null); + // add DECIMAL_DIGITS + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(9); + colMetaData.setColName("DECIMAL_DIGITS"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); + columnMetaDataList.add(colMetaData); + // add NUM_PREC_RADIX + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(10); + colMetaData.setColName("NUM_PREC_RADIX"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); + columnMetaDataList.add(colMetaData); + // add NULLABLE + colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(11); + colMetaData.setColName("NULLABLE"); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_INT); + columnMetaDataList.add(colMetaData); + + resultSet.setColumnMetaDataList(columnMetaDataList); + + // set up rowDataList + ResultSet resultSet0 = stmt.executeQuery("describe " + tableNamePattern); + List rowDataList = new ArrayList<>(); + int index = 0; + while (resultSet0.next()) { + TSDBResultSetRowData rowData = new TSDBResultSetRowData(24); + // set TABLE_NAME + rowData.setString(2, tableNamePattern); + // set COLUMN_NAME + rowData.setString(3, resultSet0.getString(1)); + // set DATA_TYPE + String typeName = resultSet0.getString(2); + rowData.setInt(4, getDataType(typeName)); + // set TYPE_NAME + rowData.setString(5, typeName); + // set COLUMN_SIZE + int length = resultSet0.getInt(3); + rowData.setInt(6, getColumnSize(typeName, length)); + // set DECIMAL_DIGITS + rowData.setInt(8, getDecimalDigits(typeName)); + // set NUM_PREC_RADIX + rowData.setInt(9, 10); + // set NULLABLE + rowData.setInt(10, getNullable(index, typeName)); + rowDataList.add(rowData); + index++; + } + resultSet.setRowDataList(rowDataList); + + return resultSet; + } else { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } } @Override - public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) throws SQLException { - return null; - } - - @Override - public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { - return null; - } - - @Override - public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) throws SQLException { - return null; - } - - @Override - public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { - return null; - } - - @Override - public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { - return null; - } - - @Override - public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { - return null; - } - - @Override - public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { - return null; - } - - @Override - public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { - return null; - } - - @Override - public ResultSet getTypeInfo() throws SQLException { - return null; - } - - @Override - public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException { - return null; - } - - @Override - public boolean supportsResultSetType(int type) throws SQLException { - return false; - } - - @Override - public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { - return false; - } - - @Override - public boolean ownUpdatesAreVisible(int type) throws SQLException { - return false; - } - - @Override - public boolean ownDeletesAreVisible(int type) throws SQLException { - return false; - } - - @Override - public boolean ownInsertsAreVisible(int type) throws SQLException { - return false; - } - - @Override - public boolean othersUpdatesAreVisible(int type) throws SQLException { - return false; - } - - @Override - public boolean othersDeletesAreVisible(int type) throws SQLException { - return false; - } - - @Override - public boolean othersInsertsAreVisible(int type) throws SQLException { - return false; - } - - @Override - public boolean updatesAreDetected(int type) throws SQLException { - return false; - } - - @Override - public boolean deletesAreDetected(int type) throws SQLException { - return false; - } - - @Override - public boolean insertsAreDetected(int type) throws SQLException { - return false; - } - - @Override - public boolean supportsBatchUpdates() throws SQLException { - return false; - } - - @Override - public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) throws SQLException { - return null; - } - - @Override - public Connection getConnection() throws SQLException { - return null; - } - - @Override - public boolean supportsSavepoints() throws SQLException { - return false; - } - - @Override - public boolean supportsNamedParameters() throws SQLException { - return false; - } - - @Override - public boolean supportsMultipleOpenResults() throws SQLException { - return false; - } - - @Override - public boolean supportsGetGeneratedKeys() throws SQLException { - return false; - } - - @Override - public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException { - return null; - } - - @Override - public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { - return null; - } - - @Override - public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, String attributeNamePattern) throws SQLException { - return null; - } - - @Override - public boolean supportsResultSetHoldability(int holdability) throws SQLException { - return false; - } - - @Override - public int getResultSetHoldability() throws SQLException { + public long getMaxLogicalLobSize() throws SQLException { return 0; } @Override - public int getDatabaseMajorVersion() throws SQLException { - return 0; - } - - @Override - public int getDatabaseMinorVersion() throws SQLException { - return 0; - } - - @Override - public int getJDBCMajorVersion() throws SQLException { - return 0; - } - - @Override - public int getJDBCMinorVersion() throws SQLException { - return 0; - } - - @Override - public int getSQLStateType() throws SQLException { - return 0; - } - - @Override - public boolean locatorsUpdateCopy() throws SQLException { + public boolean supportsRefCursors() throws SQLException { return false; } - @Override - public boolean supportsStatementPooling() throws SQLException { - return false; - } - - @Override - public RowIdLifetime getRowIdLifetime() throws SQLException { - return null; - } - - @Override - public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { - return null; - } - - @Override - public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { - return false; - } - - @Override - public boolean autoCommitFailureClosesAllResultSets() throws SQLException { - return false; - } - - @Override - public ResultSet getClientInfoProperties() throws SQLException { - return null; - } - - @Override - public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException { - return null; - } - - @Override - public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, String columnNamePattern) throws SQLException { - return null; - } - - @Override - public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException { - return null; - } - - @Override - public boolean generatedKeyAlwaysReturned() throws SQLException { - return false; - } @Override public T unwrap(Class iface) throws SQLException { diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java index 9e87cfa680..cb6ff369f2 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java @@ -33,7 +33,7 @@ public class RestfulDriver extends AbstractTaosDriver { return null; Properties props = parseURL(url, info); - String host = props.getProperty(TSDBDriver.PROPERTY_KEY_HOST, "localhost"); + String host = props.getProperty(TSDBDriver.PROPERTY_KEY_HOST); String port = props.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "6041"); String database = props.containsKey(TSDBDriver.PROPERTY_KEY_DBNAME) ? props.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME) : null; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java index c536ae4a89..6c17b92ba4 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java @@ -1,5 +1,6 @@ package com.taosdata.jdbc.rs; +import com.alibaba.fastjson.JSONArray; import com.taosdata.jdbc.TSDBConstants; import org.apache.commons.lang3.StringUtils; @@ -38,6 +39,12 @@ public class RestfulResultSet implements ResultSet { } } + public RestfulResultSet(JSONArray data, JSONArray head) { + for (int i = 0; i < data.size(); i++) { + + } + } + @Override public boolean next() throws SQLException { if (isClosed) throw new SQLException(TSDBConstants.WrapErrMsg("Result is Closed!!!")); @@ -78,7 +85,7 @@ public class RestfulResultSet implements ResultSet { @Override public byte getByte(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override @@ -113,25 +120,25 @@ public class RestfulResultSet implements ResultSet { @Override public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public byte[] getBytes(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Date getDate(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Time getTime(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override @@ -144,19 +151,19 @@ public class RestfulResultSet implements ResultSet { @Override public InputStream getAsciiStream(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public InputStream getUnicodeStream(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public InputStream getBinaryStream(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override @@ -244,20 +251,20 @@ public class RestfulResultSet implements ResultSet { public SQLWarning getWarnings() throws SQLException { return null; //TODO: SQLFeature Not Supported -// throw new SQLFeatureNotSupportedException(); +// throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void clearWarnings() throws SQLException { return; //TODO: SQLFeature Not Supported -// throw new SQLFeatureNotSupportedException(); +// throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public String getCursorName() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override @@ -269,14 +276,14 @@ public class RestfulResultSet implements ResultSet { public Object getObject(int columnIndex) throws SQLException { // return null; //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Object getObject(String columnLabel) throws SQLException { // return null; //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override @@ -287,439 +294,439 @@ public class RestfulResultSet implements ResultSet { @Override public Reader getCharacterStream(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Reader getCharacterStream(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public BigDecimal getBigDecimal(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public BigDecimal getBigDecimal(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isBeforeFirst() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isAfterLast() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isFirst() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isLast() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void beforeFirst() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void afterLast() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean first() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean last() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getRow() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean absolute(int row) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean relative(int rows) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean previous() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void setFetchDirection(int direction) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getFetchDirection() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void setFetchSize(int rows) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getFetchSize() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getType() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getConcurrency() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean rowUpdated() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean rowInserted() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean rowDeleted() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNull(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBoolean(int columnIndex, boolean x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateByte(int columnIndex, byte x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateShort(int columnIndex, short x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateInt(int columnIndex, int x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateLong(int columnIndex, long x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateFloat(int columnIndex, float x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateDouble(int columnIndex, double x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateString(int columnIndex, String x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBytes(int columnIndex, byte[] x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateDate(int columnIndex, Date x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateTime(int columnIndex, Time x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateObject(int columnIndex, Object x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNull(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBoolean(String columnLabel, boolean x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateByte(String columnLabel, byte x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateShort(String columnLabel, short x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateInt(String columnLabel, int x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateLong(String columnLabel, long x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateFloat(String columnLabel, float x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateDouble(String columnLabel, double x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateString(String columnLabel, String x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBytes(String columnLabel, byte[] x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateDate(String columnLabel, Date x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateTime(String columnLabel, Time x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateObject(String columnLabel, Object x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void insertRow() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateRow() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void deleteRow() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void refreshRow() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void cancelRowUpdates() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void moveToInsertRow() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void moveToCurrentRow() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Statement getStatement() throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Object getObject(int columnIndex, Map> map) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Ref getRef(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override @@ -730,145 +737,145 @@ public class RestfulResultSet implements ResultSet { @Override public Clob getClob(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Array getArray(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Object getObject(String columnLabel, Map> map) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Ref getRef(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Blob getBlob(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Clob getClob(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Array getArray(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Date getDate(int columnIndex, Calendar cal) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Date getDate(String columnLabel, Calendar cal) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Time getTime(int columnIndex, Calendar cal) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Time getTime(String columnLabel, Calendar cal) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public URL getURL(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public URL getURL(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateRef(int columnIndex, Ref x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateRef(String columnLabel, Ref x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(int columnIndex, Blob x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(String columnLabel, Blob x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(int columnIndex, Clob x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(String columnLabel, Clob x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateArray(int columnIndex, Array x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateArray(String columnLabel, Array x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public RowId getRowId(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override @@ -879,302 +886,302 @@ public class RestfulResultSet implements ResultSet { @Override public void updateRowId(int columnIndex, RowId x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateRowId(String columnLabel, RowId x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getHoldability() throws SQLException { // return 0; //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isClosed() throws SQLException { return false; //TODO: SQLFeature Not Supported -// throw new SQLFeatureNotSupportedException(); +// throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNString(int columnIndex, String nString) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNString(String columnLabel, String nString) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(int columnIndex, NClob nClob) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(String columnLabel, NClob nClob) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public NClob getNClob(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public NClob getNClob(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public SQLXML getSQLXML(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public SQLXML getSQLXML(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public String getNString(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public String getNString(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Reader getNCharacterStream(int columnIndex) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Reader getNCharacterStream(String columnLabel) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(int columnIndex, Reader reader) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(String columnLabel, Reader reader) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(int columnIndex, Reader reader) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(String columnLabel, Reader reader) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public T getObject(int columnIndex, Class type) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public T getObject(String columnLabel, Class type) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public T unwrap(Class iface) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isWrapperFor(Class iface) throws SQLException { //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java index 30b56638d8..e3a74d1f53 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java @@ -1,6 +1,7 @@ package com.taosdata.jdbc.rs; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.taosdata.jdbc.TSDBConstants; import com.taosdata.jdbc.rs.util.HttpClientPoolUtil; @@ -12,12 +13,17 @@ import java.util.List; public class RestfulStatement implements Statement { + private static final String STATEMENT_CLOSED = "Statement already closed."; private boolean closed; private String database; private final RestfulConnection conn; - public RestfulStatement(RestfulConnection c, String database) { - this.conn = c; + private volatile RestfulResultSet resultSet; + private volatile int affectedRows; + private volatile boolean closeOnCompletion; + + public RestfulStatement(RestfulConnection conn, String database) { + this.conn = conn; this.database = database; } @@ -45,9 +51,7 @@ public class RestfulStatement implements Statement { JSONObject jsonObject = JSON.parseObject(result); if (jsonObject.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + - jsonObject.getString("desc") + "\n" + - "error code: " + jsonObject.getString("code"))); + throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonObject.getString("desc") + "\n" + "error code: " + jsonObject.getString("code"))); } String dataStr = jsonObject.getString("data"); if ("use".equalsIgnoreCase(fields.split(" ")[0])) { @@ -59,13 +63,13 @@ public class RestfulStatement implements Statement { return new RestfulResultSet(dataStr, ""); } if (jsonField.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + - jsonField.getString("desc") + "\n" + - "error code: " + jsonField.getString("code"))); + throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonField.getString("desc") + "\n" + "error code: " + jsonField.getString("code"))); } String fieldData = jsonField.getString("data"); - return new RestfulResultSet(dataStr, fieldData); + this.resultSet = new RestfulResultSet(dataStr, fieldData); + this.affectedRows = 0; + return resultSet; } @Override @@ -78,77 +82,103 @@ public class RestfulStatement implements Statement { if (this.database == null) throw new SQLException("Database not specified or available"); - final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; + final String url = "http://" + conn.getHost().trim() + ":" + conn.getPort() + "/rest/sql"; HttpClientPoolUtil.execute(url, "use " + conn.getDatabase()); String result = HttpClientPoolUtil.execute(url, sql); JSONObject jsonObject = JSON.parseObject(result); if (jsonObject.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + - jsonObject.getString("desc") + "\n" + - "error code: " + jsonObject.getString("code"))); + throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonObject.getString("desc") + "\n" + "error code: " + jsonObject.getString("code"))); } - return Integer.parseInt(jsonObject.getString("rows")); + this.resultSet = null; + this.affectedRows = Integer.parseInt(jsonObject.getString("rows")); + return this.affectedRows; } @Override public void close() throws SQLException { - this.closed = true; + synchronized (RestfulStatement.class) { + if (!isClosed()) + this.closed = true; + } } @Override public int getMaxFieldSize() throws SQLException { - return 0; + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + return TSDBConstants.maxFieldSize; } @Override public void setMaxFieldSize(int max) throws SQLException { - + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + if (max < 0) + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + // nothing to do } @Override public int getMaxRows() throws SQLException { + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); return 0; } @Override public void setMaxRows(int max) throws SQLException { - + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + if (max < 0) + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + // nothing to do } @Override public void setEscapeProcessing(boolean enable) throws SQLException { - + if (isClosed()) + throw new SQLException(RestfulStatement.STATEMENT_CLOSED); } @Override public int getQueryTimeout() throws SQLException { + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); return 0; } @Override public void setQueryTimeout(int seconds) throws SQLException { - + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + if (seconds < 0) + throw new SQLException(TSDBConstants.INVALID_VARIABLES); } @Override public void cancel() throws SQLException { - + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public SQLWarning getWarnings() throws SQLException { - //TODO: getWarnings not Implemented + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); return null; } @Override public void clearWarnings() throws SQLException { - + // nothing to do + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); } @Override public void setCursorName(String name) throws SQLException { - + if (isClosed()) + throw new SQLException(RestfulStatement.STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override @@ -163,129 +193,174 @@ public class RestfulStatement implements Statement { if (this.database == null) throw new SQLException("Database not specified or available"); - final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; - // use database - HttpClientPoolUtil.execute(url, "use " + conn.getDatabase()); - // execute sql - String result = HttpClientPoolUtil.execute(url, sql); - // parse result - JSONObject jsonObject = JSON.parseObject(result); - if (jsonObject.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + - jsonObject.getString("desc") + "\n" + - "error code: " + jsonObject.getString("code"))); + if (SqlSyntaxValidator.isSelectSql(sql)) { + executeQuery(sql); + } else if (SqlSyntaxValidator.isInsertSql(sql)) { + executeUpdate(sql); + } else { + final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; + HttpClientPoolUtil.execute(url, "use " + this.database); + String result = HttpClientPoolUtil.execute(url, sql); + JSONObject jsonObject = JSON.parseObject(result); + if (jsonObject.getString("status").equals("error")) { + throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonObject.getString("desc") + "\n" + "error code: " + jsonObject.getString("code"))); + } + this.resultSet = new RestfulResultSet(jsonObject.getJSONArray("data"), jsonObject.getJSONArray("head")); } + return true; } @Override public ResultSet getResultSet() throws SQLException { - return null; + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + return resultSet; } @Override public int getUpdateCount() throws SQLException { - return 0; + if (isClosed()) { + throw new SQLException("Invalid method call on a closed statement."); + } + return this.affectedRows; } @Override public boolean getMoreResults() throws SQLException { - return false; + return getMoreResults(CLOSE_CURRENT_RESULT); } @Override public void setFetchDirection(int direction) throws SQLException { - + if (direction != ResultSet.FETCH_FORWARD && direction != ResultSet.FETCH_REVERSE && direction != ResultSet.FETCH_UNKNOWN) + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + this.resultSet.setFetchDirection(direction); } @Override public int getFetchDirection() throws SQLException { - return 0; + return this.resultSet.getFetchDirection(); } @Override public void setFetchSize(int rows) throws SQLException { - + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + if (rows < 0) + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + //nothing to do } @Override public int getFetchSize() throws SQLException { + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); return 0; } @Override public int getResultSetConcurrency() throws SQLException { - return 0; + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + return this.resultSet.getConcurrency(); } @Override public int getResultSetType() throws SQLException { - return 0; + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + return this.resultSet.getType(); } @Override public void addBatch(String sql) throws SQLException { - + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + //TODO: } @Override public void clearBatch() throws SQLException { - + //TODO: } @Override public int[] executeBatch() throws SQLException { + //TODO: return new int[0]; } @Override public Connection getConnection() throws SQLException { - return null; + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + return this.conn; } @Override public boolean getMoreResults(int current) throws SQLException { + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + if (resultSet == null) + return false; + +// switch (current) { +// case CLOSE_CURRENT_RESULT: +// resultSet.close(); +// break; +// case KEEP_CURRENT_RESULT: +// break; +// case CLOSE_ALL_RESULTS: +// resultSet.close(); +// break; +// default: +// throw new SQLException(TSDBConstants.INVALID_VARIABLES); +// } +// return next; return false; } @Override public ResultSet getGeneratedKeys() throws SQLException { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - return 0; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - return 0; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int executeUpdate(String sql, String[] columnNames) throws SQLException { - return 0; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - return false; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean execute(String sql, int[] columnIndexes) throws SQLException { - return false; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean execute(String sql, String[] columnNames) throws SQLException { - return false; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getResultSetHoldability() throws SQLException { - return 0; + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + return this.resultSet.getHoldability(); } @Override @@ -295,22 +370,30 @@ public class RestfulStatement implements Statement { @Override public void setPoolable(boolean poolable) throws SQLException { - + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + //nothing to do } @Override public boolean isPoolable() throws SQLException { + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); return false; } @Override public void closeOnCompletion() throws SQLException { - + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + this.closeOnCompletion = true; } @Override public boolean isCloseOnCompletion() throws SQLException { - return false; + if (isClosed()) + throw new SQLException(STATEMENT_CLOSED); + return this.closeOnCompletion; } @Override diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java index 388c3978be..05d02d38f9 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java @@ -31,8 +31,8 @@ public class SqlSyntaxValidator { this.tsdbConnection = (TSDBConnection) connection; } + /* public boolean validateSqlSyntax(String sql) throws SQLException { - boolean res = false; if (tsdbConnection == null || tsdbConnection.isClosed()) { throw new SQLException("invalid connection"); @@ -46,6 +46,7 @@ public class SqlSyntaxValidator { } return res; } + */ public static boolean isValidForExecuteUpdate(String sql) { for (String prefix : updateSQL) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java index d13475b96d..0af6b91532 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulJDBCTest.java @@ -1,5 +1,6 @@ package com.taosdata.jdbc.rs; + import org.junit.*; import org.junit.runners.MethodSorters; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java new file mode 100644 index 0000000000..0c95e81e2b --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java @@ -0,0 +1,98 @@ +package com.taosdata.jdbc.rs; + +import org.junit.*; +import org.junit.runners.MethodSorters; + +import java.sql.*; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class SQLTest { + private static final String host = "master"; + + private static Connection connection; + + @Test + public void testCase001() { + String sql = "create database if not exists restful_test"; + execute(sql); + } + + @Test + public void testCase002() { + String sql = "use restful_test"; + execute(sql); + } + + @Test + public void testCase003() { + String sql = "show databases"; + try (Statement statement = connection.createStatement()) { + statement.execute(sql); + ResultSet resultSet = statement.getResultSet(); + printResult(resultSet); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Test + public void testCase004() { + String sql = "select * from restful_test.weather"; + executeQuery(sql); + } + + + private void execute(String sql) { + try (Statement statement = connection.createStatement()) { + long start = System.currentTimeMillis(); + boolean execute = statement.execute(sql); + long end = System.currentTimeMillis(); + printSql(sql, execute, (end - start)); + } catch (SQLException e) { + System.out.println("ERROR execute SQL ===> " + sql); + e.printStackTrace(); + } + } + + private static void printSql(String sql, boolean succeed, long cost) { + System.out.println("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql); + } + + private void executeQuery(String sql) { + try (Statement statement = connection.createStatement()) { + long start = System.currentTimeMillis(); + ResultSet resultSet = statement.executeQuery(sql); + long end = System.currentTimeMillis(); + printSql(sql, true, (end - start)); + printResult(resultSet); + } catch (SQLException e) { + System.out.println("ERROR execute SQL ===> " + sql); + e.printStackTrace(); + } + } + + private static void printResult(ResultSet resultSet) throws SQLException { + ResultSetMetaData metaData = resultSet.getMetaData(); + while (resultSet.next()) { + StringBuilder sb = new StringBuilder(); + for (int i = 1; i <= metaData.getColumnCount(); i++) { + String columnLabel = metaData.getColumnLabel(i); + String value = resultSet.getString(i); + sb.append(columnLabel + ": " + value + "\t"); + } + System.out.println(sb.toString()); + } + } + + @BeforeClass + public static void before() throws ClassNotFoundException, SQLException { + Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); + connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata"); + } + + @AfterClass + public static void after() throws SQLException { + connection.close(); + } + +} From 646acdb0f6dac0eb6487fdd7ab76dfb376837695 Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 29 Dec 2020 10:43:14 +0800 Subject: [PATCH 2/5] change --- .../taosdata/jdbc/rs/RestfulResultSet.java | 496 ++++++++++-------- .../jdbc/rs/RestfulResultSetMetaData.java | 17 +- .../taosdata/jdbc/rs/RestfulStatement.java | 79 +-- .../jdbc/utils/SqlSyntaxValidator.java | 41 +- .../java/com/taosdata/jdbc/rs/SQLTest.java | 311 ++++++++++- 5 files changed, 637 insertions(+), 307 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java index 6c17b92ba4..6985aebe31 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java @@ -1,8 +1,8 @@ package com.taosdata.jdbc.rs; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.taosdata.jdbc.TSDBConstants; -import org.apache.commons.lang3.StringUtils; import java.io.InputStream; import java.io.Reader; @@ -10,45 +10,104 @@ import java.math.BigDecimal; import java.net.URL; import java.sql.*; import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; import java.util.Map; public class RestfulResultSet implements ResultSet { - private boolean isClosed = false; + private static final String RESULT_SET_IS_CLOSED = "resultSet is closed."; + private volatile boolean isClosed; private int pos = -1; - private ArrayList> data; - private ArrayList fields; - public RestfulResultSet(String str, String fieldData) { - data = new ArrayList<>(); - str = str.substring(2, str.length() - 2); - ArrayList strTemp = new ArrayList<>(Arrays.asList(str.split("],\\["))); - for (String s : strTemp) { - ArrayList curr = new ArrayList<>(Arrays.asList(s.split(","))); - data.add(curr); - } - if (!StringUtils.isBlank(fieldData)) { - fields = new ArrayList<>(); - fieldData = fieldData.substring(2, fieldData.length() - 2); - ArrayList fieldTemp = new ArrayList<>(Arrays.asList(fieldData.split("],\\["))); - for (String s : fieldTemp) { - String curr = Arrays.asList(s.split(",")).get(0); - fields.add(curr.substring(1, curr.length() - 1)); // 去掉双引号 + private final String database; + private final Statement statement; + // data + private ArrayList> resultSet; + // meta + private ArrayList columnNames; + private ArrayList columns; + private RestfulResultSetMetaData metaData; + + /** + * 由一个result的Json构造结果集,对应执行show databases,show tables等这些语句,返回结果集,但无法获取结果集对应的meta,统一当成String处理 + ***/ + public RestfulResultSet(String database, Statement statement, JSONObject resultJson) { + this.database = database; + this.statement = statement; + // row data + JSONArray data = resultJson.getJSONArray("data"); + resultSet = new ArrayList<>(); + int columnIndex = 0; + for (; columnIndex < data.size(); columnIndex++) { + ArrayList oneRow = new ArrayList<>(); + JSONArray one = data.getJSONArray(columnIndex); + for (int j = 0; j < one.size(); j++) { + oneRow.add(one.getString(j)); } + resultSet.add(oneRow); } + + // column only names + columnNames = new ArrayList<>(); + columns = new ArrayList<>(); + JSONArray head = resultJson.getJSONArray("head"); + for (int i = 0; i < head.size(); i++) { + String name = head.getString(i); + columnNames.add(name); + columns.add(new Field(name, "", 0, "")); + } + this.metaData = new RestfulResultSetMetaData(this.database, columns); } - public RestfulResultSet(JSONArray data, JSONArray head) { - for (int i = 0; i < data.size(); i++) { + /** + * 由2个resultSet的JSON构造结果集 + * @param resultJson: 包含data信息的结果集,有sql返回的结果集 + * @param fieldJson: 包含meta信息的结果集,有describe xxx + * **/ + public RestfulResultSet(String database, Statement statement, JSONObject resultJson, JSONObject fieldJson) { + this(database, statement, resultJson); + ArrayList newColumns = new ArrayList<>(); + for (Field column : columns) { + Field field = findField(column.name, fieldJson.getJSONArray("data")); + if (field != null) { + newColumns.add(field); + } else { + newColumns.add(column); + } + } + this.columns = newColumns; + this.metaData = new RestfulResultSetMetaData(this.database, this.columns); + } + public Field findField(String columnName, JSONArray fieldDataJson) { + for (int i = 0; i < fieldDataJson.size(); i++) { + JSONArray field = fieldDataJson.getJSONArray(i); + if (columnName.equalsIgnoreCase(field.getString(0))) { + return new Field(field.getString(0), field.getString(1), field.getInteger(2), field.getString(3)); + } + } + return null; + } + + public class Field { + String name; + String type; + int length; + String note; + + public Field(String name, String type, int length, String note) { + this.name = name; + this.type = type; + this.length = length; + this.note = note; } } @Override public boolean next() throws SQLException { - if (isClosed) throw new SQLException(TSDBConstants.WrapErrMsg("Result is Closed!!!")); - if (pos < data.size() - 1) { + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + if (pos < resultSet.size() - 1) { pos++; return true; } @@ -57,24 +116,34 @@ public class RestfulResultSet implements ResultSet { @Override public void close() throws SQLException { - this.isClosed = true; + synchronized (RestfulResultSet.class) { + this.isClosed = true; + } } @Override public boolean wasNull() throws SQLException { - return data.isEmpty(); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + return resultSet.isEmpty(); } @Override public String getString(int columnIndex) throws SQLException { - if (columnIndex > data.get(pos).size()) { - throw new SQLException(TSDBConstants.WrapErrMsg("Column Index out of range, " + columnIndex + " > " + data.get(pos).size())); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + if (columnIndex > resultSet.get(pos).size()) { + throw new SQLException(TSDBConstants.WrapErrMsg("Column Index out of range, " + columnIndex + " > " + resultSet.get(pos).size())); } - return data.get(pos).get(columnIndex - 1); + return resultSet.get(pos).get(columnIndex - 1).toString(); } @Override public boolean getBoolean(int columnIndex) throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + String result = getString(columnIndex); if (!(result.equals("true") || result.equals("false"))) { throw new SQLException("not boolean value"); @@ -84,65 +153,90 @@ public class RestfulResultSet implements ResultSet { @Override public byte getByte(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public short getShort(int columnIndex) throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + return Short.parseShort(getString(columnIndex)); } @Override public int getInt(int columnIndex) throws SQLException { - String result = getString(columnIndex); - return Integer.parseInt(result); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + return Integer.parseInt(getString(columnIndex)); } @Override public long getLong(int columnIndex) throws SQLException { - String result = getString(columnIndex); - return Long.parseLong(result); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + return Long.parseLong(getString(columnIndex)); } @Override public float getFloat(int columnIndex) throws SQLException { - String result = getString(columnIndex); - return Float.parseFloat(result); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + return Float.parseFloat(getString(columnIndex)); } @Override public double getDouble(int columnIndex) throws SQLException { - String result = getString(columnIndex); - return Double.parseDouble(result); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + return Double.parseDouble(getString(columnIndex)); } + /*******************************************************************************************************************/ + @Override public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public byte[] getBytes(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Date getDate(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Time getTime(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Timestamp getTimestamp(int columnIndex) throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + String strDate = getString(columnIndex); strDate = strDate.substring(1, strDate.length() - 1); return Timestamp.valueOf(strDate); @@ -150,756 +244,748 @@ public class RestfulResultSet implements ResultSet { @Override public InputStream getAsciiStream(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public InputStream getUnicodeStream(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public InputStream getBinaryStream(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public String getString(String columnLabel) throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + return getString(findColumn(columnLabel) + 1); } @Override public boolean getBoolean(String columnLabel) throws SQLException { - return Boolean.parseBoolean(getString(columnLabel)); + return getBoolean(findColumn(columnLabel)); } @Override public byte getByte(String columnLabel) throws SQLException { - return 0; + return getByte(findColumn(columnLabel)); } @Override public short getShort(String columnLabel) throws SQLException { - return Short.parseShort(getString(columnLabel)); + return getShort(findColumn(columnLabel)); } @Override public int getInt(String columnLabel) throws SQLException { - return Integer.parseInt(getString(columnLabel)); + return getInt(findColumn(columnLabel)); } @Override public long getLong(String columnLabel) throws SQLException { - return Long.parseLong(getString(columnLabel)); + return getLong(findColumn(columnLabel)); } @Override public float getFloat(String columnLabel) throws SQLException { - String result = getString(columnLabel); - return Float.parseFloat(result); + return getFloat(findColumn(columnLabel)); } @Override public double getDouble(String columnLabel) throws SQLException { - return Double.parseDouble(getString(columnLabel)); + return getDouble(findColumn(columnLabel)); } @Override public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { - return null; + return getBigDecimal(findColumn(columnLabel)); } @Override public byte[] getBytes(String columnLabel) throws SQLException { - return new byte[0]; + return getBytes(findColumn(columnLabel)); } @Override public Date getDate(String columnLabel) throws SQLException { - return null; + return getDate(findColumn(columnLabel)); } @Override public Time getTime(String columnLabel) throws SQLException { - return null; + return getTime(findColumn(columnLabel)); } @Override public Timestamp getTimestamp(String columnLabel) throws SQLException { - return Timestamp.valueOf(getString(columnLabel)); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + return Timestamp.valueOf(getString(findColumn(columnLabel))); } @Override public InputStream getAsciiStream(String columnLabel) throws SQLException { - return null; + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public InputStream getUnicodeStream(String columnLabel) throws SQLException { - return null; + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public InputStream getBinaryStream(String columnLabel) throws SQLException { - return null; + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public SQLWarning getWarnings() throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); return null; - //TODO: SQLFeature Not Supported -// throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void clearWarnings() throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); return; - //TODO: SQLFeature Not Supported -// throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public String getCursorName() throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public ResultSetMetaData getMetaData() throws SQLException { - return new RestfulResultSetMetaData(fields); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + return this.metaData; } @Override public Object getObject(int columnIndex) throws SQLException { -// return null; - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Object getObject(String columnLabel) throws SQLException { -// return null; - //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return getObject(findColumn(columnLabel)); } @Override public int findColumn(String columnLabel) throws SQLException { - return fields.indexOf(columnLabel); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + return columnNames.indexOf(columnLabel); } @Override public Reader getCharacterStream(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Reader getCharacterStream(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public BigDecimal getBigDecimal(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public BigDecimal getBigDecimal(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isBeforeFirst() throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isAfterLast() throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isFirst() throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isLast() throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void beforeFirst() throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void afterLast() throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean first() throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean last() throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getRow() throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean absolute(int row) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean relative(int rows) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean previous() throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void setFetchDirection(int direction) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + if (direction != ResultSet.FETCH_REVERSE || direction != ResultSet.FETCH_REVERSE || direction != ResultSet.FETCH_UNKNOWN) + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getFetchDirection() throws SQLException { - //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + return ResultSet.FETCH_FORWARD; } @Override public void setFetchSize(int rows) throws SQLException { - //TODO: SQLFeature Not Supported + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + if (rows < 0) + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getFetchSize() throws SQLException { - //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + return this.resultSet.size(); } @Override public int getType() throws SQLException { - //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return ResultSet.TYPE_FORWARD_ONLY; } @Override public int getConcurrency() throws SQLException { - //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return ResultSet.CONCUR_READ_ONLY; } @Override public boolean rowUpdated() throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean rowInserted() throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean rowDeleted() throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNull(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBoolean(int columnIndex, boolean x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateByte(int columnIndex, byte x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateShort(int columnIndex, short x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateInt(int columnIndex, int x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateLong(int columnIndex, long x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateFloat(int columnIndex, float x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateDouble(int columnIndex, double x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateString(int columnIndex, String x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBytes(int columnIndex, byte[] x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateDate(int columnIndex, Date x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateTime(int columnIndex, Time x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateObject(int columnIndex, Object x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNull(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBoolean(String columnLabel, boolean x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateByte(String columnLabel, byte x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateShort(String columnLabel, short x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateInt(String columnLabel, int x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateLong(String columnLabel, long x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateFloat(String columnLabel, float x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateDouble(String columnLabel, double x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateString(String columnLabel, String x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBytes(String columnLabel, byte[] x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateDate(String columnLabel, Date x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateTime(String columnLabel, Time x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateObject(String columnLabel, Object x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void insertRow() throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateRow() throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void deleteRow() throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void refreshRow() throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void cancelRowUpdates() throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void moveToInsertRow() throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void moveToCurrentRow() throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Statement getStatement() throws SQLException { - //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (isClosed()) + throw new SQLException(TSDBConstants.WrapErrMsg(RESULT_SET_IS_CLOSED)); + + return this.statement; } @Override public Object getObject(int columnIndex, Map> map) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Ref getRef(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Blob getBlob(int columnIndex) throws SQLException { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Clob getClob(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Array getArray(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } + /******************************************************************************************************************/ @Override public Object getObject(String columnLabel, Map> map) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Ref getRef(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Blob getBlob(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Clob getClob(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Array getArray(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Date getDate(int columnIndex, Calendar cal) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Date getDate(String columnLabel, Calendar cal) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Time getTime(int columnIndex, Calendar cal) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Time getTime(String columnLabel, Calendar cal) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public URL getURL(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public URL getURL(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateRef(int columnIndex, Ref x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateRef(String columnLabel, Ref x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(int columnIndex, Blob x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(String columnLabel, Blob x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(int columnIndex, Clob x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(String columnLabel, Clob x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateArray(int columnIndex, Array x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateArray(String columnLabel, Array x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public RowId getRowId(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public RowId getRowId(String columnLabel) throws SQLException { - return null; + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateRowId(int columnIndex, RowId x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateRowId(String columnLabel, RowId x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getHoldability() throws SQLException { -// return 0; - //TODO: SQLFeature Not Supported - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return ResultSet.HOLD_CURSORS_OVER_COMMIT; } @Override @@ -911,277 +997,231 @@ public class RestfulResultSet implements ResultSet { @Override public void updateNString(int columnIndex, String nString) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNString(String columnLabel, String nString) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(int columnIndex, NClob nClob) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(String columnLabel, NClob nClob) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public NClob getNClob(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public NClob getNClob(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public SQLXML getSQLXML(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public SQLXML getSQLXML(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public String getNString(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public String getNString(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Reader getNCharacterStream(int columnIndex) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Reader getNCharacterStream(String columnLabel) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(int columnIndex, Reader reader) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateClob(String columnLabel, Reader reader) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(int columnIndex, Reader reader) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void updateNClob(String columnLabel, Reader reader) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public T getObject(int columnIndex, Class type) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public T getObject(String columnLabel, Class type) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public T unwrap(Class iface) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean isWrapperFor(Class iface) throws SQLException { - //TODO: SQLFeature Not Supported throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java index 5dd61391bc..1af3088b17 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSetMetaData.java @@ -2,13 +2,15 @@ package com.taosdata.jdbc.rs; import java.sql.ResultSetMetaData; import java.sql.SQLException; -import java.util.List; +import java.util.ArrayList; public class RestfulResultSetMetaData implements ResultSetMetaData { - private List fields; + private final String database; + private ArrayList fields; - public RestfulResultSetMetaData(List fields) { + public RestfulResultSetMetaData(String database, ArrayList fields) { + this.database = database; this.fields = fields; } @@ -24,6 +26,7 @@ public class RestfulResultSetMetaData implements ResultSetMetaData { @Override public boolean isCaseSensitive(int column) throws SQLException { + //TODO return false; } @@ -39,7 +42,7 @@ public class RestfulResultSetMetaData implements ResultSetMetaData { @Override public int isNullable(int column) throws SQLException { - return 0; + return ResultSetMetaData.columnNullable; } @Override @@ -54,7 +57,7 @@ public class RestfulResultSetMetaData implements ResultSetMetaData { @Override public String getColumnLabel(int column) throws SQLException { - return fields.get(column - 1); + return fields.get(column - 1).name; } @Override @@ -64,7 +67,7 @@ public class RestfulResultSetMetaData implements ResultSetMetaData { @Override public String getSchemaName(int column) throws SQLException { - return null; + return this.database; } @Override @@ -84,7 +87,7 @@ public class RestfulResultSetMetaData implements ResultSetMetaData { @Override public String getCatalogName(int column) throws SQLException { - return null; + return this.database; } @Override diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java index e3a74d1f53..b622673ffa 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java @@ -8,6 +8,7 @@ import com.taosdata.jdbc.rs.util.HttpClientPoolUtil; import com.taosdata.jdbc.utils.SqlSyntaxValidator; import java.sql.*; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -27,6 +28,16 @@ public class RestfulStatement implements Statement { this.database = database; } + private String parseTableIdentifier(String sql) { + List words = Arrays.asList(sql.trim().toLowerCase().split(" ")); + if (words.get(0).equalsIgnoreCase("select")) { + if (words.contains("from")) { + return words.get(words.indexOf("from") + 1); + } + } + return null; + } + @Override public ResultSet executeQuery(String sql) throws SQLException { if (isClosed()) @@ -35,39 +46,27 @@ public class RestfulStatement implements Statement { throw new SQLException("not a select sql for executeQuery: " + sql); final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; + // row data String result = HttpClientPoolUtil.execute(url, sql); - String fields = ""; - List words = Arrays.asList(sql.split(" ")); - if (words.get(0).equalsIgnoreCase("select")) { - int index = 0; - if (words.contains("from")) { - index = words.indexOf("from"); + JSONObject resultJson = JSON.parseObject(result); + if (resultJson.getString("status").equals("error")) { + throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + resultJson.getString("desc") + "\n" + "error code: " + resultJson.getString("code"))); + } + + // parse table name from sql + String tableIdentifier = parseTableIdentifier(sql); + if (tableIdentifier != null) { + // field meta + String fields = HttpClientPoolUtil.execute(url, "DESCRIBE " + tableIdentifier); + JSONObject fieldJson = JSON.parseObject(fields); + if (fieldJson.getString("status").equals("error")) { + throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + fieldJson.getString("desc") + "\n" + "error code: " + fieldJson.getString("code"))); } - if (words.contains("FROM")) { - index = words.indexOf("FROM"); - } - fields = HttpClientPoolUtil.execute(url, "DESCRIBE " + words.get(index + 1)); + this.resultSet = new RestfulResultSet(database, this, resultJson, fieldJson); + } else { + this.resultSet = new RestfulResultSet(database, this, resultJson); } - JSONObject jsonObject = JSON.parseObject(result); - if (jsonObject.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonObject.getString("desc") + "\n" + "error code: " + jsonObject.getString("code"))); - } - String dataStr = jsonObject.getString("data"); - if ("use".equalsIgnoreCase(fields.split(" ")[0])) { - return new RestfulResultSet(dataStr, ""); - } - - JSONObject jsonField = JSON.parseObject(fields); - if (jsonField == null) { - return new RestfulResultSet(dataStr, ""); - } - if (jsonField.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonField.getString("desc") + "\n" + "error code: " + jsonField.getString("code"))); - } - String fieldData = jsonField.getString("data"); - - this.resultSet = new RestfulResultSet(dataStr, fieldData); this.affectedRows = 0; return resultSet; } @@ -195,17 +194,19 @@ public class RestfulStatement implements Statement { if (SqlSyntaxValidator.isSelectSql(sql)) { executeQuery(sql); - } else if (SqlSyntaxValidator.isInsertSql(sql)) { - executeUpdate(sql); - } else { - final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; - HttpClientPoolUtil.execute(url, "use " + this.database); - String result = HttpClientPoolUtil.execute(url, sql); - JSONObject jsonObject = JSON.parseObject(result); - if (jsonObject.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonObject.getString("desc") + "\n" + "error code: " + jsonObject.getString("code"))); + } else if (SqlSyntaxValidator.isShowSql(sql) || SqlSyntaxValidator.isDescribeSql(sql)) { + final String url = "http://" + conn.getHost().trim() + ":" + conn.getPort() + "/rest/sql"; + if (!SqlSyntaxValidator.isShowDatabaseSql(sql)) { + HttpClientPoolUtil.execute(url, "use " + conn.getDatabase()); } - this.resultSet = new RestfulResultSet(jsonObject.getJSONArray("data"), jsonObject.getJSONArray("head")); + String result = HttpClientPoolUtil.execute(url, sql); + JSONObject resultJson = JSON.parseObject(result); + if (resultJson.getString("status").equals("error")) { + throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + resultJson.getString("desc") + "\n" + "error code: " + resultJson.getString("code"))); + } + this.resultSet = new RestfulResultSet(database, this, resultJson); + } else { + executeUpdate(sql); } return true; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java index 05d02d38f9..f0d9234616 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java @@ -15,14 +15,12 @@ package com.taosdata.jdbc.utils; import com.taosdata.jdbc.TSDBConnection; -import com.taosdata.jdbc.TSDBJNIConnector; import java.sql.Connection; -import java.sql.SQLException; public class SqlSyntaxValidator { - private static final String[] updateSQL = {"insert", "update", "delete", "create", "alter", "drop", "show", "describe", "use"}; + private static final String[] updateSQL = {"insert", "update", "delete", "create", "alter", "drop", "show", "describe", "use", "import"}; private static final String[] querySQL = {"select"}; private TSDBConnection tsdbConnection; @@ -31,23 +29,6 @@ public class SqlSyntaxValidator { this.tsdbConnection = (TSDBConnection) connection; } - /* - public boolean validateSqlSyntax(String sql) throws SQLException { - boolean res = false; - if (tsdbConnection == null || tsdbConnection.isClosed()) { - throw new SQLException("invalid connection"); - } else { - TSDBJNIConnector jniConnector = tsdbConnection.getConnection(); - if (jniConnector == null) { - throw new SQLException("jniConnector is null"); - } else { - res = jniConnector.validateCreateTableSql(sql); - } - } - return res; - } - */ - public static boolean isValidForExecuteUpdate(String sql) { for (String prefix : updateSQL) { if (sql.trim().toLowerCase().startsWith(prefix)) @@ -57,18 +38,28 @@ public class SqlSyntaxValidator { } public static boolean isUseSql(String sql) { - return sql.trim().toLowerCase().startsWith(updateSQL[8]) || sql.trim().toLowerCase().matches("create\\s*database.*") || sql.toLowerCase().toLowerCase().matches("drop\\s*database.*"); + return sql.trim().toLowerCase().startsWith("use") || sql.trim().toLowerCase().matches("create\\s*database.*") || sql.toLowerCase().toLowerCase().matches("drop\\s*database.*"); } - public static boolean isUpdateSql(String sql) { - return sql.trim().toLowerCase().startsWith(updateSQL[1]); + public static boolean isShowSql(String sql) { + return sql.trim().toLowerCase().startsWith("show"); } + public static boolean isDescribeSql(String sql) { + return sql.trim().toLowerCase().startsWith("describe"); + } + + public static boolean isInsertSql(String sql) { - return sql.trim().toLowerCase().startsWith(updateSQL[0]); + return sql.trim().toLowerCase().startsWith("insert") || sql.trim().toLowerCase().startsWith("import"); } public static boolean isSelectSql(String sql) { - return sql.trim().toLowerCase().startsWith(querySQL[0]); + return sql.trim().toLowerCase().startsWith("select"); + } + + + public static boolean isShowDatabaseSql(String sql) { + return sql.trim().toLowerCase().matches("show\\s*databases"); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java index 0c95e81e2b..d414bc4b09 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java @@ -1,6 +1,9 @@ package com.taosdata.jdbc.rs; -import org.junit.*; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; import org.junit.runners.MethodSorters; import java.sql.*; @@ -26,6 +29,305 @@ public class SQLTest { @Test public void testCase003() { String sql = "show databases"; + executeWithResult(sql); + } + + @Test + public void testCase004() { + String sql = "show tables"; + executeWithResult(sql); + } + + @Test + public void testCase005() { + String sql = "show stables"; + executeWithResult(sql); + } + + @Test + public void testCase006() { + String sql = "show dnodes"; + executeWithResult(sql); + } + + @Test + public void testCase007() { + String sql = "show vgroups"; + executeWithResult(sql); + } + + @Test + public void testCase008() { + String sql = "drop table if exists restful_test.weather"; + execute(sql); + } + + @Test + public void testCase009() { + String sql = "create table if not exists restful_test.weather(ts timestamp, temperature float) tags(location nchar(64))"; + execute(sql); + } + + @Test + public void testCase010() { + String sql = "create table t1 using restful_test.weather tags('北京')"; + execute(sql); + } + + @Test + public void testCase011() { + String sql = "insert into restful_test.t1 values(now, 22.22)"; + executeUpdate(sql); + } + + @Test + public void testCase012() { + String sql = "insert into restful_test.t1 values('2020-01-01 00:00:00.000', 22.22)"; + executeUpdate(sql); + } + + @Test + public void testCase013() { + String sql = "insert into restful_test.t1 values('2020-01-01 00:01:00.000', 22.22),('2020-01-01 00:02:00.000', 22.22)"; + executeUpdate(sql); + } + + @Test + public void testCase014() { + String sql = "insert into restful_test.t2 using weather tags('上海') values('2020-01-01 00:03:00.000', 22.22)"; + executeUpdate(sql); + } + + @Test + public void testCase015() { + String sql = "insert into restful_test.t2 using weather tags('上海') values('2020-01-01 00:01:00.000', 22.22),('2020-01-01 00:02:00.000', 22.22)"; + executeUpdate(sql); + } + + @Test + public void testCase016() { + String sql = "insert into t1 values('2020-01-01 01:0:00.000', 22.22),('2020-01-01 02:00:00.000', 22.22) t2 values('2020-01-01 01:0:00.000', 33.33),('2020-01-01 02:00:00.000', 33.33)"; + executeUpdate(sql); + } + + @Test + public void testCase017() { + String sql = "Insert into t3 using weather tags('广东') values('2020-01-01 01:0:00.000', 22.22),('2020-01-01 02:00:00.000', 22.22) t4 using weather tags('天津') values('2020-01-01 01:0:00.000', 33.33),('2020-01-01 02:00:00.000', 33.33)"; + executeUpdate(sql); + } + + @Test + public void testCase018() { + String sql = "select * from restful_test.t1"; + executeQuery(sql); + } + + @Test + public void testCase019() { + String sql = "select * from restful_test.weather"; + executeQuery(sql); + } + + @Test + public void testCase020() { + String sql = "select ts, temperature from restful_test.t1"; + executeQuery(sql); + } + + @Test + public void testCase021() { + String sql = "select ts, temperature from restful_test.weather"; + executeQuery(sql); + } + + @Test + public void testCase022() { + String sql = "select temperature, ts from restful_test.t1"; + executeQuery(sql); + } + + @Test + public void testCase023() { + String sql = "select temperature, ts from restful_test.weather"; + executeQuery(sql); + } + + @Test + public void testCase024() { + String sql = "import into restful_test.t5 using weather tags('石家庄') values('2020-01-01 00:01:00.000', 22.22)"; + executeUpdate(sql); + } + + @Test + public void testCase025() { + String sql = "import into restful_test.t6 using weather tags('沈阳') values('2020-01-01 00:01:00.000', 22.22),('2020-01-01 00:02:00.000', 22.22)"; + executeUpdate(sql); + } + + @Test + public void testCase026() { + String sql = "import into restful_test.t7 using weather tags('长沙') values('2020-01-01 00:01:00.000', 22.22) restful_test.t8 using weather tags('吉林') values('2020-01-01 00:01:00.000', 22.22)"; + executeUpdate(sql); + } + + @Test + public void testCase027() { + String sql = "import into restful_test.t9 using weather tags('武汉') values('2020-01-01 00:01:00.000', 22.22) ,('2020-01-02 00:01:00.000', 22.22) restful_test.t10 using weather tags('哈尔滨') values('2020-01-01 00:01:00.000', 22.22),('2020-01-02 00:01:00.000', 22.22)"; + executeUpdate(sql); + } + + @Test + public void testCase028() { + String sql = "select location, temperature, ts from restful_test.weather where temperature > 1"; + executeQuery(sql); + } + + @Test + public void testCase029() { + String sql = "select location, temperature, ts from restful_test.weather where temperature < 1"; + executeQuery(sql); + } + + @Test + public void testCase30() { + String sql = "select location, temperature, ts from restful_test.weather where ts > now"; + executeQuery(sql); + } + + @Test + public void testCase31() { + String sql = "select location, temperature, ts from restful_test.weather where ts < now"; + executeQuery(sql); + } + + @Test + public void testCase32() { + String sql = "select count(*) from restful_test.weather"; + executeQuery(sql); + } + + @Test + public void testCase33() { + String sql = "select first(*) from restful_test.weather"; + executeQuery(sql); + } + + @Test + public void testCase34() { + String sql = "select last(*) from restful_test.weather"; + executeQuery(sql); + } + + @Test + public void testCase35() { + String sql = "select last_row(*) from restful_test.weather"; + executeQuery(sql); + } + + @Test + public void testCase36() { + String sql = "select ts, ts as primary_key from restful_test.weather"; + executeQuery(sql); + } + + + @Test + public void testCase037() { + String sql = "select database()"; + execute("use restful_test"); + executeQuery(sql); + } + + @Test + public void testCase038() { + String sql = "select client_version()"; + executeQuery(sql); + } + + @Test + public void testCase039() { + String sql = "select server_status()"; + executeQuery(sql); + } + + @Test + public void testCase040() { + String sql = "select server_status() as status"; + executeQuery(sql); + } + + @Test + public void testCase041() { + String sql = "select tbname, location from restful_test.weather"; + executeQuery(sql); + } + + @Test + public void testCase042() { + String sql = "select count(tbname) from restful_test.weather"; + executeQuery(sql); + } + + @Test + public void testCase043() { + String sql = "select * from restful_test.weather where ts < now - 1h"; + executeQuery(sql); + } + + @Test + public void testCase044() { + String sql = "select * from restful_test.weather where ts < now - 1h and location like '%'"; + executeQuery(sql); + } + + @Test + public void testCase045() { + String sql = "select * from restful_test.weather where ts < now - 1h order by ts"; + executeQuery(sql); + } + + @Test + public void testCase046() { + String sql = "select last(*) from restful_test.weather where ts < now - 1h group by tbname order by tbname"; + executeQuery(sql); + } + + @Test + public void testCase047() { + String sql = "select * from restful_test.weather limit 2"; + executeQuery(sql); + } + + @Test + public void testCase048() { + String sql = "select * from restful_test.weather limit 2 offset 5"; + executeQuery(sql); + } + + @Test + public void testCase049() { + String sql = "select * from restful_test.t1, restful_test.t3 where t1.ts = t3.ts "; + executeQuery(sql); + } + + @Test + public void testCase050() { + String sql = "select * from restful_test.t1, restful_test.t3 where t1.ts = t3.ts and t1.location = t3.location"; + executeQuery(sql); + } + + private void executeUpdate(String sql) { + try (Statement statement = connection.createStatement()) { + long start = System.currentTimeMillis(); + int affectedRows = statement.executeUpdate(sql); + long end = System.currentTimeMillis(); + System.out.println("[ affected rows : " + affectedRows + " ] time cost: " + (end - start) + " ms, execute statement ====> " + sql); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private void executeWithResult(String sql) { try (Statement statement = connection.createStatement()) { statement.execute(sql); ResultSet resultSet = statement.getResultSet(); @@ -35,13 +337,6 @@ public class SQLTest { } } - @Test - public void testCase004() { - String sql = "select * from restful_test.weather"; - executeQuery(sql); - } - - private void execute(String sql) { try (Statement statement = connection.createStatement()) { long start = System.currentTimeMillis(); From 17b4e8c6c8f372af043d24e3606cb6ec5ae4f510 Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 29 Dec 2020 14:44:46 +0800 Subject: [PATCH 3/5] change --- .../taosdata/jdbc/rs/RestfulResultSet.java | 27 +++++---- .../taosdata/jdbc/rs/RestfulStatement.java | 59 ++++++++++++++----- .../jdbc/rs/util/HttpClientPoolUtil.java | 22 ++----- .../java/com/taosdata/jdbc/rs/SQLTest.java | 20 ++++--- 4 files changed, 79 insertions(+), 49 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java index 6985aebe31..1aa3d5b3ce 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java @@ -11,6 +11,7 @@ import java.net.URL; import java.sql.*; import java.util.ArrayList; import java.util.Calendar; +import java.util.List; import java.util.Map; public class RestfulResultSet implements ResultSet { @@ -59,15 +60,17 @@ public class RestfulResultSet implements ResultSet { } /** - * 由2个resultSet的JSON构造结果集 + * 由多个resultSet的JSON构造结果集 + * * @param resultJson: 包含data信息的结果集,有sql返回的结果集 - * @param fieldJson: 包含meta信息的结果集,有describe xxx - * **/ - public RestfulResultSet(String database, Statement statement, JSONObject resultJson, JSONObject fieldJson) { + * @param fieldJson: 包含多个(最多2个)meta信息的结果集,有describe xxx + **/ + public RestfulResultSet(String database, Statement statement, JSONObject resultJson, List fieldJson) { this(database, statement, resultJson); ArrayList newColumns = new ArrayList<>(); + for (Field column : columns) { - Field field = findField(column.name, fieldJson.getJSONArray("data")); + Field field = findField(column.name, fieldJson); if (field != null) { newColumns.add(field); } else { @@ -78,13 +81,17 @@ public class RestfulResultSet implements ResultSet { this.metaData = new RestfulResultSetMetaData(this.database, this.columns); } - public Field findField(String columnName, JSONArray fieldDataJson) { - for (int i = 0; i < fieldDataJson.size(); i++) { - JSONArray field = fieldDataJson.getJSONArray(i); - if (columnName.equalsIgnoreCase(field.getString(0))) { - return new Field(field.getString(0), field.getString(1), field.getInteger(2), field.getString(3)); + public Field findField(String columnName, List fieldJsonList) { + for (JSONObject fieldJSON : fieldJsonList) { + JSONArray fieldDataJson = fieldJSON.getJSONArray("data"); + for (int i = 0; i < fieldDataJson.size(); i++) { + JSONArray field = fieldDataJson.getJSONArray(i); + if (columnName.equalsIgnoreCase(field.getString(0))) { + return new Field(field.getString(0), field.getString(1), field.getInteger(2), field.getString(3)); + } } } + return null; } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java index b622673ffa..690b8a17e6 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java @@ -1,7 +1,6 @@ package com.taosdata.jdbc.rs; import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.taosdata.jdbc.TSDBConstants; import com.taosdata.jdbc.rs.util.HttpClientPoolUtil; @@ -11,6 +10,7 @@ import java.sql.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; public class RestfulStatement implements Statement { @@ -28,14 +28,37 @@ public class RestfulStatement implements Statement { this.database = database; } - private String parseTableIdentifier(String sql) { - List words = Arrays.asList(sql.trim().toLowerCase().split(" ")); - if (words.get(0).equalsIgnoreCase("select")) { - if (words.contains("from")) { - return words.get(words.indexOf("from") + 1); - } + private String[] parseTableIdentifier(String sql) { + sql = sql.trim().toLowerCase(); + String[] ret = null; + if (sql.contains("where")) + sql = sql.substring(0, sql.indexOf("where")); + if (sql.contains("interval")) + sql = sql.substring(0, sql.indexOf("interval")); + if (sql.contains("fill")) + sql = sql.substring(0, sql.indexOf("fill")); + if (sql.contains("sliding")) + sql = sql.substring(0, sql.indexOf("sliding")); + if (sql.contains("group by")) + sql = sql.substring(0, sql.indexOf("group by")); + if (sql.contains("order by")) + sql = sql.substring(0, sql.indexOf("order by")); + if (sql.contains("slimit")) + sql = sql.substring(0, sql.indexOf("slimit")); + if (sql.contains("limit")) + sql = sql.substring(0, sql.indexOf("limit")); + // parse + if (sql.contains("from")) { + sql = sql.substring(sql.indexOf("from") + 4).trim(); + return Arrays.asList(sql.split(",")).stream() + .map(tableIdentifier -> { + tableIdentifier = tableIdentifier.trim(); + if (tableIdentifier.contains(" ")) + tableIdentifier = tableIdentifier.substring(0, tableIdentifier.indexOf(" ")); + return tableIdentifier; + }).collect(Collectors.joining(",")).split(","); } - return null; + return ret; } @Override @@ -54,15 +77,19 @@ public class RestfulStatement implements Statement { } // parse table name from sql - String tableIdentifier = parseTableIdentifier(sql); - if (tableIdentifier != null) { - // field meta - String fields = HttpClientPoolUtil.execute(url, "DESCRIBE " + tableIdentifier); - JSONObject fieldJson = JSON.parseObject(fields); - if (fieldJson.getString("status").equals("error")) { - throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + fieldJson.getString("desc") + "\n" + "error code: " + fieldJson.getString("code"))); + String[] tableIdentifiers = parseTableIdentifier(sql); + if (tableIdentifiers != null) { + List fieldJsonList = new ArrayList<>(); + for (String tableIdentifier : tableIdentifiers) { + // field meta + String fields = HttpClientPoolUtil.execute(url, "DESCRIBE " + tableIdentifier); + JSONObject fieldJson = JSON.parseObject(fields); + if (fieldJson.getString("status").equals("error")) { + throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + fieldJson.getString("desc") + "\n" + "error code: " + fieldJson.getString("code"))); + } + fieldJsonList.add(fieldJson); } - this.resultSet = new RestfulResultSet(database, this, resultJson, fieldJson); + this.resultSet = new RestfulResultSet(database, this, resultJson, fieldJsonList); } else { this.resultSet = new RestfulResultSet(database, this, resultJson); } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/util/HttpClientPoolUtil.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/util/HttpClientPoolUtil.java index 65399b122d..7bf8efffc1 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/util/HttpClientPoolUtil.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/util/HttpClientPoolUtil.java @@ -17,6 +17,8 @@ import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; +import java.nio.charset.Charset; + public class HttpClientPoolUtil { public static PoolingHttpClientConnectionManager cm = null; @@ -94,7 +96,8 @@ public class HttpClientPoolUtil { initPools(); } method = (HttpEntityEnclosingRequestBase) getRequest(uri, HttpPost.METHOD_NAME, DEFAULT_CONTENT_TYPE, 0); - method.setEntity(new StringEntity(data)); + method.setHeader("Content-Type", "text/plain"); + method.setEntity(new StringEntity(data, Charset.forName("UTF-8"))); HttpContext context = HttpClientContext.create(); CloseableHttpResponse httpResponse = httpClient.execute(method, context); httpEntity = httpResponse.getEntity(); @@ -105,26 +108,13 @@ public class HttpClientPoolUtil { if (method != null) { method.abort(); } -// e.printStackTrace(); -// logger.error("execute post request exception, url:" + uri + ", exception:" + e.toString() -// + ", cost time(ms):" + (System.currentTimeMillis() - startTime)); - new Exception("execute post request exception, url:" - + uri + ", exception:" + e.toString() + - ", cost time(ms):" + (System.currentTimeMillis() - startTime)) - .printStackTrace(); + new Exception("execute post request exception, url:" + uri + ", exception:" + e.toString() + ", cost time(ms):" + (System.currentTimeMillis() - startTime)).printStackTrace(); } finally { if (httpEntity != null) { try { EntityUtils.consumeQuietly(httpEntity); } catch (Exception e) { -// e.printStackTrace(); -// logger.error("close response exception, url:" + uri + ", exception:" + e.toString() -// + ", cost time(ms):" + (System.currentTimeMillis() - startTime)); - new Exception( - "close response exception, url:" + uri + - ", exception:" + e.toString() - + ", cost time(ms):" + (System.currentTimeMillis() - startTime)) - .printStackTrace(); + new Exception("close response exception, url:" + uri + ", exception:" + e.toString() + ", cost time(ms):" + (System.currentTimeMillis() - startTime)).printStackTrace(); } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java index d414bc4b09..8ff308f854 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/SQLTest.java @@ -189,43 +189,43 @@ public class SQLTest { } @Test - public void testCase30() { + public void testCase030() { String sql = "select location, temperature, ts from restful_test.weather where ts > now"; executeQuery(sql); } @Test - public void testCase31() { + public void testCase031() { String sql = "select location, temperature, ts from restful_test.weather where ts < now"; executeQuery(sql); } @Test - public void testCase32() { + public void testCase032() { String sql = "select count(*) from restful_test.weather"; executeQuery(sql); } @Test - public void testCase33() { + public void testCase033() { String sql = "select first(*) from restful_test.weather"; executeQuery(sql); } @Test - public void testCase34() { + public void testCase034() { String sql = "select last(*) from restful_test.weather"; executeQuery(sql); } @Test - public void testCase35() { + public void testCase035() { String sql = "select last_row(*) from restful_test.weather"; executeQuery(sql); } @Test - public void testCase36() { + public void testCase036() { String sql = "select ts, ts as primary_key from restful_test.weather"; executeQuery(sql); } @@ -316,6 +316,12 @@ public class SQLTest { executeQuery(sql); } + @Test + public void testCase051() { + String sql = "select * from restful_test.t1 tt, restful_test.t3 yy where tt.ts = yy.ts"; + executeQuery(sql); + } + private void executeUpdate(String sql) { try (Statement statement = connection.createStatement()) { long start = System.currentTimeMillis(); From 021eb5f27b4f927945b9f5326749c8a59e129e66 Mon Sep 17 00:00:00 2001 From: zyyang Date: Wed, 30 Dec 2020 11:33:37 +0800 Subject: [PATCH 4/5] change --- .../taosdata/jdbc/rs/RestfulConnection.java | 141 +++++++++++++++--- 1 file changed, 122 insertions(+), 19 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java index 125d948989..00055731e3 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java @@ -12,6 +12,8 @@ import java.util.concurrent.Executor; public class RestfulConnection implements Connection { + 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; @@ -35,44 +37,67 @@ public class RestfulConnection implements Connection { @Override public Statement createStatement() throws SQLException { if (isClosed()) - throw new SQLException(TSDBConstants.WrapErrMsg("connection is closed.")); + throw new SQLException(CONNECTION_IS_CLOSED); + return new RestfulStatement(this, database); } @Override public PreparedStatement prepareStatement(String sql) throws SQLException { + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); //TODO: prepareStatement throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public CallableStatement prepareCall(String sql) throws SQLException { + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public String nativeSQL(String sql) throws SQLException { - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); + + //nothing did + return sql; } @Override public void setAutoCommit(boolean autoCommit) throws SQLException { - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); + if (!autoCommit) + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public boolean getAutoCommit() throws SQLException { + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); return true; } @Override public void commit() throws SQLException { - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + 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 { - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); + if (getAutoCommit()) + throw new SQLException(AUTO_COMMIT_IS_TRUE); + //nothing to do } @Override @@ -90,56 +115,83 @@ public class RestfulConnection implements Connection { @Override public DatabaseMetaData getMetaData() throws SQLException { - //TODO: RestfulDatabaseMetaData is not implemented return this.metadata; } @Override public void setReadOnly(boolean readOnly) throws SQLException { - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); + if (!readOnly) + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @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); //nothing to do } @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 { - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + 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.UNSUPPORT_METHOD_EXCEPTIONZ_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 { - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + 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.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -150,25 +202,32 @@ public class RestfulConnection implements Connection { @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) { + 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); - } - if (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.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public Map> getTypeMap() throws SQLException { + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); + synchronized (RestfulConnection.class) { if (this.typeMap == null) { - this.typeMap = new HashMap>(); + this.typeMap = new HashMap<>(); } return this.typeMap; } @@ -176,6 +235,9 @@ public class RestfulConnection implements Connection { @Override public void setTypeMap(Map> map) throws SQLException { + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); + synchronized (RestfulConnection.class) { this.typeMap = map; } @@ -183,31 +245,53 @@ public class RestfulConnection implements Connection { @Override public void setHoldability(int holdability) throws SQLException { - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); + if (holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT) + throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_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.UNSUPPORT_METHOD_EXCEPTIONZ_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.UNSUPPORT_METHOD_EXCEPTIONZ_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.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public void releaseSavepoint(Savepoint savepoint) throws SQLException { + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -277,11 +361,16 @@ public class RestfulConnection implements Connection { @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 enumer = properties.keys(); enumer.hasMoreElements(); ) { String name = (String) enumer.nextElement(); clientInfoProps.put(name, properties.getProperty(name)); @@ -290,11 +379,17 @@ public class RestfulConnection implements Connection { @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; } @@ -310,11 +405,15 @@ public class RestfulConnection implements Connection { @Override public void setSchema(String schema) throws SQLException { + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); //nothing to do } @Override public String getSchema() throws SQLException { + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); return this.database; } @@ -335,11 +434,15 @@ public class RestfulConnection implements Connection { @Override public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @Override public int getNetworkTimeout() throws SQLException { + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); return 0; } From dda79b37d1d32657df59f5cccb5b8c05e2234054 Mon Sep 17 00:00:00 2001 From: zyyang Date: Wed, 30 Dec 2020 13:16:23 +0800 Subject: [PATCH 5/5] change --- .../main/java/com/taosdata/jdbc/rs/RestfulConnection.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java index 00055731e3..8bd974e3c2 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulConnection.java @@ -115,6 +115,9 @@ public class RestfulConnection implements Connection { @Override public DatabaseMetaData getMetaData() throws SQLException { + if (isClosed()) + throw new SQLException(CONNECTION_IS_CLOSED); + return this.metadata; } @@ -122,8 +125,7 @@ public class RestfulConnection implements Connection { public void setReadOnly(boolean readOnly) throws SQLException { if (isClosed()) throw new SQLException(CONNECTION_IS_CLOSED); - if (!readOnly) - throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + // nothing to do } @Override