change
This commit is contained in:
parent
d5c2782fb7
commit
49df8540ea
|
@ -0,0 +1,808 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*****************************************************************************/
|
||||||
|
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<ColumnMetaData> columnMetaDataList = new ArrayList<ColumnMetaData>(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<TSDBResultSetRowData> rowDataList = new ArrayList<TSDBResultSetRowData>(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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,68 +19,71 @@ import java.util.Map;
|
||||||
|
|
||||||
public abstract class TSDBConstants {
|
public abstract class TSDBConstants {
|
||||||
|
|
||||||
public static final String DEFAULT_PORT = "6200";
|
public static final String DEFAULT_PORT = "6200";
|
||||||
public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!";
|
public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!";
|
||||||
public static final String INVALID_VARIABLES = "invalid variables";
|
public static final String INVALID_VARIABLES = "invalid variables";
|
||||||
public static Map<Integer, String> DATATYPE_MAP = null;
|
public static Map<Integer, String> DATATYPE_MAP = null;
|
||||||
|
|
||||||
public static final long JNI_NULL_POINTER = 0L;
|
public static final long JNI_NULL_POINTER = 0L;
|
||||||
|
|
||||||
public static final int JNI_SUCCESS = 0;
|
public static final int JNI_SUCCESS = 0;
|
||||||
public static final int JNI_TDENGINE_ERROR = -1;
|
public static final int JNI_TDENGINE_ERROR = -1;
|
||||||
public static final int JNI_CONNECTION_NULL = -2;
|
public static final int JNI_CONNECTION_NULL = -2;
|
||||||
public static final int JNI_RESULT_SET_NULL = -3;
|
public static final int JNI_RESULT_SET_NULL = -3;
|
||||||
public static final int JNI_NUM_OF_FIELDS_0 = -4;
|
public static final int JNI_NUM_OF_FIELDS_0 = -4;
|
||||||
public static final int JNI_SQL_NULL = -5;
|
public static final int JNI_SQL_NULL = -5;
|
||||||
public static final int JNI_FETCH_END = -6;
|
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 String FixErrMsg(int code) {
|
public static final int TSDB_DATA_TYPE_NULL = 0;
|
||||||
switch (code) {
|
public static final int TSDB_DATA_TYPE_BOOL = 1;
|
||||||
case JNI_TDENGINE_ERROR:
|
public static final int TSDB_DATA_TYPE_TINYINT = 2;
|
||||||
return WrapErrMsg("internal error of database!");
|
public static final int TSDB_DATA_TYPE_SMALLINT = 3;
|
||||||
case JNI_CONNECTION_NULL:
|
public static final int TSDB_DATA_TYPE_INT = 4;
|
||||||
return WrapErrMsg("invalid tdengine connection!");
|
public static final int TSDB_DATA_TYPE_BIGINT = 5;
|
||||||
case JNI_RESULT_SET_NULL:
|
public static final int TSDB_DATA_TYPE_FLOAT = 6;
|
||||||
return WrapErrMsg("invalid resultset pointer!");
|
public static final int TSDB_DATA_TYPE_DOUBLE = 7;
|
||||||
case JNI_NUM_OF_FIELDS_0:
|
public static final int TSDB_DATA_TYPE_BINARY = 8;
|
||||||
return WrapErrMsg("invalid num of fields!");
|
public static final int TSDB_DATA_TYPE_TIMESTAMP = 9;
|
||||||
case JNI_SQL_NULL:
|
public static final int TSDB_DATA_TYPE_NCHAR = 10;
|
||||||
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 {
|
// nchar field's max length
|
||||||
DATATYPE_MAP = new HashMap<Integer, String>();
|
public static final int maxFieldSize = 16 * 1024;
|
||||||
DATATYPE_MAP.put(1, "BOOL");
|
|
||||||
DATATYPE_MAP.put(2, "TINYINT");
|
public static String WrapErrMsg(String msg) {
|
||||||
DATATYPE_MAP.put(3, "SMALLINT");
|
return "TDengine Error: " + msg;
|
||||||
DATATYPE_MAP.put(4, "INT");
|
}
|
||||||
DATATYPE_MAP.put(5, "BIGINT");
|
|
||||||
DATATYPE_MAP.put(6, "FLOAT");
|
public static String FixErrMsg(int code) {
|
||||||
DATATYPE_MAP.put(7, "DOUBLE");
|
switch (code) {
|
||||||
DATATYPE_MAP.put(8, "BINARY");
|
case JNI_TDENGINE_ERROR:
|
||||||
DATATYPE_MAP.put(9, "TIMESTAMP");
|
return WrapErrMsg("internal error of database!");
|
||||||
DATATYPE_MAP.put(10, "NCHAR");
|
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<Integer, String>();
|
||||||
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,29 @@
|
||||||
package com.taosdata.jdbc.rs;
|
package com.taosdata.jdbc.rs;
|
||||||
|
|
||||||
import com.taosdata.jdbc.TSDBConstants;
|
import com.taosdata.jdbc.TSDBConstants;
|
||||||
|
import com.taosdata.jdbc.TSDBDriver;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
public class RestfulConnection implements Connection {
|
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 String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
private final Properties props;
|
private final Properties props;
|
||||||
private final String database;
|
private volatile String database;
|
||||||
private final String url;
|
private final String url;
|
||||||
|
/******************************************************/
|
||||||
/**********************************************/
|
private boolean isClosed;
|
||||||
private volatile AtomicBoolean isClosed = new AtomicBoolean(false);
|
private DatabaseMetaData metadata;
|
||||||
private DatabaseMetaData databaseMetaData;
|
private Map<String, Class<?>> typeMap;
|
||||||
|
private Properties clientInfoProps = new Properties();
|
||||||
|
|
||||||
public RestfulConnection(String host, String port, Properties props, String database, String url) {
|
public RestfulConnection(String host, String port, Properties props, String database, String url) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
@ -26,282 +31,425 @@ public class RestfulConnection implements Connection {
|
||||||
this.props = props;
|
this.props = props;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
//TODO
|
this.metadata = new RestfulDatabaseMetaData(url, props.getProperty(TSDBDriver.PROPERTY_KEY_USER), this);
|
||||||
this.databaseMetaData = new RestfulDatabaseMetaData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Statement createStatement() throws SQLException {
|
public Statement createStatement() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("restful TDengine connection is closed."));
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
return new RestfulStatement(this, database);
|
return new RestfulStatement(this, database);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
public PreparedStatement prepareStatement(String sql) throws SQLException {
|
||||||
//TODO:
|
if (isClosed())
|
||||||
return null;
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
//TODO: prepareStatement
|
||||||
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallableStatement prepareCall(String sql) throws SQLException {
|
public CallableStatement prepareCall(String sql) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String nativeSQL(String sql) throws SQLException {
|
public String nativeSQL(String sql) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
|
//nothing did
|
||||||
|
return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
public void setAutoCommit(boolean autoCommit) throws SQLException {
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (!autoCommit)
|
||||||
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getAutoCommit() throws SQLException {
|
public boolean getAutoCommit() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void commit() throws SQLException {
|
public void commit() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (getAutoCommit())
|
||||||
|
throw new SQLException(AUTO_COMMIT_IS_TRUE);
|
||||||
|
//nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void rollback() throws SQLException {
|
public void rollback() throws SQLException {
|
||||||
throw new SQLException(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
|
@Override
|
||||||
public void close() throws SQLException {
|
public void close() throws SQLException {
|
||||||
//TODO: check if resource need release
|
if (isClosed)
|
||||||
this.isClosed.set(true);
|
return;
|
||||||
|
//TODO: release all resources
|
||||||
|
isClosed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isClosed() throws SQLException {
|
public boolean isClosed() throws SQLException {
|
||||||
return this.isClosed.get();
|
return isClosed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseMetaData getMetaData() throws SQLException {
|
public DatabaseMetaData getMetaData() throws SQLException {
|
||||||
return this.databaseMetaData;
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
|
return this.metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReadOnly(boolean readOnly) throws SQLException {
|
public void setReadOnly(boolean readOnly) throws SQLException {
|
||||||
throw new SQLFeatureNotSupportedException("transactions are not supported");
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isReadOnly() throws SQLException {
|
public boolean isReadOnly() throws SQLException {
|
||||||
return false;
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCatalog(String catalog) throws SQLException {
|
public void setCatalog(String catalog) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
synchronized (RestfulConnection.class) {
|
||||||
|
this.database = catalog;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCatalog() throws SQLException {
|
public String getCatalog() throws SQLException {
|
||||||
return null;
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
return this.database;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTransactionIsolation(int level) throws SQLException {
|
public void setTransactionIsolation(int level) throws SQLException {
|
||||||
//transaction is not supported
|
if (isClosed())
|
||||||
throw new SQLFeatureNotSupportedException("transactions are not supported");
|
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
|
@Override
|
||||||
public int getTransactionIsolation() throws SQLException {
|
public int getTransactionIsolation() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
//Connection.TRANSACTION_NONE specifies that transactions are not supported.
|
//Connection.TRANSACTION_NONE specifies that transactions are not supported.
|
||||||
return Connection.TRANSACTION_NONE;
|
return Connection.TRANSACTION_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLWarning getWarnings() throws SQLException {
|
public SQLWarning getWarnings() throws SQLException {
|
||||||
//TODO: getWarnings not implemented
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearWarnings() throws SQLException {
|
public void clearWarnings() throws SQLException {
|
||||||
throw new SQLFeatureNotSupportedException("clearWarnings not supported.");
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
//nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||||
return null;
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||||
return null;
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (resultSetType != ResultSet.TYPE_FORWARD_ONLY || resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
|
||||||
|
throw new SQLFeatureNotSupportedException(TSDBConstants.INVALID_VARIABLES);
|
||||||
|
|
||||||
|
return this.prepareStatement(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
|
||||||
return null;
|
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
|
@Override
|
||||||
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
public Map<String, Class<?>> getTypeMap() throws SQLException {
|
||||||
return null;
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
|
synchronized (RestfulConnection.class) {
|
||||||
|
if (this.typeMap == null) {
|
||||||
|
this.typeMap = new HashMap<>();
|
||||||
|
}
|
||||||
|
return this.typeMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
|
synchronized (RestfulConnection.class) {
|
||||||
|
this.typeMap = map;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setHoldability(int holdability) throws SQLException {
|
public void setHoldability(int holdability) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
if (holdability != ResultSet.HOLD_CURSORS_OVER_COMMIT)
|
||||||
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHoldability() throws SQLException {
|
public int getHoldability() throws SQLException {
|
||||||
return 0;
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Savepoint setSavepoint() throws SQLException {
|
public Savepoint setSavepoint() throws SQLException {
|
||||||
return null;
|
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
|
@Override
|
||||||
public Savepoint setSavepoint(String name) throws SQLException {
|
public Savepoint setSavepoint(String name) throws SQLException {
|
||||||
return null;
|
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
|
@Override
|
||||||
public void rollback(Savepoint savepoint) throws SQLException {
|
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
|
@Override
|
||||||
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
|
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
|
@Override
|
||||||
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
|
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
|
@Override
|
||||||
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
|
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
|
||||||
return null;
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
|
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
|
||||||
return null;
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
|
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
|
||||||
return null;
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
|
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
|
||||||
return null;
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Clob createClob() throws SQLException {
|
public Clob createClob() throws SQLException {
|
||||||
//TODO: not supported
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
throw new SQLFeatureNotSupportedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Blob createBlob() throws SQLException {
|
public Blob createBlob() throws SQLException {
|
||||||
//TODO: not supported
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
throw new SQLFeatureNotSupportedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NClob createNClob() throws SQLException {
|
public NClob createNClob() throws SQLException {
|
||||||
//TODO: not supported
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
throw new SQLFeatureNotSupportedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLXML createSQLXML() throws SQLException {
|
public SQLXML createSQLXML() throws SQLException {
|
||||||
//TODO: not supported
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
throw new SQLFeatureNotSupportedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(int timeout) throws SQLException {
|
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
|
@Override
|
||||||
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
public void setClientInfo(String name, String value) throws SQLClientInfoException {
|
||||||
|
if (isClosed)
|
||||||
|
throw new SQLClientInfoException();
|
||||||
|
clientInfoProps.setProperty(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setClientInfo(Properties properties) throws SQLClientInfoException {
|
public void setClientInfo(Properties properties) throws SQLClientInfoException {
|
||||||
|
if (isClosed)
|
||||||
|
throw new SQLClientInfoException();
|
||||||
|
|
||||||
|
for (Enumeration<Object> enumer = properties.keys(); enumer.hasMoreElements(); ) {
|
||||||
|
String name = (String) enumer.nextElement();
|
||||||
|
clientInfoProps.put(name, properties.getProperty(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getClientInfo(String name) throws SQLException {
|
public String getClientInfo(String name) throws SQLException {
|
||||||
return null;
|
if (isClosed)
|
||||||
|
throw new SQLClientInfoException();
|
||||||
|
|
||||||
|
return clientInfoProps.getProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Properties getClientInfo() throws SQLException {
|
public Properties getClientInfo() throws SQLException {
|
||||||
return null;
|
if (isClosed)
|
||||||
|
throw new SQLClientInfoException();
|
||||||
|
|
||||||
|
return clientInfoProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
|
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
|
||||||
//TODO: not supported
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
throw new SQLFeatureNotSupportedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
|
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
|
||||||
//TODO: not supported
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
throw new SQLFeatureNotSupportedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSchema(String schema) throws SQLException {
|
public void setSchema(String schema) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
|
||||||
|
synchronized (RestfulConnection.class) {
|
||||||
|
this.database = schema;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSchema() throws SQLException {
|
public String getSchema() throws SQLException {
|
||||||
return null;
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
|
return this.database;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void abort(Executor executor) throws SQLException {
|
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
|
@Override
|
||||||
public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
|
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
|
@Override
|
||||||
public int getNetworkTimeout() throws SQLException {
|
public int getNetworkTimeout() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(CONNECTION_IS_CLOSED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -33,7 +33,7 @@ public class RestfulDriver extends AbstractTaosDriver {
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
Properties props = parseURL(url, info);
|
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 port = props.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "6041");
|
||||||
String database = props.containsKey(TSDBDriver.PROPERTY_KEY_DBNAME) ? props.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME) : null;
|
String database = props.containsKey(TSDBDriver.PROPERTY_KEY_DBNAME) ? props.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME) : null;
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2,13 +2,15 @@ package com.taosdata.jdbc.rs;
|
||||||
|
|
||||||
import java.sql.ResultSetMetaData;
|
import java.sql.ResultSetMetaData;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class RestfulResultSetMetaData implements ResultSetMetaData {
|
public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
|
|
||||||
private List<String> fields;
|
private final String database;
|
||||||
|
private ArrayList<RestfulResultSet.Field> fields;
|
||||||
|
|
||||||
public RestfulResultSetMetaData(List<String> fields) {
|
public RestfulResultSetMetaData(String database, ArrayList<RestfulResultSet.Field> fields) {
|
||||||
|
this.database = database;
|
||||||
this.fields = fields;
|
this.fields = fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +26,7 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCaseSensitive(int column) throws SQLException {
|
public boolean isCaseSensitive(int column) throws SQLException {
|
||||||
|
//TODO
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +42,7 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int isNullable(int column) throws SQLException {
|
public int isNullable(int column) throws SQLException {
|
||||||
return 0;
|
return ResultSetMetaData.columnNullable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,7 +57,7 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getColumnLabel(int column) throws SQLException {
|
public String getColumnLabel(int column) throws SQLException {
|
||||||
return fields.get(column - 1);
|
return fields.get(column - 1).name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,7 +67,7 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSchemaName(int column) throws SQLException {
|
public String getSchemaName(int column) throws SQLException {
|
||||||
return null;
|
return this.database;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -84,7 +87,7 @@ public class RestfulResultSetMetaData implements ResultSetMetaData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCatalogName(int column) throws SQLException {
|
public String getCatalogName(int column) throws SQLException {
|
||||||
return null;
|
return this.database;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -7,20 +7,60 @@ import com.taosdata.jdbc.rs.util.HttpClientPoolUtil;
|
||||||
import com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
import com.taosdata.jdbc.utils.SqlSyntaxValidator;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class RestfulStatement implements Statement {
|
public class RestfulStatement implements Statement {
|
||||||
|
|
||||||
|
private static final String STATEMENT_CLOSED = "Statement already closed.";
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
private String database;
|
private String database;
|
||||||
private final RestfulConnection conn;
|
private final RestfulConnection conn;
|
||||||
|
|
||||||
public RestfulStatement(RestfulConnection c, String database) {
|
private volatile RestfulResultSet resultSet;
|
||||||
this.conn = c;
|
private volatile int affectedRows;
|
||||||
|
private volatile boolean closeOnCompletion;
|
||||||
|
|
||||||
|
public RestfulStatement(RestfulConnection conn, String database) {
|
||||||
|
this.conn = conn;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ret;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet executeQuery(String sql) throws SQLException {
|
public ResultSet executeQuery(String sql) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
|
@ -29,43 +69,33 @@ public class RestfulStatement implements Statement {
|
||||||
throw new SQLException("not a select sql for executeQuery: " + sql);
|
throw new SQLException("not a select sql for executeQuery: " + sql);
|
||||||
|
|
||||||
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
||||||
|
// row data
|
||||||
String result = HttpClientPoolUtil.execute(url, sql);
|
String result = HttpClientPoolUtil.execute(url, sql);
|
||||||
String fields = "";
|
JSONObject resultJson = JSON.parseObject(result);
|
||||||
List<String> words = Arrays.asList(sql.split(" "));
|
if (resultJson.getString("status").equals("error")) {
|
||||||
if (words.get(0).equalsIgnoreCase("select")) {
|
throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + resultJson.getString("desc") + "\n" + "error code: " + resultJson.getString("code")));
|
||||||
int index = 0;
|
}
|
||||||
if (words.contains("from")) {
|
|
||||||
index = words.indexOf("from");
|
// parse table name from sql
|
||||||
|
String[] tableIdentifiers = parseTableIdentifier(sql);
|
||||||
|
if (tableIdentifiers != null) {
|
||||||
|
List<JSONObject> 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);
|
||||||
}
|
}
|
||||||
if (words.contains("FROM")) {
|
this.resultSet = new RestfulResultSet(database, this, resultJson, fieldJsonList);
|
||||||
index = words.indexOf("FROM");
|
} else {
|
||||||
}
|
this.resultSet = new RestfulResultSet(database, this, resultJson);
|
||||||
fields = HttpClientPoolUtil.execute(url, "DESCRIBE " + words.get(index + 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONObject jsonObject = JSON.parseObject(result);
|
this.affectedRows = 0;
|
||||||
if (jsonObject.getString("status").equals("error")) {
|
return resultSet;
|
||||||
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");
|
|
||||||
|
|
||||||
return new RestfulResultSet(dataStr, fieldData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -78,77 +108,103 @@ public class RestfulStatement implements Statement {
|
||||||
if (this.database == null)
|
if (this.database == null)
|
||||||
throw new SQLException("Database not specified or available");
|
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());
|
HttpClientPoolUtil.execute(url, "use " + conn.getDatabase());
|
||||||
String result = HttpClientPoolUtil.execute(url, sql);
|
String result = HttpClientPoolUtil.execute(url, sql);
|
||||||
JSONObject jsonObject = JSON.parseObject(result);
|
JSONObject jsonObject = JSON.parseObject(result);
|
||||||
if (jsonObject.getString("status").equals("error")) {
|
if (jsonObject.getString("status").equals("error")) {
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " +
|
throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " + jsonObject.getString("desc") + "\n" + "error code: " + jsonObject.getString("code")));
|
||||||
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
|
@Override
|
||||||
public void close() throws SQLException {
|
public void close() throws SQLException {
|
||||||
this.closed = true;
|
synchronized (RestfulStatement.class) {
|
||||||
|
if (!isClosed())
|
||||||
|
this.closed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxFieldSize() throws SQLException {
|
public int getMaxFieldSize() throws SQLException {
|
||||||
return 0;
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
|
return TSDBConstants.maxFieldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMaxFieldSize(int max) throws SQLException {
|
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
|
@Override
|
||||||
public int getMaxRows() throws SQLException {
|
public int getMaxRows() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMaxRows(int max) throws SQLException {
|
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
|
@Override
|
||||||
public void setEscapeProcessing(boolean enable) throws SQLException {
|
public void setEscapeProcessing(boolean enable) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(RestfulStatement.STATEMENT_CLOSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getQueryTimeout() throws SQLException {
|
public int getQueryTimeout() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setQueryTimeout(int seconds) throws SQLException {
|
public void setQueryTimeout(int seconds) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
|
if (seconds < 0)
|
||||||
|
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancel() throws SQLException {
|
public void cancel() throws SQLException {
|
||||||
|
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SQLWarning getWarnings() throws SQLException {
|
public SQLWarning getWarnings() throws SQLException {
|
||||||
//TODO: getWarnings not Implemented
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearWarnings() throws SQLException {
|
public void clearWarnings() throws SQLException {
|
||||||
|
// nothing to do
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCursorName(String name) throws SQLException {
|
public void setCursorName(String name) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(RestfulStatement.STATEMENT_CLOSED);
|
||||||
|
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -159,133 +215,181 @@ public class RestfulStatement implements Statement {
|
||||||
//如果执行了use操作应该将当前Statement的catalog设置为新的database
|
//如果执行了use操作应该将当前Statement的catalog设置为新的database
|
||||||
if (SqlSyntaxValidator.isUseSql(sql)) {
|
if (SqlSyntaxValidator.isUseSql(sql)) {
|
||||||
this.database = sql.trim().replace("use", "").trim();
|
this.database = sql.trim().replace("use", "").trim();
|
||||||
|
this.conn.setCatalog(this.database);
|
||||||
}
|
}
|
||||||
if (this.database == null)
|
if (this.database == null)
|
||||||
throw new SQLException("Database not specified or available");
|
throw new SQLException("Database not specified or available");
|
||||||
|
|
||||||
final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql";
|
if (SqlSyntaxValidator.isSelectSql(sql)) {
|
||||||
// use database
|
executeQuery(sql);
|
||||||
HttpClientPoolUtil.execute(url, "use " + conn.getDatabase());
|
} else if (SqlSyntaxValidator.isShowSql(sql) || SqlSyntaxValidator.isDescribeSql(sql)) {
|
||||||
// execute sql
|
final String url = "http://" + conn.getHost().trim() + ":" + conn.getPort() + "/rest/sql";
|
||||||
String result = HttpClientPoolUtil.execute(url, sql);
|
if (!SqlSyntaxValidator.isShowDatabaseSql(sql)) {
|
||||||
// parse result
|
HttpClientPoolUtil.execute(url, "use " + conn.getDatabase());
|
||||||
JSONObject jsonObject = JSON.parseObject(result);
|
}
|
||||||
if (jsonObject.getString("status").equals("error")) {
|
String result = HttpClientPoolUtil.execute(url, sql);
|
||||||
throw new SQLException(TSDBConstants.WrapErrMsg("SQL execution error: " +
|
JSONObject resultJson = JSON.parseObject(result);
|
||||||
jsonObject.getString("desc") + "\n" +
|
if (resultJson.getString("status").equals("error")) {
|
||||||
"error code: " + jsonObject.getString("code")));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet getResultSet() throws SQLException {
|
public ResultSet getResultSet() throws SQLException {
|
||||||
return null;
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
|
return resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getUpdateCount() throws SQLException {
|
public int getUpdateCount() throws SQLException {
|
||||||
return 0;
|
if (isClosed()) {
|
||||||
|
throw new SQLException("Invalid method call on a closed statement.");
|
||||||
|
}
|
||||||
|
return this.affectedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getMoreResults() throws SQLException {
|
public boolean getMoreResults() throws SQLException {
|
||||||
return false;
|
return getMoreResults(CLOSE_CURRENT_RESULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFetchDirection(int direction) throws SQLException {
|
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
|
@Override
|
||||||
public int getFetchDirection() throws SQLException {
|
public int getFetchDirection() throws SQLException {
|
||||||
return 0;
|
return this.resultSet.getFetchDirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFetchSize(int rows) throws SQLException {
|
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
|
@Override
|
||||||
public int getFetchSize() throws SQLException {
|
public int getFetchSize() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getResultSetConcurrency() throws SQLException {
|
public int getResultSetConcurrency() throws SQLException {
|
||||||
return 0;
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
|
return this.resultSet.getConcurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getResultSetType() throws SQLException {
|
public int getResultSetType() throws SQLException {
|
||||||
return 0;
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
|
return this.resultSet.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addBatch(String sql) throws SQLException {
|
public void addBatch(String sql) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
|
//TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearBatch() throws SQLException {
|
public void clearBatch() throws SQLException {
|
||||||
|
//TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] executeBatch() throws SQLException {
|
public int[] executeBatch() throws SQLException {
|
||||||
|
//TODO:
|
||||||
return new int[0];
|
return new int[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection getConnection() throws SQLException {
|
public Connection getConnection() throws SQLException {
|
||||||
return null;
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
|
return this.conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getMoreResults(int current) throws SQLException {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResultSet getGeneratedKeys() throws SQLException {
|
public ResultSet getGeneratedKeys() throws SQLException {
|
||||||
return null;
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
|
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
|
||||||
return 0;
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
|
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
|
||||||
return 0;
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
|
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
|
||||||
return 0;
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
|
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
|
||||||
return false;
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
|
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
|
||||||
return false;
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(String sql, String[] columnNames) throws SQLException {
|
public boolean execute(String sql, String[] columnNames) throws SQLException {
|
||||||
return false;
|
throw new SQLFeatureNotSupportedException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getResultSetHoldability() throws SQLException {
|
public int getResultSetHoldability() throws SQLException {
|
||||||
return 0;
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
|
return this.resultSet.getHoldability();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -295,22 +399,30 @@ public class RestfulStatement implements Statement {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPoolable(boolean poolable) throws SQLException {
|
public void setPoolable(boolean poolable) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
|
//nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPoolable() throws SQLException {
|
public boolean isPoolable() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeOnCompletion() throws SQLException {
|
public void closeOnCompletion() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
|
this.closeOnCompletion = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCloseOnCompletion() throws SQLException {
|
public boolean isCloseOnCompletion() throws SQLException {
|
||||||
return false;
|
if (isClosed())
|
||||||
|
throw new SQLException(STATEMENT_CLOSED);
|
||||||
|
return this.closeOnCompletion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,6 +17,8 @@ import org.apache.http.protocol.HTTP;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
|
||||||
public class HttpClientPoolUtil {
|
public class HttpClientPoolUtil {
|
||||||
public static PoolingHttpClientConnectionManager cm = null;
|
public static PoolingHttpClientConnectionManager cm = null;
|
||||||
|
@ -94,7 +96,8 @@ public class HttpClientPoolUtil {
|
||||||
initPools();
|
initPools();
|
||||||
}
|
}
|
||||||
method = (HttpEntityEnclosingRequestBase) getRequest(uri, HttpPost.METHOD_NAME, DEFAULT_CONTENT_TYPE, 0);
|
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();
|
HttpContext context = HttpClientContext.create();
|
||||||
CloseableHttpResponse httpResponse = httpClient.execute(method, context);
|
CloseableHttpResponse httpResponse = httpClient.execute(method, context);
|
||||||
httpEntity = httpResponse.getEntity();
|
httpEntity = httpResponse.getEntity();
|
||||||
|
@ -105,26 +108,13 @@ public class HttpClientPoolUtil {
|
||||||
if (method != null) {
|
if (method != null) {
|
||||||
method.abort();
|
method.abort();
|
||||||
}
|
}
|
||||||
// e.printStackTrace();
|
new Exception("execute post request exception, url:" + uri + ", exception:" + e.toString() + ", cost time(ms):" + (System.currentTimeMillis() - startTime)).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();
|
|
||||||
} finally {
|
} finally {
|
||||||
if (httpEntity != null) {
|
if (httpEntity != null) {
|
||||||
try {
|
try {
|
||||||
EntityUtils.consumeQuietly(httpEntity);
|
EntityUtils.consumeQuietly(httpEntity);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// e.printStackTrace();
|
new Exception("close response exception, url:" + uri + ", exception:" + e.toString() + ", cost time(ms):" + (System.currentTimeMillis() - startTime)).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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,14 +15,12 @@
|
||||||
package com.taosdata.jdbc.utils;
|
package com.taosdata.jdbc.utils;
|
||||||
|
|
||||||
import com.taosdata.jdbc.TSDBConnection;
|
import com.taosdata.jdbc.TSDBConnection;
|
||||||
import com.taosdata.jdbc.TSDBJNIConnector;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class SqlSyntaxValidator {
|
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 static final String[] querySQL = {"select"};
|
||||||
|
|
||||||
private TSDBConnection tsdbConnection;
|
private TSDBConnection tsdbConnection;
|
||||||
|
@ -31,22 +29,6 @@ public class SqlSyntaxValidator {
|
||||||
this.tsdbConnection = (TSDBConnection) connection;
|
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) {
|
public static boolean isValidForExecuteUpdate(String sql) {
|
||||||
for (String prefix : updateSQL) {
|
for (String prefix : updateSQL) {
|
||||||
if (sql.trim().toLowerCase().startsWith(prefix))
|
if (sql.trim().toLowerCase().startsWith(prefix))
|
||||||
|
@ -56,18 +38,28 @@ public class SqlSyntaxValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUseSql(String sql) {
|
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) {
|
public static boolean isShowSql(String sql) {
|
||||||
return sql.trim().toLowerCase().startsWith(updateSQL[1]);
|
return sql.trim().toLowerCase().startsWith("show");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isDescribeSql(String sql) {
|
||||||
|
return sql.trim().toLowerCase().startsWith("describe");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean isInsertSql(String sql) {
|
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) {
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue