- *
- * 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.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-public class TSDBDatabaseMetaData extends AbstractDatabaseMetaData {
-
- private final String url;
- private final String userName;
- private Connection conn;
-
- public TSDBDatabaseMetaData(String url, String userName) {
- this.url = url;
- this.userName = userName;
- }
-
- public Connection getConnection() throws SQLException {
- return this.conn;
- }
-
- public void setConnection(Connection conn) {
- this.conn = conn;
- }
-
- public String getURL() throws SQLException {
- return this.url;
- }
-
- public String getUserName() throws SQLException {
- return this.userName;
- }
-
- public String getDriverName() throws SQLException {
- return TSDBDriver.class.getName();
- }
-
- /**
- * @Param catalog : database名称,"" 表示不属于任何database的table,null表示不使用database来缩小范围
- * @Param schemaPattern : schema名称,""表示
- * @Param tableNamePattern : 表名满足tableNamePattern的表, null表示返回所有表
- * @Param types : 表类型,null表示返回所有类型
- */
- public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException {
- if (conn == null || conn.isClosed()) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
- }
- return super.getTables(catalog, schemaPattern, tableNamePattern, types, conn);
- }
-
- public ResultSet getCatalogs() throws SQLException {
- if (conn == null || conn.isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
- return super.getCatalogs(conn);
- }
-
- public ResultSet getTableTypes() throws SQLException {
- if (conn == null || conn.isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
- return super.getTableTypes();
- }
-
- public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException {
- if (conn == null || conn.isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
- return super.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern, conn);
- }
-
- public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException {
- if (conn == null || conn.isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
- return super.getPrimaryKeys(catalog, schema, table, conn);
- }
-
- public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException {
- if (conn == null || conn.isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
- return super.getSuperTables(catalog, schemaPattern, tableNamePattern, conn);
- }
-
-}
\ No newline at end of file
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java
deleted file mode 100755
index ac8f68d918375643b5066d3091c3e06010bc0afe..0000000000000000000000000000000000000000
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java
+++ /dev/null
@@ -1,254 +0,0 @@
-package com.taosdata.jdbc;
-
-import java.sql.*;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import java.util.logging.Logger;
-
-/**
- * The Java SQL framework allows for multiple database drivers. Each driver
- * should supply a class that implements the Driver interface
- *
- *
- * The DriverManager will try to load as many drivers as it can find and then
- * for any given connection request, it will ask each driver in turn to try to
- * connect to the target URL.
- *
- *
- * It is strongly recommended that each Driver class should be small and stand
- * alone so that the Driver class can be loaded and queried without bringing in
- * vast quantities of supporting code.
- *
- *
- * When a Driver class is loaded, it should create an instance of itself and
- * register it with the DriverManager. This means that a user can load and
- * register a driver by doing Class.forName("foo.bah.Driver")
- */
-public class TSDBDriver extends AbstractDriver {
-
- @Deprecated
- private static final String URL_PREFIX1 = "jdbc:TSDB://";
-
- private static final String URL_PREFIX = "jdbc:TAOS://";
-
- /**
- * PRODUCT_NAME
- */
- public static final String PROPERTY_KEY_PRODUCT_NAME = "productName";
- /**
- * Key used to retrieve the host value from the properties instance passed to
- * the driver.
- */
- public static final String PROPERTY_KEY_HOST = "host";
- /**
- * Key used to retrieve the port number value from the properties instance
- * passed to the driver.
- */
- public static final String PROPERTY_KEY_PORT = "port";
- /**
- * Key used to retrieve the database value from the properties instance passed
- * to the driver.
- */
- public static final String PROPERTY_KEY_DBNAME = "dbname";
- /**
- * Key used to retrieve the user value from the properties instance passed to
- * the driver.
- */
- public static final String PROPERTY_KEY_USER = "user";
- /**
- * Key used to retrieve the password value from the properties instance passed
- * to the driver.
- */
- public static final String PROPERTY_KEY_PASSWORD = "password";
- /**
- * Key used to retrieve the token value from the properties instance passed to
- * the driver.
- * Just for Cloud Service
- */
- public static final String PROPERTY_KEY_TOKEN = "token";
- /**
- * Use SSL (true/false) to communicate with the server. The default value is false.
- * Just for Cloud Service
- */
- public static final String PROPERTY_KEY_USE_SSL = "useSSL";
- /**
- * Key for the configuration file directory of TSDB client in properties instance
- */
- public static final String PROPERTY_KEY_CONFIG_DIR = "cfgdir";
- /**
- * Key for the timezone used by the TSDB client in properties instance
- */
- public static final String PROPERTY_KEY_TIME_ZONE = "timezone";
- /**
- * Key for the locale used by the TSDB client in properties instance
- */
- public static final String PROPERTY_KEY_LOCALE = "locale";
- /**
- * Key for the char encoding used by the TSDB client in properties instance
- */
- public static final String PROPERTY_KEY_CHARSET = "charset";
-
- /**
- * fetch data from native function in a batch model
- */
- public static final String PROPERTY_KEY_BATCH_LOAD = "batchfetch";
-
- /**
- * timestamp format for JDBC-RESTful,should one of the options: string or timestamp or utc
- */
- public static final String PROPERTY_KEY_TIMESTAMP_FORMAT = "timestampFormat";
-
- /**
- * continue process commands in executeBatch
- */
- public static final String PROPERTY_KEY_BATCH_ERROR_IGNORE = "batchErrorIgnore";
-
- /**
- * message receive from server timeout. ms
- */
- public static final String PROPERTY_KEY_MESSAGE_WAIT_TIMEOUT = "messageWaitTimeout";
-
- /**
- * max message number send to server concurrently
- */
- public static final String PROPERTY_KEY_MAX_CONCURRENT_REQUEST = "maxConcurrentRequest";
-
- private TSDBDatabaseMetaData dbMetaData = null;
-
- static {
- try {
- DriverManager.registerDriver(new TSDBDriver());
- } catch (SQLException e) {
- throw TSDBError.createRuntimeException(TSDBErrorNumbers.ERROR_CANNOT_REGISTER_JNI_DRIVER, e);
- }
- }
-
- public Connection connect(String url, Properties info) throws SQLException {
- if (!acceptsURL(url))
- return null;
-
- Properties props = parseURL(url, info);
- if (props == null) {
- return null;
- }
-
- if (!props.containsKey(TSDBDriver.PROPERTY_KEY_USER))
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_USER_IS_REQUIRED);
- if (!props.containsKey(TSDBDriver.PROPERTY_KEY_PASSWORD))
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PASSWORD_IS_REQUIRED);
-
- try {
- TSDBJNIConnector.init(props);
- return new TSDBConnection(props, this.dbMetaData);
- } catch (SQLWarning sqlWarning) {
- return new TSDBConnection(props, this.dbMetaData);
- } catch (SQLException sqlEx) {
- throw sqlEx;
- } catch (Exception ex) {
- throw new SQLException("SQLException:" + ex, ex);
- }
- }
-
- /**
- * @param url the URL of the database
- * @return true
if this driver understands the given URL;
- * false
otherwise
- * @throws SQLException if a database access error occurs or the url is {@code null}
- */
- public boolean acceptsURL(String url) throws SQLException {
- if (url == null)
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET);
- return url.trim().length() > 0 && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1));
- }
-
- public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
- if (info == null) {
- info = new Properties();
- }
-
- if (acceptsURL(url)) {
- info = parseURL(url, info);
- }
-
- return getPropertyInfo(info);
- }
-
- /**
- * example: jdbc:TAOS://127.0.0.1:0/db?user=root&password=your_password
- */
- @Override
- public Properties parseURL(String url, Properties defaults) {
- Properties urlProps = (defaults != null) ? defaults : new Properties();
- if (url == null || url.length() <= 0 || url.trim().length() <= 0)
- return null;
- if (!url.startsWith(URL_PREFIX) && !url.startsWith(URL_PREFIX1))
- return null;
-
- // parse properties
- String urlForMeta = url;
- int beginningOfSlashes = url.indexOf("//");
- int index = url.indexOf("?");
- if (index != -1) {
- String paramString = url.substring(index + 1);
- url = url.substring(0, index);
- StringTokenizer queryParams = new StringTokenizer(paramString, "&");
- while (queryParams.hasMoreElements()) {
- String oneToken = queryParams.nextToken();
- String[] pair = oneToken.split("=");
-
- if ((pair[0] != null && pair[0].trim().length() > 0) && (pair[1] != null && pair[1].trim().length() > 0)) {
- urlProps.setProperty(pair[0].trim(), pair[1].trim());
- }
- }
- }
-
- // parse Product Name
- String dbProductName = url.substring(0, beginningOfSlashes);
- dbProductName = dbProductName.substring(dbProductName.indexOf(":") + 1);
- dbProductName = dbProductName.substring(0, dbProductName.indexOf(":"));
- urlProps.setProperty(TSDBDriver.PROPERTY_KEY_PRODUCT_NAME, dbProductName);
-
- // parse database name
- url = url.substring(beginningOfSlashes + 2);
- int indexOfSlash = url.indexOf("/");
- if (indexOfSlash != -1) {
- if (indexOfSlash + 1 < url.length()) {
- urlProps.setProperty(TSDBDriver.PROPERTY_KEY_DBNAME, url.substring(indexOfSlash + 1));
- }
- url = url.substring(0, indexOfSlash);
- }
-
- // parse port
- int indexOfColon = url.indexOf(":");
- if (indexOfColon != -1) {
- if (indexOfColon + 1 < url.length()) {
- urlProps.setProperty(TSDBDriver.PROPERTY_KEY_PORT, url.substring(indexOfColon + 1));
- }
- url = url.substring(0, indexOfColon);
- }
-
- if (url.length() > 0 && url.trim().length() > 0) {
- urlProps.setProperty(TSDBDriver.PROPERTY_KEY_HOST, url);
- }
-
- this.dbMetaData = new TSDBDatabaseMetaData(urlForMeta, urlProps.getProperty(TSDBDriver.PROPERTY_KEY_USER));
- return urlProps;
- }
-
- public int getMajorVersion() {
- return 2;
- }
-
- public int getMinorVersion() {
- return 0;
- }
-
- public boolean jdbcCompliant() {
- return false;
- }
-
- public Logger getParentLogger() {
- return null;
- }
-
-}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
deleted file mode 100644
index 0970148b1dfb6c6c1fb85330e312bf2c8168b3c7..0000000000000000000000000000000000000000
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.taosdata.jdbc;
-
-import java.sql.SQLClientInfoException;
-import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
-import java.sql.SQLWarning;
-import java.util.HashMap;
-import java.util.Map;
-
-public class TSDBError {
- private static final Map TSDBErrorMap = new HashMap<>();
-
- static {
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED, "connection already closed");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD, "this operation is NOT supported currently!");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_VARIABLE, "invalid variables");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED, "statement is closed");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED, "resultSet is closed");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_BATCH_IS_EMPTY, "Batch is empty!");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY, "Can not issue data manipulation statements with executeQuery()");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEUPDATE, "Can not issue SELECT via executeUpdate()");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "invalid sql for executeQuery: (?)");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE, "Database not specified or available");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "invalid sql for executeUpdate: (?)");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "invalid sql for execute: (?)");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE, "parameter index out of range");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED, "connection already closed");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE, "unknown sql type in tdengine");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_CANNOT_REGISTER_JNI_DRIVER, "can't register JDBC-JNI driver");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_CANNOT_REGISTER_RESTFUL_DRIVER, "can't register JDBC-RESTful driver");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_URL_NOT_SET, "url is not set");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_SQL, "invalid sql");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE, "numeric value out of range");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_TAOS_TYPE, "unknown taos type in tdengine");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_TIMESTAMP_PRECISION, "unknown timestamp precision");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_USER_IS_REQUIRED, "user is required");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_PASSWORD_IS_REQUIRED, "password is required");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_INVALID_JSON_FORMAT, "invalid json format");
-
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error");
-
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_SUBSCRIBE_FAILED, "failed to create subscription");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING, "Unsupported encoding");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_TDENGINE_ERROR, "internal error of database, please see taoslog for more details");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL, "JNI connection is NULL");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL, "JNI result set is NULL");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0, "invalid num of fields");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_SQL_NULL, "empty sql string");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_FETCH_END, "fetch to the end of resultSet");
- TSDBErrorMap.put(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY, "JNI alloc memory failed, please see taoslog for more details");
- }
-
- public static SQLException createSQLException(int errorCode) {
- String message;
- if (TSDBErrorNumbers.contains(errorCode))
- message = TSDBErrorMap.get(errorCode);
- else
- message = TSDBErrorMap.get(TSDBErrorNumbers.ERROR_UNKNOWN);
- return createSQLException(errorCode, message);
- }
-
- public static SQLException createSQLException(int errorCode, String message) {
- // throw SQLFeatureNotSupportedException
- if (errorCode == TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD)
- return new SQLFeatureNotSupportedException(message, "", errorCode);
- // throw SQLClientInfoException
- if (errorCode == TSDBErrorNumbers.ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED)
- return new SQLClientInfoException(message, null);
-
- if (errorCode > 0x2300 && errorCode < 0x2350)
- // JDBC exception's error number is less than 0x2350
- return new SQLException("ERROR (" + Integer.toHexString(errorCode) + "): " + message, "", errorCode);
- if (errorCode > 0x2350 && errorCode < 0x2400)
- // JNI exception's error number is large than 0x2350
- return new SQLException("JNI ERROR (" + Integer.toHexString(errorCode) + "): " + message, "", errorCode);
- return new SQLException("TDengine ERROR (" + Integer.toHexString(errorCode) + "): " + message, "", errorCode);
- }
-
- public static RuntimeException createRuntimeException(int errorCode, Throwable t) {
- String message = TSDBErrorMap.get(errorCode);
- return new RuntimeException("ERROR (" + Integer.toHexString(errorCode) + "): " + message, t);
- }
-
- public static SQLWarning createSQLWarning(String message) {
- return new SQLWarning(message);
- }
-}
\ No newline at end of file
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
deleted file mode 100644
index 1c380fed7dac2c54655830eef6f575e9c07e22af..0000000000000000000000000000000000000000
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package com.taosdata.jdbc;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class TSDBErrorNumbers {
-
- public static final int ERROR_CONNECTION_CLOSED = 0x2301; // connection already closed
- public static final int ERROR_UNSUPPORTED_METHOD = 0x2302; //this operation is NOT supported currently!
- public static final int ERROR_INVALID_VARIABLE = 0x2303; //invalid variables
- public static final int ERROR_STATEMENT_CLOSED = 0x2304; //statement already closed
- public static final int ERROR_RESULTSET_CLOSED = 0x2305; //resultSet is closed
- public static final int ERROR_BATCH_IS_EMPTY = 0x2306; //Batch is empty!
- public static final int ERROR_INVALID_WITH_EXECUTEQUERY = 0x2307; //Can not issue data manipulation statements with executeQuery()
- public static final int ERROR_INVALID_WITH_EXECUTEUPDATE = 0x2308; //Can not issue SELECT via executeUpdate()
- public static final int ERROR_INVALID_FOR_EXECUTE_QUERY = 0x2309; //not a valid sql for executeQuery: (SQL)
- public static final int ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE = 0x230a; //Database not specified or available
- public static final int ERROR_INVALID_FOR_EXECUTE_UPDATE = 0x230b; //not a valid sql for executeUpdate: (SQL)
- public static final int ERROR_INVALID_FOR_EXECUTE = 0x230c; //not a valid sql for execute: (SQL)
- public static final int ERROR_PARAMETER_INDEX_OUT_RANGE = 0x230d; // parameter index out of range
- public static final int ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED = 0x230e; // connection already closed
- public static final int ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE = 0x230f; //unknown sql type in tdengine
- public static final int ERROR_CANNOT_REGISTER_JNI_DRIVER = 0x2310; // can't register JDBC-JNI driver
- public static final int ERROR_CANNOT_REGISTER_RESTFUL_DRIVER = 0x2311; // can't register JDBC-RESTful driver
- public static final int ERROR_URL_NOT_SET = 0x2312; // url is not set
- public static final int ERROR_INVALID_SQL = 0x2313; // invalid sql
- public static final int ERROR_NUMERIC_VALUE_OUT_OF_RANGE = 0x2314; // numeric value out of range
- public static final int ERROR_UNKNOWN_TAOS_TYPE = 0x2315; //unknown taos type in tdengine
- public static final int ERROR_UNKNOWN_TIMESTAMP_PRECISION = 0x2316; // unknown timestamp precision
- public static final int ERROR_RESTFul_Client_Protocol_Exception = 0x2317;
- public static final int ERROR_RESTFul_Client_IOException = 0x2318;
- public static final int ERROR_USER_IS_REQUIRED = 0x2319; // user is required
- public static final int ERROR_PASSWORD_IS_REQUIRED = 0x231a; // password is required
- public static final int ERROR_INVALID_JSON_FORMAT = 0x231b;
- public static final int ERROR_HTTP_ENTITY_IS_NULL = 0x231c; //http entity is null
-
-
- public static final int ERROR_UNKNOWN = 0x2350; //unknown error
-
- public static final int ERROR_SUBSCRIBE_FAILED = 0x2351; // failed to create subscription
- public static final int ERROR_UNSUPPORTED_ENCODING = 0x2352; // Unsupported encoding
- public static final int ERROR_JNI_TDENGINE_ERROR = 0x2353; // internal error of database
- public static final int ERROR_JNI_CONNECTION_NULL = 0x2354; // JNI connection is NULL
- public static final int ERROR_JNI_RESULT_SET_NULL = 0x2355; // invalid JNI result set
- public static final int ERROR_JNI_NUM_OF_FIELDS_0 = 0x2356; // invalid num of fields
- public static final int ERROR_JNI_SQL_NULL = 0x2357; // empty sql string
- public static final int ERROR_JNI_FETCH_END = 0x2358; // fetch to the end of resultSet
- public static final int ERROR_JNI_OUT_OF_MEMORY = 0x2359; // JNI alloc memory failed
-
- private static final Set errorNumbers = new HashSet<>();
-
- static {
- errorNumbers.add(ERROR_CONNECTION_CLOSED);
- errorNumbers.add(ERROR_UNSUPPORTED_METHOD);
- errorNumbers.add(ERROR_INVALID_VARIABLE);
- errorNumbers.add(ERROR_STATEMENT_CLOSED);
- errorNumbers.add(ERROR_RESULTSET_CLOSED);
- errorNumbers.add(ERROR_INVALID_WITH_EXECUTEQUERY);
- errorNumbers.add(ERROR_INVALID_WITH_EXECUTEUPDATE);
- errorNumbers.add(ERROR_INVALID_FOR_EXECUTE_QUERY);
- errorNumbers.add(ERROR_DATABASE_NOT_SPECIFIED_OR_AVAILABLE);
- errorNumbers.add(ERROR_INVALID_FOR_EXECUTE_UPDATE);
- errorNumbers.add(ERROR_INVALID_FOR_EXECUTE);
- errorNumbers.add(ERROR_PARAMETER_INDEX_OUT_RANGE);
- errorNumbers.add(ERROR_SQLCLIENT_EXCEPTION_ON_CONNECTION_CLOSED);
- errorNumbers.add(ERROR_UNKNOWN_SQL_TYPE_IN_TDENGINE);
- errorNumbers.add(ERROR_CANNOT_REGISTER_JNI_DRIVER);
- errorNumbers.add(ERROR_CANNOT_REGISTER_RESTFUL_DRIVER);
- errorNumbers.add(ERROR_URL_NOT_SET);
- errorNumbers.add(ERROR_INVALID_SQL);
- errorNumbers.add(ERROR_NUMERIC_VALUE_OUT_OF_RANGE);
- errorNumbers.add(ERROR_UNKNOWN_TAOS_TYPE);
- errorNumbers.add(ERROR_UNKNOWN_TIMESTAMP_PRECISION);
- errorNumbers.add(ERROR_RESTFul_Client_IOException);
- errorNumbers.add(ERROR_USER_IS_REQUIRED);
- errorNumbers.add(ERROR_PASSWORD_IS_REQUIRED);
- errorNumbers.add(ERROR_INVALID_JSON_FORMAT);
- errorNumbers.add(ERROR_HTTP_ENTITY_IS_NULL);
-
- errorNumbers.add(ERROR_RESTFul_Client_Protocol_Exception);
-
- errorNumbers.add(ERROR_SUBSCRIBE_FAILED);
- errorNumbers.add(ERROR_UNSUPPORTED_ENCODING);
- errorNumbers.add(ERROR_JNI_TDENGINE_ERROR);
- errorNumbers.add(ERROR_JNI_CONNECTION_NULL);
- errorNumbers.add(ERROR_JNI_RESULT_SET_NULL);
- errorNumbers.add(ERROR_JNI_NUM_OF_FIELDS_0);
- errorNumbers.add(ERROR_JNI_SQL_NULL);
- errorNumbers.add(ERROR_JNI_FETCH_END);
- errorNumbers.add(ERROR_JNI_OUT_OF_MEMORY);
- }
-
- private TSDBErrorNumbers() {
- }
-
- public static boolean contains(int errorNumber) {
- return errorNumbers.contains(errorNumber);
- }
-}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBException.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBException.java
deleted file mode 100644
index 31299a1c6f37a8b75521a65e7de09f5162558dd6..0000000000000000000000000000000000000000
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBException.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.taosdata.jdbc;
-
-public class TSDBException {
- private int code;
- private String message;
-
- public int getCode() {
- return code;
- }
-
- public void setCode(int code) {
- this.code = code;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-}
\ No newline at end of file
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
deleted file mode 100755
index 3cc28b4de68cae7bcf337b12ba924454d5653706..0000000000000000000000000000000000000000
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+++ /dev/null
@@ -1,384 +0,0 @@
-package com.taosdata.jdbc;
-
-import com.alibaba.fastjson.JSONObject;
-import com.taosdata.jdbc.enums.SchemalessProtocolType;
-import com.taosdata.jdbc.enums.SchemalessTimestampType;
-import com.taosdata.jdbc.utils.TaosInfo;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-import java.sql.SQLException;
-import java.sql.SQLWarning;
-import java.util.List;
-import java.util.Properties;
-
-/**
- * JNI connector
- */
-public class TSDBJNIConnector {
- private static final Object LOCK = new Object();
- private static volatile boolean isInitialized;
-
- private final TaosInfo taosInfo = TaosInfo.getInstance();
- private long taos = TSDBConstants.JNI_NULL_POINTER; // Connection pointer used in C
- private boolean isResultsetClosed; // result set status in current connection
- private int affectedRows = -1;
-
- static {
- System.loadLibrary("taos");
- }
-
- /***********************************************************************/
- //NOTE: JDBC
- public static void init(Properties props) throws SQLWarning {
- synchronized (LOCK) {
- if (!isInitialized) {
-
- JSONObject configJSON = new JSONObject();
- for (String key : props.stringPropertyNames()) {
- configJSON.put(key, props.getProperty(key));
- }
- setConfigImp(configJSON.toJSONString());
-
- initImp(props.getProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR, null));
-
- String locale = props.getProperty(TSDBDriver.PROPERTY_KEY_LOCALE);
- if (setOptions(0, locale) < 0) {
- throw TSDBError.createSQLWarning("Failed to set locale: " + locale + ". System default will be used.");
- }
- String charset = props.getProperty(TSDBDriver.PROPERTY_KEY_CHARSET);
- if (setOptions(1, charset) < 0) {
- throw TSDBError.createSQLWarning("Failed to set charset: " + charset + ". System default will be used.");
- }
- String timezone = props.getProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE);
- if (setOptions(2, timezone) < 0) {
- throw TSDBError.createSQLWarning("Failed to set timezone: " + timezone + ". System default will be used.");
- }
- isInitialized = true;
- TaosGlobalConfig.setCharset(getTsCharset());
- }
- }
- }
-
- private static native void initImp(String configDir);
-
- private static native int setOptions(int optionIndex, String optionValue);
-
- private static native String getTsCharset();
-
- private static native TSDBException setConfigImp(String config);
-
- public boolean connect(String host, int port, String dbName, String user, String password) throws SQLException {
- if (this.taos != TSDBConstants.JNI_NULL_POINTER) {
- closeConnection();
- this.taos = TSDBConstants.JNI_NULL_POINTER;
- }
-
- this.taos = this.connectImp(host, port, dbName, user, password);
- if (this.taos == TSDBConstants.JNI_NULL_POINTER) {
- String errMsg = this.getErrMsg(0);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL, errMsg);
- }
- // invoke connectImp only here
- taosInfo.conn_open_increment();
- return true;
- }
-
- private native long connectImp(String host, int port, String dbName, String user, String password);
-
- /**
- * Execute DML/DDL operation
- */
- public long executeQuery(String sql) throws SQLException {
- long pSql = 0L;
- try {
- pSql = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos);
- taosInfo.stmt_count_increment();
- } catch (UnsupportedEncodingException e) {
- this.freeResultSetImp(this.taos, pSql);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_ENCODING);
- }
- if (pSql == TSDBConstants.JNI_CONNECTION_NULL) {
- this.freeResultSetImp(this.taos, pSql);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
- }
- if (pSql == TSDBConstants.JNI_SQL_NULL) {
- this.freeResultSetImp(this.taos, pSql);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_SQL_NULL);
- }
- if (pSql == TSDBConstants.JNI_OUT_OF_MEMORY) {
- this.freeResultSetImp(this.taos, pSql);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY);
- }
-
- int code = this.getErrCode(pSql);
- if (code != TSDBConstants.JNI_SUCCESS) {
- affectedRows = -1;
- String msg = this.getErrMsg(pSql);
- this.freeResultSetImp(this.taos, pSql);
- throw TSDBError.createSQLException(code, msg);
- }
-
- // Try retrieving result set for the executed SQL using the current connection pointer.
- pSql = this.getResultSetImp(this.taos, pSql);
- // if pSql == 0L that means resultset is closed
- isResultsetClosed = (pSql == TSDBConstants.JNI_NULL_POINTER);
-
- return pSql;
- }
-
- private native long executeQueryImp(byte[] sqlBytes, long connection);
-
- /**
- * Get recent error code by connection
- */
- public int getErrCode(long pSql) {
- return this.getErrCodeImp(this.taos, pSql);
- }
-
- private native int getErrCodeImp(long connection, long pSql);
-
- /**
- * Get recent error message by connection
- */
- public String getErrMsg(long pSql) {
- return this.getErrMsgImp(pSql);
- }
-
- private native String getErrMsgImp(long pSql);
-
- private native long getResultSetImp(long connection, long pSql);
-
- public boolean isUpdateQuery(long pSql) {
- return isUpdateQueryImp(this.taos, pSql) == 1;
- }
-
- private native long isUpdateQueryImp(long connection, long pSql);
-
- public boolean isClosed() {
- return this.taos == TSDBConstants.JNI_NULL_POINTER;
- }
-
- public boolean isResultsetClosed() {
- return this.isResultsetClosed;
- }
-
- /**
- * Free result set operation from C to release result set pointer by JNI
- */
- public int freeResultSet(long pSql) {
- int res = this.freeResultSetImp(this.taos, pSql);
- isResultsetClosed = true;
- return res;
- }
-
- private native int freeResultSetImp(long connection, long result);
-
- /**
- * Get affected rows count
- */
- public int getAffectedRows(long pSql) {
- int affectedRows = this.affectedRows;
- if (affectedRows < 0) {
- affectedRows = this.getAffectedRowsImp(this.taos, pSql);
- }
- return affectedRows;
- }
-
- private native int getAffectedRowsImp(long connection, long pSql);
-
- /**
- * Get schema metadata
- */
- public int getSchemaMetaData(long resultSet, List columnMetaData) {
- int ret = this.getSchemaMetaDataImp(this.taos, resultSet, columnMetaData);
- columnMetaData.forEach(column -> column.setColIndex(column.getColIndex() + 1));
- return ret;
- }
-
- private native int getSchemaMetaDataImp(long connection, long resultSet, List columnMetaData);
-
- /**
- * Get one row data
- */
- public int fetchRow(long resultSet, TSDBResultSetRowData rowData) {
- return this.fetchRowImp(this.taos, resultSet, rowData);
- }
-
- private native int fetchRowImp(long connection, long resultSet, TSDBResultSetRowData rowData);
-
- public int fetchBlock(long resultSet, TSDBResultSetBlockData blockData) {
- return this.fetchBlockImp(this.taos, resultSet, blockData);
- }
-
- private native int fetchBlockImp(long connection, long resultSet, TSDBResultSetBlockData blockData);
-
- /**
- * Get Result Time Precision.
- *
- * @return 0: ms, 1: us, 2: ns
- */
- public int getResultTimePrecision(long sqlObj) {
- return this.getResultTimePrecisionImp(this.taos, sqlObj);
- }
-
- private native int getResultTimePrecisionImp(long connection, long result);
-
- /**
- * Execute close operation from C to release connection pointer by JNI
- */
- public void closeConnection() throws SQLException {
- int code = this.closeConnectionImp(this.taos);
-
- if (code < 0) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
- } else if (code == 0) {
- this.taos = TSDBConstants.JNI_NULL_POINTER;
- } else {
- throw new SQLException("Undefined error code returned by TDengine when closing a connection");
- }
-
- // invoke closeConnectionImpl only here
- taosInfo.connect_close_increment();
- }
-
- private native int closeConnectionImp(long connection);
-
- /*****************************************************************************************/
- // NOTE: subscribe
-
- /**
- * Create a subscription
- */
- long subscribe(String topic, String sql, boolean restart) {
- return subscribeImp(this.taos, restart, topic, sql, 0);
- }
-
- private native long subscribeImp(long connection, boolean restart, String topic, String sql, int period);
-
- /**
- * Consume a subscription
- */
- long consume(long subscription) {
- return this.consumeImp(subscription);
- }
-
- private native long consumeImp(long subscription);
-
- /**
- * Unsubscribe, close a subscription
- */
- void unsubscribe(long subscription, boolean isKeep) {
- unsubscribeImp(subscription, isKeep);
- }
-
- private native void unsubscribeImp(long subscription, boolean isKeep);
-
- /******************************************************************************************************/
- // NOTE: parameter binding
- public long prepareStmt(String sql) throws SQLException {
- long stmt = prepareStmtImp(sql.getBytes(), this.taos);
-
- if (stmt == TSDBConstants.JNI_CONNECTION_NULL) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL, "connection already closed");
- }
- if (stmt == TSDBConstants.JNI_SQL_NULL) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_SQL_NULL);
- }
- if (stmt == TSDBConstants.JNI_OUT_OF_MEMORY) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY);
- }
- if (stmt == TSDBConstants.JNI_TDENGINE_ERROR) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_TDENGINE_ERROR);
- }
-
- return stmt;
- }
-
- private native long prepareStmtImp(byte[] sql, long con);
-
- public void setBindTableName(long stmt, String tableName) throws SQLException {
- int code = setBindTableNameImp(stmt, tableName, this.taos);
- if (code != TSDBConstants.JNI_SUCCESS) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN,
- "failed to set table name, reason: " + stmtErrorMsgImp(stmt, this.taos));
- }
- }
-
- private native int setBindTableNameImp(long stmt, String name, long conn);
-
- public void setBindTableNameAndTags(long stmt, String tableName, int numOfTags, ByteBuffer tags,
- ByteBuffer typeList, ByteBuffer lengthList, ByteBuffer nullList) throws SQLException {
- int code = setTableNameTagsImp(stmt, tableName, numOfTags, tags.array(), typeList.array(), lengthList.array(), nullList.array(), this.taos);
- if (code != TSDBConstants.JNI_SUCCESS) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN,
- "failed to bind table name and corresponding tags, reason: " + stmtErrorMsgImp(stmt, this.taos));
- }
- }
-
- private native int setTableNameTagsImp(long stmt, String name, int numOfTags, byte[] tags, byte[] typeList, byte[] lengthList, byte[] nullList, long conn);
-
- public void bindColumnDataArray(long stmt, ByteBuffer colDataList, ByteBuffer lengthList, ByteBuffer isNullList, int type, int bytes, int numOfRows, int columnIndex) throws SQLException {
- int code = bindColDataImp(stmt, colDataList.array(), lengthList.array(), isNullList.array(), type, bytes, numOfRows, columnIndex, this.taos);
- if (code != TSDBConstants.JNI_SUCCESS) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN,
- "failed to bind column data, reason: " + stmtErrorMsgImp(stmt, this.taos));
- }
- }
-
- private native int bindColDataImp(long stmt, byte[] colDataList, byte[] lengthList, byte[] isNullList, int type, int bytes, int numOfRows, int columnIndex, long conn);
-
- public void executeBatch(long stmt) throws SQLException {
- int code = executeBatchImp(stmt, this.taos);
- if (code != TSDBConstants.JNI_SUCCESS) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN,
- "failed to execute batch bind, reason: " + stmtErrorMsgImp(stmt, this.taos));
- }
- }
-
- public void addBatch(long stmt) throws SQLException {
- int code = addBatchImp(stmt, this.taos);
- if (code != TSDBConstants.JNI_SUCCESS) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, stmtErrorMsgImp(stmt, this.taos));
- }
- }
-
- private native int addBatchImp(long stmt, long con);
-
- private native int executeBatchImp(long stmt, long con);
-
- public void closeBatch(long stmt) throws SQLException {
- int code = closeStmt(stmt, this.taos);
- if (code != TSDBConstants.JNI_SUCCESS) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to close batch bind");
- }
- }
-
- private native int closeStmt(long stmt, long con);
-
- private native String stmtErrorMsgImp(long stmt, long con);
-
- /*************************************************************************************************/
- // NOTE: schemaless-lines
- public void insertLines(String[] lines, SchemalessProtocolType protocolType, SchemalessTimestampType timestampType) throws SQLException {
- long pSql = schemalessInsertImp(lines, this.taos, protocolType.ordinal(), timestampType.ordinal());
- try {
- if (pSql == TSDBConstants.JNI_CONNECTION_NULL) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
- }
- if (pSql == TSDBConstants.JNI_OUT_OF_MEMORY) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_OUT_OF_MEMORY);
- }
-
- int code = this.getErrCode(pSql);
- if (code != TSDBConstants.JNI_SUCCESS) {
- String msg = this.getErrMsg(pSql);
- throw TSDBError.createSQLException(code, msg);
- }
- } finally {
- this.freeResultSetImp(this.taos, pSql);
- }
- }
-
- private native long schemalessInsertImp(String[] lines, long conn, int type, int precision);
-}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBParameterMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBParameterMetaData.java
deleted file mode 100644
index 9ee23e3a265298632a953b4a3feedeaf933905ca..0000000000000000000000000000000000000000
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBParameterMetaData.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.taosdata.jdbc;
-
-public class TSDBParameterMetaData extends AbstractParameterMetaData {
-
- public TSDBParameterMetaData(Object[] parameters) {
- super(parameters);
- }
-}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
deleted file mode 100644
index 7e02d80ae8224dadbb8984ca486632d53d903ef3..0000000000000000000000000000000000000000
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java
+++ /dev/null
@@ -1,971 +0,0 @@
-/***************************************************************************
- * 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 com.taosdata.jdbc.utils.Utils;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-import java.math.BigDecimal;
-import java.net.URL;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.sql.*;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/*
- * TDengine only supports a subset of the standard SQL, thus this implementation of the
- * standard JDBC API contains more or less some adjustments customized for certain
- * compatibility needs.
- */
-public class TSDBPreparedStatement extends TSDBStatement implements PreparedStatement {
- // for jdbc preparedStatement interface
- private String rawSql;
- private Object[] parameters;
- // for parameter binding
- private long nativeStmtHandle;
- private String tableName;
- private ArrayList tableTags;
- private int tagValueLength;
- private ArrayList colData;
-
- TSDBPreparedStatement(TSDBConnection connection, String sql) throws SQLException {
- super(connection);
- init(sql);
- int parameterCnt = 0;
- if (!sql.contains("?"))
- return;
- for (int i = 0; i < sql.length(); i++) {
- if ('?' == sql.charAt(i)) {
- parameterCnt++;
- }
- }
- parameters = new Object[parameterCnt];
- // for parameter-binding
-// TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector();
-// this.nativeStmtHandle = connector.prepareStmt(rawSql);
-
- if (parameterCnt > 1) {
- // the table name is also a parameter, so ignore it.
- this.colData = new ArrayList<>();
- this.tableTags = new ArrayList<>();
- }
- }
-
- private void init(String sql) {
- this.rawSql = sql;
- preprocessSql();
- }
-
- /**
- * Some of the SQLs sent by other popular frameworks or tools like Spark, contains syntax that cannot be parsed by
- * the TDengine client. Thus, some simple parsers/filters are intentionally added in this JDBC implementation in
- * order to process those supported SQLs.
- */
- private void preprocessSql() {
- /***For processing some of Spark SQLs*/
- // SELECT * FROM db.tb WHERE 1=0
- this.rawSql = this.rawSql.replaceAll("WHERE 1=0", "WHERE _c0=1");
- this.rawSql = this.rawSql.replaceAll("WHERE 1=2", "WHERE _c0=1");
-
- // SELECT "ts","val" FROM db.tb
- this.rawSql = this.rawSql.replaceAll("\"", "");
-
- /***** For processing inner subqueries *****/
- Pattern pattern = Pattern.compile("FROM\\s+((\\(.+\\))\\s+SUB_QRY)", Pattern.CASE_INSENSITIVE);
- Matcher matcher = pattern.matcher(rawSql);
- String tableFullName = "";
- if (matcher.find() && matcher.groupCount() == 2) {
- String subQry = matcher.group(2);
- Pattern pattern1 = Pattern.compile("FROM\\s+(\\w+\\.\\w+)", Pattern.CASE_INSENSITIVE);
- Matcher matcher1 = pattern1.matcher(subQry);
- if (matcher1.find() && matcher1.groupCount() == 1) {
- tableFullName = matcher1.group(1);
- }
- rawSql = rawSql.replace(matcher.group(1), tableFullName);
- }
- }
-
- @Override
- public ResultSet executeQuery() throws SQLException {
- final String sql = Utils.getNativeSql(this.rawSql, this.parameters);
- return executeQuery(sql);
- }
-
- @Override
- public int executeUpdate() throws SQLException {
- String sql = Utils.getNativeSql(this.rawSql, this.parameters);
- return executeUpdate(sql);
- }
-
- @Override
- public void setNull(int parameterIndex, int sqlType) throws SQLException {
- setObject(parameterIndex, null);
- }
-
- @Override
- public void setBoolean(int parameterIndex, boolean x) throws SQLException {
- setObject(parameterIndex, x);
- }
-
- @Override
- public void setByte(int parameterIndex, byte x) throws SQLException {
- setObject(parameterIndex, x);
- }
-
- @Override
- public void setShort(int parameterIndex, short x) throws SQLException {
- setObject(parameterIndex, x);
- }
-
- @Override
- public void setInt(int parameterIndex, int x) throws SQLException {
- setObject(parameterIndex, x);
- }
-
- @Override
- public void setLong(int parameterIndex, long x) throws SQLException {
- setObject(parameterIndex, x);
- }
-
- @Override
- public void setFloat(int parameterIndex, float x) throws SQLException {
- setObject(parameterIndex, x);
- }
-
- @Override
- public void setDouble(int parameterIndex, double x) throws SQLException {
- setObject(parameterIndex, x);
- }
-
- @Override
- public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
- setObject(parameterIndex, x.doubleValue());
- }
-
- @Override
- public void setString(int parameterIndex, String x) throws SQLException {
- setObject(parameterIndex, x);
- }
-
- @Override
- public void setBytes(int parameterIndex, byte[] x) throws SQLException {
- setObject(parameterIndex, x);
- }
-
- @Override
- public void setDate(int parameterIndex, Date x) throws SQLException {
- setObject(parameterIndex, new Timestamp(x.getTime()));
- }
-
- @Override
- public void setTime(int parameterIndex, Time x) throws SQLException {
- setObject(parameterIndex, new Timestamp(x.getTime()));
- }
-
- @Override
- public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
- setObject(parameterIndex, x);
- }
-
- @Override
- public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void clearParameters() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- parameters = new Object[parameters.length];
- }
-
- @Override
- public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- setObject(parameterIndex, x);
- }
-
- @Override
- public void setObject(int parameterIndex, Object x) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- if (parameterIndex < 1 && parameterIndex >= parameters.length)
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PARAMETER_INDEX_OUT_RANGE);
- parameters[parameterIndex - 1] = x;
- }
-
- @Override
- public boolean execute() throws SQLException {
- final String sql = Utils.getNativeSql(this.rawSql, this.parameters);
- return execute(sql);
- }
-
- @Override
- public void addBatch() throws SQLException {
- String sql = Utils.getNativeSql(this.rawSql, this.parameters);
- addBatch(sql);
- }
-
- @Override
- public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setRef(int parameterIndex, Ref x) throws SQLException {
- if (isClosed()) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- }
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setBlob(int parameterIndex, Blob x) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setClob(int parameterIndex, Clob x) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setArray(int parameterIndex, Array x) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public ResultSetMetaData getMetaData() throws SQLException {
- if (this.getResultSet() == null)
- return null;
- return getResultSet().getMetaData();
- }
-
- @Override
- public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setURL(int parameterIndex, URL x) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public ParameterMetaData getParameterMetaData() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
-
- return new TSDBParameterMetaData(parameters);
- }
-
- @Override
- public void setRowId(int parameterIndex, RowId x) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setNString(int parameterIndex, String value) throws SQLException {
- setString(parameterIndex, value);
- }
-
- @Override
- public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setNClob(int parameterIndex, NClob value) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setClob(int parameterIndex, Reader reader) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void setNClob(int parameterIndex, Reader reader) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED);
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- ///////////////////////////////////////////////////////////////////////
- // NOTE: the following APIs are not JDBC compatible
- // parameter binding
- private static class ColumnInfo {
- @SuppressWarnings("rawtypes")
- private ArrayList data;
- private int type;
- private int bytes;
- private boolean typeIsSet;
-
- public ColumnInfo() {
- this.typeIsSet = false;
- }
-
- public void setType(int type) throws SQLException {
- if (this.isTypeSet()) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data type has been set");
- }
-
- this.typeIsSet = true;
- this.type = type;
- }
-
- public boolean isTypeSet() {
- return this.typeIsSet;
- }
- }
-
- private static class TableTagInfo {
- private boolean isNull;
- private final Object value;
- private final int type;
-
- public TableTagInfo(Object value, int type) {
- this.value = value;
- this.type = type;
- }
-
- public static TableTagInfo createNullTag(int type) {
- TableTagInfo info = new TableTagInfo(null, type);
- info.isNull = true;
- return info;
- }
- }
-
- public void setTableName(String name) throws SQLException {
-
- if (this.nativeStmtHandle == 0) {
- TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector();
- this.nativeStmtHandle = connector.prepareStmt(rawSql);
- }
-
- if (this.tableName != null) {
- this.columnDataAddBatch();
- this.columnDataClearBatchInternal();
- }
- this.tableName = name;
- }
-
- private void ensureTagCapacity(int index) {
- if (this.tableTags.size() < index + 1) {
- int delta = index + 1 - this.tableTags.size();
- this.tableTags.addAll(Collections.nCopies(delta, null));
- }
- }
-
- public void setTagNull(int index, int type) {
- ensureTagCapacity(index);
- this.tableTags.set(index, TableTagInfo.createNullTag(type));
- }
-
- public void setTagBoolean(int index, boolean value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BOOL));
- this.tagValueLength += Byte.BYTES;
- }
-
- public void setTagInt(int index, int value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_INT));
- this.tagValueLength += Integer.BYTES;
- }
-
- public void setTagByte(int index, byte value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TINYINT));
- this.tagValueLength += Byte.BYTES;
- }
-
- public void setTagShort(int index, short value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_SMALLINT));
- this.tagValueLength += Short.BYTES;
- }
-
- public void setTagLong(int index, long value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BIGINT));
- this.tagValueLength += Long.BYTES;
- }
-
- public void setTagTimestamp(int index, long value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP));
- this.tagValueLength += Long.BYTES;
- }
-
- public void setTagFloat(int index, float value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_FLOAT));
- this.tagValueLength += Float.BYTES;
- }
-
- public void setTagDouble(int index, double value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_DOUBLE));
- this.tagValueLength += Double.BYTES;
- }
-
- public void setTagString(int index, String value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_BINARY));
- this.tagValueLength += value.getBytes().length;
- }
-
- public void setTagNString(int index, String value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_NCHAR));
-
- String charset = TaosGlobalConfig.getCharset();
- try {
- this.tagValueLength += value.getBytes(charset).length;
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e.getMessage());
- }
- }
-
- public void setTagJson(int index, String value) {
- ensureTagCapacity(index);
- this.tableTags.set(index, new TableTagInfo(value, TSDBConstants.TSDB_DATA_TYPE_JSON));
-
- String charset = TaosGlobalConfig.getCharset();
- try {
- this.tagValueLength += value.getBytes(charset).length;
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e.getMessage());
- }
- }
-
- public void setValueImpl(int columnIndex, ArrayList list, int type, int bytes) throws SQLException {
- if (this.colData.size() == 0) {
- this.colData.addAll(Collections.nCopies(this.parameters.length - 1 - this.tableTags.size(), null));
- }
-
- ColumnInfo col = this.colData.get(columnIndex);
- if (col == null) {
- ColumnInfo p = new ColumnInfo();
- p.setType(type);
- p.bytes = bytes;
- p.data = (ArrayList>) list.clone();
- this.colData.set(columnIndex, p);
- } else {
- if (col.type != type) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data type mismatch");
- }
- col.data.addAll(list);
- }
- }
-
- public void setInt(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_INT, Integer.BYTES);
- }
-
- public void setFloat(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_FLOAT, Float.BYTES);
- }
-
- public void setTimestamp(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP, Long.BYTES);
- }
-
- public void setLong(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BIGINT, Long.BYTES);
- }
-
- public void setDouble(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_DOUBLE, Double.BYTES);
- }
-
- public void setBoolean(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BOOL, Byte.BYTES);
- }
-
- public void setByte(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_TINYINT, Byte.BYTES);
- }
-
- public void setShort(int columnIndex, ArrayList list) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_SMALLINT, Short.BYTES);
- }
-
- public void setString(int columnIndex, ArrayList list, int size) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_BINARY, size);
- }
-
- // note: expand the required space for each NChar character
- public void setNString(int columnIndex, ArrayList list, int size) throws SQLException {
- setValueImpl(columnIndex, list, TSDBConstants.TSDB_DATA_TYPE_NCHAR, size * Integer.BYTES);
- }
-
- public void columnDataAddBatch() throws SQLException {
- // pass the data block to native code
- if (rawSql == null) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "sql statement not set yet");
- }
- // table name is not set yet, abort
- if (this.tableName == null) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "table name not set yet");
- }
-
- int numOfCols = this.colData.size();
- if (numOfCols == 0) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind");
- }
- if (nativeStmtHandle == 0) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "stmt is null");
- }
-
- TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector();
- if (this.tableTags == null) {
- connector.setBindTableName(this.nativeStmtHandle, this.tableName);
- } else {
- int tagSize = this.tableTags.size();
- ByteBuffer tagDataList = ByteBuffer.allocate(this.tagValueLength);
- tagDataList.order(ByteOrder.LITTLE_ENDIAN);
-
- ByteBuffer typeList = ByteBuffer.allocate(tagSize);
- typeList.order(ByteOrder.LITTLE_ENDIAN);
-
- ByteBuffer lengthList = ByteBuffer.allocate(tagSize * Long.BYTES);
- lengthList.order(ByteOrder.LITTLE_ENDIAN);
-
- ByteBuffer isNullList = ByteBuffer.allocate(tagSize * Integer.BYTES);
- isNullList.order(ByteOrder.LITTLE_ENDIAN);
-
- for (TableTagInfo tag : this.tableTags) {
- if (tag.isNull) {
- typeList.put((byte) tag.type);
- isNullList.putInt(1);
- lengthList.putLong(0);
- continue;
- }
-
- switch (tag.type) {
- case TSDBConstants.TSDB_DATA_TYPE_INT: {
- Integer val = (Integer) tag.value;
- tagDataList.putInt(val);
- lengthList.putLong(Integer.BYTES);
- break;
- }
- case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
- Byte val = (Byte) tag.value;
- tagDataList.put(val);
- lengthList.putLong(Byte.BYTES);
- break;
- }
- case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
- Boolean val = (Boolean) tag.value;
- tagDataList.put((byte) (val ? 1 : 0));
- lengthList.putLong(Byte.BYTES);
- break;
- }
- case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
- Short val = (Short) tag.value;
- tagDataList.putShort(val);
- lengthList.putLong(Short.BYTES);
- break;
- }
- case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
- case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
- Long val = (Long) tag.value;
- tagDataList.putLong(val == null ? 0 : val);
- lengthList.putLong(Long.BYTES);
- break;
- }
- case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
- Float val = (Float) tag.value;
- tagDataList.putFloat(val == null ? 0 : val);
- lengthList.putLong(Float.BYTES);
- break;
- }
- case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
- Double val = (Double) tag.value;
- tagDataList.putDouble(val == null ? 0 : val);
- lengthList.putLong(Double.BYTES);
- break;
- }
- case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
- case TSDBConstants.TSDB_DATA_TYPE_JSON:
- case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
- String charset = TaosGlobalConfig.getCharset();
- String val = (String) tag.value;
- byte[] b;
- try {
- if (tag.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) {
- b = val.getBytes();
- } else {
- b = val.getBytes(charset);
- }
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e.getMessage());
- }
- tagDataList.put(b);
- lengthList.putLong(b.length);
- break;
- }
- case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
- case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
- case TSDBConstants.TSDB_DATA_TYPE_UINT:
- case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types");
- }
- }
- typeList.put((byte) tag.type);
- isNullList.putInt(tag.isNull ? 1 : 0);
- }
-
- connector.setBindTableNameAndTags(this.nativeStmtHandle, this.tableName, this.tableTags.size(),
- tagDataList, typeList, lengthList, isNullList);
- }
-
- ColumnInfo colInfo = this.colData.get(0);
- if (colInfo == null) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind");
- }
-
- int rows = colInfo.data.size();
- for (int i = 0; i < numOfCols; ++i) {
- ColumnInfo col1 = this.colData.get(i);
- if (col1 == null || !col1.isTypeSet()) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "column data not bind");
- }
- if (rows != col1.data.size()) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "the rows in column data not identical");
- }
-
- ByteBuffer colDataList = ByteBuffer.allocate(rows * col1.bytes);
- colDataList.order(ByteOrder.LITTLE_ENDIAN);
-
- ByteBuffer lengthList = ByteBuffer.allocate(rows * Integer.BYTES);
- lengthList.order(ByteOrder.LITTLE_ENDIAN);
-
- ByteBuffer isNullList = ByteBuffer.allocate(rows * Byte.BYTES);
- isNullList.order(ByteOrder.LITTLE_ENDIAN);
-
- switch (col1.type) {
- case TSDBConstants.TSDB_DATA_TYPE_INT: {
- for (int j = 0; j < rows; ++j) {
- Integer val = (Integer) col1.data.get(j);
- colDataList.putInt(val == null ? Integer.MIN_VALUE : val);
- isNullList.put((byte) (val == null ? 1 : 0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_TINYINT: {
- for (int j = 0; j < rows; ++j) {
- Byte val = (Byte) col1.data.get(j);
- colDataList.put(val == null ? 0 : val);
- isNullList.put((byte) (val == null ? 1 : 0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_BOOL: {
- for (int j = 0; j < rows; ++j) {
- Boolean val = (Boolean) col1.data.get(j);
- if (val == null) {
- colDataList.put((byte) 0);
- } else {
- colDataList.put((byte) (val ? 1 : 0));
- }
-
- isNullList.put((byte) (val == null ? 1 : 0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: {
- for (int j = 0; j < rows; ++j) {
- Short val = (Short) col1.data.get(j);
- colDataList.putShort(val == null ? 0 : val);
- isNullList.put((byte) (val == null ? 1 : 0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
- case TSDBConstants.TSDB_DATA_TYPE_BIGINT: {
- for (int j = 0; j < rows; ++j) {
- Long val = (Long) col1.data.get(j);
- colDataList.putLong(val == null ? 0 : val);
- isNullList.put((byte) (val == null ? 1 : 0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_FLOAT: {
- for (int j = 0; j < rows; ++j) {
- Float val = (Float) col1.data.get(j);
- colDataList.putFloat(val == null ? 0 : val);
- isNullList.put((byte) (val == null ? 1 : 0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: {
- for (int j = 0; j < rows; ++j) {
- Double val = (Double) col1.data.get(j);
- colDataList.putDouble(val == null ? 0 : val);
- isNullList.put((byte) (val == null ? 1 : 0));
- }
- break;
- }
-
- case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
- case TSDBConstants.TSDB_DATA_TYPE_BINARY: {
- String charset = TaosGlobalConfig.getCharset();
- for (int j = 0; j < rows; ++j) {
- String val = (String) col1.data.get(j);
-
- colDataList.position(j * col1.bytes); // seek to the correct position
- if (val != null) {
- byte[] b = null;
- try {
- if (col1.type == TSDBConstants.TSDB_DATA_TYPE_BINARY) {
- b = val.getBytes();
- } else {
- b = val.getBytes(charset);
- }
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e.getMessage());
- }
-
- if (val.length() > col1.bytes) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "string data too long");
- }
-
- colDataList.put(b);
- lengthList.putInt(b.length);
- isNullList.put((byte) 0);
- } else {
- lengthList.putInt(0);
- isNullList.put((byte) 1);
- }
- }
- break;
- }
- case TSDBConstants.TSDB_DATA_TYPE_UTINYINT:
- case TSDBConstants.TSDB_DATA_TYPE_USMALLINT:
- case TSDBConstants.TSDB_DATA_TYPE_UINT:
- case TSDBConstants.TSDB_DATA_TYPE_UBIGINT: {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "not support data types");
- }
- }
-
- connector.bindColumnDataArray(this.nativeStmtHandle, colDataList, lengthList, isNullList, col1.type, col1.bytes, rows, i);
- }
- connector.addBatch(this.nativeStmtHandle);
- this.columnDataClearBatchInternal();
- }
-
- public void columnDataExecuteBatch() throws SQLException {
- TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector();
- connector.executeBatch(this.nativeStmtHandle);
- this.columnDataClearBatchInternal();
- }
-
- @Deprecated
- public void columnDataClearBatch() {
- columnDataClearBatchInternal();
- }
-
- private void columnDataClearBatchInternal() {
- this.tableName = null;
- if (this.tableTags != null)
- this.tableTags.clear();
- tagValueLength = 0;
- if (this.colData != null)
- this.colData.clear();
- }
-
- public void columnDataCloseBatch() throws SQLException {
- TSDBJNIConnector connector = ((TSDBConnection) this.getConnection()).getConnector();
- connector.closeBatch(this.nativeStmtHandle);
-
- this.nativeStmtHandle = 0L;
- this.tableName = null;
- }
-
- @Override
- public void close() throws SQLException {
- if (this.nativeStmtHandle != 0L) {
- this.columnDataClearBatchInternal();
- this.columnDataCloseBatch();
- }
- super.close();
- }
-}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
deleted file mode 100644
index e1e15d0332ca465c31c2ef2726b181716298378e..0000000000000000000000000000000000000000
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet.java
+++ /dev/null
@@ -1,490 +0,0 @@
-/***************************************************************************
- * 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 com.google.common.primitives.Ints;
-import com.google.common.primitives.Longs;
-import com.google.common.primitives.Shorts;
-
-import java.math.BigDecimal;
-import java.sql.*;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-
-public class TSDBResultSet extends AbstractResultSet implements ResultSet {
- private final TSDBJNIConnector jniConnector;
- private final TSDBStatement statement;
- private final long resultSetPointer;
- private List columnMetaDataList = new ArrayList<>();
- private final TSDBResultSetRowData rowData;
- private final TSDBResultSetBlockData blockData;
-
- private boolean batchFetch;
- private boolean lastWasNull;
- private boolean isClosed;
-
- public void setBatchFetch(boolean batchFetch) {
- this.batchFetch = batchFetch;
- }
-
- public Boolean getBatchFetch() {
- return this.batchFetch;
- }
-
- public void setColumnMetaDataList(List columnMetaDataList) {
- this.columnMetaDataList = columnMetaDataList;
- }
-
- public TSDBResultSetRowData getRowData() {
- return rowData;
- }
-
- public TSDBResultSet(TSDBStatement statement, TSDBJNIConnector connector, long resultSetPointer, int timestampPrecision) throws SQLException {
- this.statement = statement;
- this.jniConnector = connector;
- this.resultSetPointer = resultSetPointer;
-
- int code = this.jniConnector.getSchemaMetaData(this.resultSetPointer, this.columnMetaDataList);
- if (code == TSDBConstants.JNI_CONNECTION_NULL) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
- }
- if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
- }
- if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0);
- }
- this.rowData = new TSDBResultSetRowData(this.columnMetaDataList.size());
- this.blockData = new TSDBResultSetBlockData(this.columnMetaDataList, this.columnMetaDataList.size(), timestampPrecision);
- this.timestampPrecision = timestampPrecision;
- }
-
- public boolean next() throws SQLException {
- if (this.getBatchFetch()) {
- if (this.blockData.forward())
- return true;
-
- int code = this.jniConnector.fetchBlock(this.resultSetPointer, this.blockData);
- this.blockData.reset();
-
- if (code == TSDBConstants.JNI_CONNECTION_NULL) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
- } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
- } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0);
- } else return code != TSDBConstants.JNI_FETCH_END;
- } else {
- if (rowData != null) {
- this.rowData.clear();
- }
- int code = this.jniConnector.fetchRow(this.resultSetPointer, this.rowData);
- if (code == TSDBConstants.JNI_CONNECTION_NULL) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
- } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
- } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0);
- } else if (code == TSDBConstants.JNI_FETCH_END) {
- return false;
- } else {
- return true;
- }
- }
- }
-
- public void close() throws SQLException {
- if (isClosed)
- return;
- if (this.statement == null)
- return;
- if (this.jniConnector != null) {
- int code = this.jniConnector.freeResultSet(this.resultSetPointer);
- if (code == TSDBConstants.JNI_CONNECTION_NULL) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL);
- } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) {
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
- }
- }
- isClosed = true;
- }
-
- public boolean wasNull() throws SQLException {
- return this.lastWasNull;
- }
-
- public String getString(int columnIndex) throws SQLException {
- checkAvailability(columnIndex, this.columnMetaDataList.size());
-
- String res = null;
- if (this.getBatchFetch())
- return this.blockData.getString(columnIndex - 1);
-
- this.lastWasNull = this.rowData.wasNull(columnIndex);
- if (!lastWasNull) {
- int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- res = this.rowData.getString(columnIndex, nativeType);
- }
- return res;
- }
-
- public boolean getBoolean(int columnIndex) throws SQLException {
- checkAvailability(columnIndex, this.columnMetaDataList.size());
-
- boolean res = false;
- if (this.getBatchFetch())
- return this.blockData.getBoolean(columnIndex - 1);
-
- this.lastWasNull = this.rowData.wasNull(columnIndex);
- if (!lastWasNull) {
- int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- res = this.rowData.getBoolean(columnIndex, nativeType);
- }
- return res;
- }
-
- public byte getByte(int columnIndex) throws SQLException {
- checkAvailability(columnIndex, this.columnMetaDataList.size());
-
- byte res = 0;
- if (this.getBatchFetch())
- return (byte) this.blockData.getInt(columnIndex - 1);
-
- this.lastWasNull = this.rowData.wasNull(columnIndex);
- if (!lastWasNull) {
- int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- res = (byte) this.rowData.getInt(columnIndex, nativeType);
- }
- return res;
- }
-
- public short getShort(int columnIndex) throws SQLException {
- checkAvailability(columnIndex, this.columnMetaDataList.size());
-
- short res = 0;
- if (this.getBatchFetch())
- return (short) this.blockData.getInt(columnIndex - 1);
-
- this.lastWasNull = this.rowData.wasNull(columnIndex);
- if (!lastWasNull) {
- int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- res = (short) this.rowData.getInt(columnIndex, nativeType);
- }
- return res;
- }
-
- public int getInt(int columnIndex) throws SQLException {
- checkAvailability(columnIndex, this.columnMetaDataList.size());
-
- int res = 0;
- if (this.getBatchFetch())
- return this.blockData.getInt(columnIndex - 1);
-
-
- this.lastWasNull = this.rowData.wasNull(columnIndex);
- if (!lastWasNull) {
- int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- res = this.rowData.getInt(columnIndex, nativeType);
- }
- return res;
- }
-
- public long getLong(int columnIndex) throws SQLException {
- checkAvailability(columnIndex, this.columnMetaDataList.size());
-
- long res = 0L;
- if (this.getBatchFetch())
- return this.blockData.getLong(columnIndex - 1);
-
- this.lastWasNull = this.rowData.wasNull(columnIndex);
- if (!lastWasNull) {
- Object value = this.rowData.getObject(columnIndex);
- if (value instanceof Timestamp) {
- Timestamp ts = (Timestamp) value;
- long epochSec = ts.getTime() / 1000;
- long nanoAdjustment = ts.getNanos();
- switch (this.timestampPrecision) {
- case 0:
- default: // ms
- return ts.getTime();
- case 1: // us
- return epochSec * 1000_000L + nanoAdjustment / 1000L;
- case 2: // ns
- return epochSec * 1000_000_000L + nanoAdjustment;
- }
- } else {
- int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- res = this.rowData.getLong(columnIndex, nativeType);
- }
- }
- return res;
- }
-
- public float getFloat(int columnIndex) throws SQLException {
- checkAvailability(columnIndex, this.columnMetaDataList.size());
-
- float res = 0;
- if (this.getBatchFetch())
- return (float) this.blockData.getDouble(columnIndex - 1);
-
- this.lastWasNull = this.rowData.wasNull(columnIndex);
- if (!lastWasNull) {
- int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- res = this.rowData.getFloat(columnIndex, nativeType);
- }
-
- return res;
- }
-
- public double getDouble(int columnIndex) throws SQLException {
- checkAvailability(columnIndex, this.columnMetaDataList.size());
-
- double res = 0;
- if (this.getBatchFetch())
- return this.blockData.getDouble(columnIndex - 1);
-
- this.lastWasNull = this.rowData.wasNull(columnIndex);
- if (!lastWasNull) {
- int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- res = this.rowData.getDouble(columnIndex, nativeType);
- }
- return res;
- }
-
- public byte[] getBytes(int columnIndex) throws SQLException {
- checkAvailability(columnIndex, this.columnMetaDataList.size());
-
- if (this.getBatchFetch())
- return this.blockData.getBytes(columnIndex -1);
-
- Object value = this.rowData.getObject(columnIndex);
- this.lastWasNull = value == null;
- if (value == null)
- return null;
-
- int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- switch (nativeType) {
- case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
- return Longs.toByteArray((long) value);
- case TSDBConstants.TSDB_DATA_TYPE_INT:
- return Ints.toByteArray((int) value);
- case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
- return Shorts.toByteArray((short) value);
- case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
- return new byte[]{(byte) value};
- case TSDBConstants.TSDB_DATA_TYPE_BINARY:
- return (byte[]) value;
- case TSDBConstants.TSDB_DATA_TYPE_BOOL:
- case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
- default:
- return value.toString().getBytes();
- }
- }
-
- public Timestamp getTimestamp(int columnIndex) throws SQLException {
- checkAvailability(columnIndex, this.columnMetaDataList.size());
-
- Timestamp res = null;
- if (this.getBatchFetch())
- return this.blockData.getTimestamp(columnIndex - 1);
-
- this.lastWasNull = this.rowData.wasNull(columnIndex);
- if (!lastWasNull) {
- int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- res = this.rowData.getTimestamp(columnIndex, nativeType);
- }
- return res;
- }
-
- public ResultSetMetaData getMetaData() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- return new TSDBResultSetMetaData(this.columnMetaDataList);
- }
-
- @Override
- public Object getObject(int columnIndex) throws SQLException {
- checkAvailability(columnIndex, this.columnMetaDataList.size());
-
- Object res = null;
- if (this.getBatchFetch())
- return this.blockData.get(columnIndex - 1);
-
- this.lastWasNull = this.rowData.wasNull(columnIndex);
- if (!lastWasNull) {
- res = this.rowData.getObject(columnIndex);
- }
- return res;
- }
-
- public int findColumn(String columnLabel) throws SQLException {
- for (ColumnMetaData colMetaData : this.columnMetaDataList) {
- if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) {
- return colMetaData.getColIndex();
- }
- }
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
- }
-
- @Override
- public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
- if (this.getBatchFetch())
- return BigDecimal.valueOf(this.blockData.getDouble(columnIndex - 1));
-
- this.lastWasNull = this.rowData.wasNull(columnIndex);
- if (lastWasNull)
- return null;
-
- BigDecimal res;
- int nativeType = this.columnMetaDataList.get(columnIndex - 1).getColType();
- switch (nativeType) {
- case TSDBConstants.TSDB_DATA_TYPE_TINYINT:
- case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:
- case TSDBConstants.TSDB_DATA_TYPE_INT:
- case TSDBConstants.TSDB_DATA_TYPE_BIGINT:
- res = new BigDecimal(Long.parseLong(this.rowData.getObject(columnIndex).toString()));
- break;
- case TSDBConstants.TSDB_DATA_TYPE_FLOAT:
- case TSDBConstants.TSDB_DATA_TYPE_DOUBLE:
- res = BigDecimal.valueOf(Double.parseDouble(this.rowData.getObject(columnIndex).toString()));
- break;
- case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
- return new BigDecimal(((Timestamp) this.rowData.getObject(columnIndex)).getTime());
- default:
- res = new BigDecimal(this.rowData.getObject(columnIndex).toString());
- }
- return res;
- }
-
- @Override
- public boolean isBeforeFirst() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public boolean isAfterLast() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public boolean isFirst() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public boolean isLast() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void beforeFirst() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public void afterLast() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public boolean first() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public boolean last() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public int getRow() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public boolean absolute(int row) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public boolean relative(int rows) throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- @Override
- public boolean previous() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
- }
-
- public Statement getStatement() throws SQLException {
- if (isClosed())
- throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_RESULTSET_CLOSED);
-
- return this.statement;
- }
-
- @Override
- public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
- //TODO:did not use the specified timezone in cal
- return getTimestamp(columnIndex);
- }
-
- public boolean isClosed() throws SQLException {
- return isClosed;
- }
-
- public String getNString(int columnIndex) throws SQLException {
- return getString(columnIndex);
- }
-
-}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java
deleted file mode 100644
index 8dcd66ad4751c27139e73a9d77bc524026805e6a..0000000000000000000000000000000000000000
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetBlockData.java
+++ /dev/null
@@ -1,552 +0,0 @@
-/***************************************************************************
- * 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.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.DoubleBuffer;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
-import java.nio.LongBuffer;
-import java.nio.ShortBuffer;
-import java.sql.SQLDataException;
-import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import com.google.common.primitives.Ints;
-import com.google.common.primitives.Longs;
-import com.google.common.primitives.Shorts;
-import com.taosdata.jdbc.enums.TimestampPrecision;
-import com.taosdata.jdbc.utils.NullType;
-
-public class TSDBResultSetBlockData {
- private static final int BINARY_LENGTH_OFFSET = 2;
- private int numOfRows = 0;
- private int rowIndex = 0;
-
- private List columnMetaDataList;
- private ArrayList