From 56d1c42f7ef1e5b2e51e34d221d9df0107d0527b Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Fri, 21 Feb 2020 18:18:42 +0800 Subject: [PATCH] add destIp support for NAT --- .../com/taosdata/jdbc/CatalogResultSet 2.java | 68 + .../com/taosdata/jdbc/ColumnMetaData 2.java | 55 + .../jdbc/DatabaseMetaDataResultSet 2.java | 1057 +++++++++++++++ .../com/taosdata/jdbc/EmptyResultSet 2.java | 986 ++++++++++++++ .../taosdata/jdbc/GetColumnsResultSet 2.java | 51 + .../taosdata/jdbc/GetTablesResultSet 2.java | 53 + .../jdbc/SavedPreparedStatement 2.java | 453 +++++++ .../com/taosdata/jdbc/TSDBConnection 2.java | 352 +++++ .../com/taosdata/jdbc/TSDBConstants 2.java | 86 ++ .../taosdata/jdbc/TSDBDatabaseMetaData 2.java | 800 +++++++++++ .../java/com/taosdata/jdbc/TSDBDriver 2.java | 358 +++++ .../java/com/taosdata/jdbc/TSDBError 2.java | 223 ++++ .../com/taosdata/jdbc/TSDBJNIConnector 2.java | 300 +++++ .../jdbc/TSDBParameterMetaData 2.java | 75 ++ .../jdbc/TSDBPreparedStatement 2.java | 478 +++++++ .../com/taosdata/jdbc/TSDBResultSet 2.java | 1033 +++++++++++++++ .../jdbc/TSDBResultSetMetaData 2.java | 213 +++ .../taosdata/jdbc/TSDBResultSetRowData 2.java | 222 ++++ .../taosdata/jdbc/TSDBResultSetWrapper 2.java | 1172 +++++++++++++++++ .../com/taosdata/jdbc/TSDBStatement 2.java | 294 +++++ .../com/taosdata/jdbc/TaosGlobalConfig 2.java | 30 + .../jdbc/bean/TSDBPreparedParam 2.java | 62 + .../jdbc/utils/SqlSyntaxValidator 2.java | 45 + .../services/.java.sql 2.Driver.icloud | Bin 0 -> 166 bytes src/inc/trpc.h | 5 +- src/rpc/CMakeLists 2.txt | 24 + src/rpc/inc/rpcHead.h | 1 + src/rpc/src/rpcMain.c | 14 +- .../com/cassandra/test/CassandraTest 2.java | 200 +++ .../com/cassandra/test/WriteThread 2.java | 99 ++ .../com/opentsdb/test/OpentsdbTest 2.java | 468 +++++++ .../java/com/opentsdb/test/WriteThread 2.java | 155 +++ .../src/main/resources/.logback 2.xml.icloud | Bin 0 -> 161 bytes .../src/main/java/TSDBSyncSample 2.java | 205 +++ .../main/java/com/taosdata/jdbc/App 2.java | 44 + .../main/resources/applicationContext 2.xml | 24 + .../java/com/taosdata/jdbc/AppTest 2.java | 20 + .../SpringbootdemoApplication 2.java | 15 + .../controller/WeatherController 2.java | 60 + .../springbootdemo/dao/WeatherMapper 2.java | 19 + .../jdbc/springbootdemo/domain/Weather 2.java | 36 + .../service/WeatherService 2.java | 40 + .../main/resources/application 2.properties | 26 + .../main/resources/mapper/WeatherMapper 2.xml | 49 + .../SpringbootdemoApplicationTests 2.java | 13 + 45 files changed, 9977 insertions(+), 6 deletions(-) create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/CatalogResultSet 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/ColumnMetaData 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/EmptyResultSet 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/GetColumnsResultSet 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/GetTablesResultSet 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/SavedPreparedStatement 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData 2.java create mode 100755 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError 2.java create mode 100755 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBParameterMetaData 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetWrapper 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TaosGlobalConfig 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/bean/TSDBPreparedParam 2.java create mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator 2.java create mode 100644 src/connector/jdbc/src/main/resources/META-INF/services/.java.sql 2.Driver.icloud create mode 100644 src/rpc/CMakeLists 2.txt create mode 100644 tests/comparisonTest/cassandra/cassandratest/src/main/java/com/cassandra/test/CassandraTest 2.java create mode 100644 tests/comparisonTest/cassandra/cassandratest/src/main/java/com/cassandra/test/WriteThread 2.java create mode 100644 tests/comparisonTest/opentsdb/opentsdbtest/src/main/java/com/opentsdb/test/OpentsdbTest 2.java create mode 100644 tests/comparisonTest/opentsdb/opentsdbtest/src/main/java/com/opentsdb/test/WriteThread 2.java create mode 100644 tests/comparisonTest/opentsdb/opentsdbtest/src/main/resources/.logback 2.xml.icloud create mode 100644 tests/examples/JDBC/JDBCDemo/src/main/java/TSDBSyncSample 2.java create mode 100644 tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/App 2.java create mode 100644 tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext 2.xml create mode 100644 tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/jdbc/AppTest 2.java create mode 100644 tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplication 2.java create mode 100644 tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/controller/WeatherController 2.java create mode 100644 tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/WeatherMapper 2.java create mode 100644 tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/Weather 2.java create mode 100644 tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/service/WeatherService 2.java create mode 100644 tests/examples/JDBC/springbootdemo/src/main/resources/application 2.properties create mode 100644 tests/examples/JDBC/springbootdemo/src/main/resources/mapper/WeatherMapper 2.xml create mode 100644 tests/examples/JDBC/springbootdemo/src/test/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplicationTests 2.java diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/CatalogResultSet 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/CatalogResultSet 2.java new file mode 100644 index 0000000000..3a01e2e092 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/CatalogResultSet 2.java @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + *****************************************************************************/ +package com.taosdata.jdbc; + +import java.sql.ResultSet; +import java.sql.SQLException; + +/* + * TDengine only supports a subset of the standard SQL, thus this implemetation of the + * standard JDBC API contains more or less some adjustments customized for certain + * compatibility needs. + */ +public class CatalogResultSet extends TSDBResultSetWrapper { + + + public CatalogResultSet(ResultSet resultSet) { + super.setOriginalResultSet(resultSet); + } + + @Override + public String getString(int columnIndex) throws SQLException { + if (columnIndex <= 1) { + return super.getString(columnIndex); + } else { + return null; + } + } + + @Override + public boolean getBoolean(int columnIndex) throws SQLException { + if (columnIndex <= 1) { + return super.getBoolean(columnIndex); + } else { + return false; + } + } + + @Override + public byte[] getBytes(int columnIndex) throws SQLException { + if (columnIndex <= 1) { + return super.getBytes(columnIndex); + } else { + return null; + } + } + + @Override + public Object getObject(int columnIndex) throws SQLException { + if (columnIndex <= 1) { + return super.getObject(columnIndex); + } else { + return null; + } + } + +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/ColumnMetaData 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/ColumnMetaData 2.java new file mode 100644 index 0000000000..5c7f80c715 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/ColumnMetaData 2.java @@ -0,0 +1,55 @@ +/*************************************************************************** + * 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; + +public class ColumnMetaData { + + int colType = 0; + String colName = null; + int colSize = -1; + int colIndex = 0; + + public int getColSize() { + return colSize; + } + + public void setColSize(int colSize) { + this.colSize = colSize; + } + + public int getColType() { + return colType; + } + + public void setColType(int colType) { + this.colType = colType; + } + + public String getColName() { + return colName; + } + + public void setColName(String colName) { + this.colName = colName; + } + + public int getColIndex() { + return colIndex; + } + + public void setColIndex(int colIndex) { + this.colIndex = colIndex; + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet 2.java new file mode 100644 index 0000000000..027d2197a3 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/DatabaseMetaDataResultSet 2.java @@ -0,0 +1,1057 @@ +/*************************************************************************** + * 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.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.*; +import java.sql.Date; +import java.util.*; + +/* + * TDengine only supports a subset of the standard SQL, thus this implemetation of the + * standard JDBC API contains more or less some adjustments customized for certain + * compatibility needs. + */ +public class DatabaseMetaDataResultSet implements ResultSet { + + private List columnMetaDataList; + private List rowDataList; + private TSDBResultSetRowData rowCursor; + + // position of cursor, starts from 0 as beforeFirst, increases as next() is called + private int cursorRowNumber = 0; + + public DatabaseMetaDataResultSet() { + rowDataList = new ArrayList(); + columnMetaDataList = new ArrayList(); + } + + public List getRowDataList() { + return rowDataList; + } + + public void setRowDataList(List rowDataList) { + this.rowDataList = rowDataList; + } + + public List getColumnMetaDataList() { + return columnMetaDataList; + } + + public void setColumnMetaDataList(List columnMetaDataList) { + this.columnMetaDataList = columnMetaDataList; + } + + public TSDBResultSetRowData getRowCursor() { + return rowCursor; + } + + public void setRowCursor(TSDBResultSetRowData rowCursor) { + this.rowCursor = rowCursor; + } + + @Override + public boolean next() throws SQLException { + boolean ret = false; + if (rowDataList.size() > 0) { + ret = rowDataList.iterator().hasNext(); + if (ret) { + rowCursor = rowDataList.iterator().next(); + cursorRowNumber++; + } + } + return ret; + } + + @Override + public void close() throws SQLException { + + } + + @Override + public boolean wasNull() throws SQLException { + return false; + } + + @Override + public String getString(int columnIndex) throws SQLException { + columnIndex--; + return rowCursor.getString(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + } + + @Override + public boolean getBoolean(int columnIndex) throws SQLException { + columnIndex--; + return rowCursor.getBoolean(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + } + + @Override + public byte getByte(int columnIndex) throws SQLException { + return (byte) rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + } + + @Override + public short getShort(int columnIndex) throws SQLException { + return (short) rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + } + + @Override + public int getInt(int columnIndex) throws SQLException { + return rowCursor.getInt(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + } + + @Override + public long getLong(int columnIndex) throws SQLException { + return rowCursor.getLong(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + } + + @Override + public float getFloat(int columnIndex) throws SQLException { + return rowCursor.getFloat(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + } + + @Override + public double getDouble(int columnIndex) throws SQLException { + return rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType()); + } + + @Override + public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { + return new BigDecimal(rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType())); + } + + @Override + public byte[] getBytes(int columnIndex) throws SQLException { + return (rowCursor.getString(columnIndex, columnMetaDataList.get(columnIndex).getColType())).getBytes(); + } + + @Override + public Date getDate(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public Time getTime(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public Timestamp getTimestamp(int columnIndex) throws SQLException { + return rowCursor.getTimestamp(columnIndex); + } + + @Override + public InputStream getAsciiStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public InputStream getUnicodeStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public InputStream getBinaryStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public String getString(String columnLabel) throws SQLException { + return getString(findColumn(columnLabel)); + } + + @Override + public boolean getBoolean(String columnLabel) throws SQLException { + return getBoolean(findColumn(columnLabel)); + } + + @Override + public byte getByte(String columnLabel) throws SQLException { + return getByte(findColumn(columnLabel)); + } + + @Override + public short getShort(String columnLabel) throws SQLException { + return getShort(findColumn(columnLabel)); + } + + @Override + public int getInt(String columnLabel) throws SQLException { + return getInt(findColumn(columnLabel)); + } + + @Override + public long getLong(String columnLabel) throws SQLException { + return getLong(findColumn(columnLabel)); + } + + @Override + public float getFloat(String columnLabel) throws SQLException { + return getFloat(findColumn(columnLabel)); + } + + @Override + public double getDouble(String columnLabel) throws SQLException { + return getDouble(findColumn(columnLabel)); + } + + @Override + public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { + return getBigDecimal(findColumn(columnLabel)); + } + + @Override + public byte[] getBytes(String columnLabel) throws SQLException { + return getBytes(findColumn(columnLabel)); + } + + @Override + public Date getDate(String columnLabel) throws SQLException { + return getDate(findColumn(columnLabel)); + } + + @Override + public Time getTime(String columnLabel) throws SQLException { + return getTime(findColumn(columnLabel)); + } + + @Override + public Timestamp getTimestamp(String columnLabel) throws SQLException { + return getTimestamp(findColumn(columnLabel)); + } + + @Override + public InputStream getAsciiStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public InputStream getUnicodeStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public InputStream getBinaryStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public SQLWarning getWarnings() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void clearWarnings() throws SQLException { + + } + + @Override + public String getCursorName() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + return new TSDBResultSetMetaData(this.columnMetaDataList); + } + + @Override + public Object getObject(int columnIndex) throws SQLException { + return rowCursor.get(columnIndex); + } + + @Override + public Object getObject(String columnLabel) throws SQLException { + return rowCursor.get(findColumn(columnLabel)); + } + + @Override + public int findColumn(String columnLabel) throws SQLException { + Iterator colMetaDataIt = this.columnMetaDataList.iterator(); + while (colMetaDataIt.hasNext()) { + ColumnMetaData colMetaData = colMetaDataIt.next(); + if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) { + return colMetaData.getColIndex() + 1; + } + } + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + } + + @Override + public Reader getCharacterStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public Reader getCharacterStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public BigDecimal getBigDecimal(int columnIndex) throws SQLException { + return new BigDecimal(rowCursor.getDouble(columnIndex, columnMetaDataList.get(columnIndex).getColType())); + } + + @Override + public BigDecimal getBigDecimal(String columnLabel) throws SQLException { + return getBigDecimal(findColumn(columnLabel)); + } + + @Override + public boolean isBeforeFirst() throws SQLException { + return cursorRowNumber == 0; + } + + @Override + public boolean isAfterLast() throws SQLException { + return rowDataList.iterator().hasNext(); + } + + @Override + public boolean isFirst() throws SQLException { + return cursorRowNumber == 1; + } + + @Override + public boolean isLast() throws SQLException { + return cursorRowNumber == rowDataList.size(); + } + + @Override + public void beforeFirst() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void afterLast() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public boolean first() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public boolean last() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public int getRow() throws SQLException { + if (cursorRowNumber > 0 && cursorRowNumber <= rowDataList.size()) { + return cursorRowNumber; + } else { + return 0; + } + + } + + @Override + public boolean absolute(int row) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public boolean relative(int rows) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public boolean previous() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setFetchDirection(int direction) throws SQLException { + + } + + @Override + public int getFetchDirection() throws SQLException { + return ResultSet.FETCH_FORWARD; + } + + @Override + public void setFetchSize(int rows) throws SQLException { + + } + + @Override + public int getFetchSize() throws SQLException { + return 0; + } + + @Override + public int getType() throws SQLException { + return ResultSet.TYPE_FORWARD_ONLY; + } + + @Override + public int getConcurrency() throws SQLException { + return ResultSet.CONCUR_READ_ONLY; + } + + @Override + public boolean rowUpdated() throws SQLException { + return false; + } + + @Override + public boolean rowInserted() throws SQLException { + return false; + } + + @Override + public boolean rowDeleted() throws SQLException { + return false; + } + + @Override + public void updateNull(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateBoolean(int columnIndex, boolean x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateByte(int columnIndex, byte x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateShort(int columnIndex, short x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateInt(int columnIndex, int x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateLong(int columnIndex, long x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateFloat(int columnIndex, float x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateDouble(int columnIndex, double x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateString(int columnIndex, String x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateBytes(int columnIndex, byte[] x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateDate(int columnIndex, Date x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateTime(int columnIndex, Time x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateObject(int columnIndex, Object x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateNull(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateBoolean(String columnLabel, boolean x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateByte(String columnLabel, byte x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateShort(String columnLabel, short x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateInt(String columnLabel, int x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateLong(String columnLabel, long x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateFloat(String columnLabel, float x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateDouble(String columnLabel, double x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateString(String columnLabel, String x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateBytes(String columnLabel, byte[] x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateDate(String columnLabel, Date x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateTime(String columnLabel, Time x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateObject(String columnLabel, Object x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void insertRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void updateRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void deleteRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void refreshRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void cancelRowUpdates() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void moveToInsertRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void moveToCurrentRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public Statement getStatement() throws SQLException { + return null; + } + + @Override + public Object getObject(int columnIndex, Map> map) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public Ref getRef(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public Blob getBlob(int columnIndex) throws SQLException { + return null; + } + + @Override + public Clob getClob(int columnIndex) throws SQLException { + return null; + } + + @Override + public Array getArray(int columnIndex) throws SQLException { + return null; + } + + @Override + public Object getObject(String columnLabel, Map> map) throws SQLException { + return null; + } + + @Override + public Ref getRef(String columnLabel) throws SQLException { + return null; + } + + @Override + public Blob getBlob(String columnLabel) throws SQLException { + return null; + } + + @Override + public Clob getClob(String columnLabel) throws SQLException { + return null; + } + + @Override + public Array getArray(String columnLabel) throws SQLException { + return null; + } + + @Override + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Date getDate(String columnLabel, Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(String columnLabel, Calendar cal) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { + return null; + } + + @Override + public URL getURL(int columnIndex) throws SQLException { + return null; + } + + @Override + public URL getURL(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateRef(int columnIndex, Ref x) throws SQLException { + + } + + @Override + public void updateRef(String columnLabel, Ref x) throws SQLException { + + } + + @Override + public void updateBlob(int columnIndex, Blob x) throws SQLException { + + } + + @Override + public void updateBlob(String columnLabel, Blob x) throws SQLException { + + } + + @Override + public void updateClob(int columnIndex, Clob x) throws SQLException { + + } + + @Override + public void updateClob(String columnLabel, Clob x) throws SQLException { + + } + + @Override + public void updateArray(int columnIndex, Array x) throws SQLException { + + } + + @Override + public void updateArray(String columnLabel, Array x) throws SQLException { + + } + + @Override + public RowId getRowId(int columnIndex) throws SQLException { + return null; + } + + @Override + public RowId getRowId(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateRowId(int columnIndex, RowId x) throws SQLException { + + } + + @Override + public void updateRowId(String columnLabel, RowId x) throws SQLException { + + } + + @Override + public int getHoldability() throws SQLException { + return 0; + } + + @Override + public boolean isClosed() throws SQLException { + return false; + } + + @Override + public void updateNString(int columnIndex, String nString) throws SQLException { + + } + + @Override + public void updateNString(String columnLabel, String nString) throws SQLException { + + } + + @Override + public void updateNClob(int columnIndex, NClob nClob) throws SQLException { + + } + + @Override + public void updateNClob(String columnLabel, NClob nClob) throws SQLException { + + } + + @Override + public NClob getNClob(int columnIndex) throws SQLException { + return null; + } + + @Override + public NClob getNClob(String columnLabel) throws SQLException { + return null; + } + + @Override + public SQLXML getSQLXML(int columnIndex) throws SQLException { + return null; + } + + @Override + public SQLXML getSQLXML(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { + + } + + @Override + public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { + + } + + @Override + public String getNString(int columnIndex) throws SQLException { + return null; + } + + @Override + public String getNString(String columnLabel) throws SQLException { + return null; + } + + @Override + public Reader getNCharacterStream(int columnIndex) throws SQLException { + return null; + } + + @Override + public Reader getNCharacterStream(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + + } + + @Override + public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { + + } + + @Override + public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { + + } + + @Override + public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { + + } + + @Override + public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { + + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { + + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { + + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { + + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { + + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { + + } + + @Override + public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { + + } + + @Override + public void updateClob(int columnIndex, Reader reader) throws SQLException { + + } + + @Override + public void updateClob(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public void updateNClob(int columnIndex, Reader reader) throws SQLException { + + } + + @Override + public void updateNClob(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public T getObject(int columnIndex, Class type) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public T getObject(String columnLabel, Class type) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } + + private int getTrueColumnIndex(int columnIndex) throws SQLException { + if (columnIndex < 1) { + throw new SQLException("Column Index out of range, " + columnIndex + " < " + 1); + } + + int numOfCols = this.columnMetaDataList.size(); + if (columnIndex > numOfCols) { + throw new SQLException("Column Index out of range, " + columnIndex + " > " + numOfCols); + } + + return columnIndex - 1; + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/EmptyResultSet 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/EmptyResultSet 2.java new file mode 100644 index 0000000000..b6587b942d --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/EmptyResultSet 2.java @@ -0,0 +1,986 @@ +/*************************************************************************** + * 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.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.*; +import java.util.Calendar; +import java.util.Map; + +/* + * TDengine only supports a subset of the standard SQL, thus this implemetation of the + * standard JDBC API contains more or less some adjustments customized for certain + * compatibility needs. + */ +public class EmptyResultSet implements ResultSet { + + @Override + public boolean next() throws SQLException { + return false; + } + + @Override + public void close() throws SQLException { + + } + + @Override + public boolean wasNull() throws SQLException { + return false; + } + + @Override + public String getString(int columnIndex) throws SQLException { + return null; + } + + @Override + public boolean getBoolean(int columnIndex) throws SQLException { + return false; + } + + @Override + public byte getByte(int columnIndex) throws SQLException { + return 0; + } + + @Override + public short getShort(int columnIndex) throws SQLException { + return 0; + } + + @Override + public int getInt(int columnIndex) throws SQLException { + return 0; + } + + @Override + public long getLong(int columnIndex) throws SQLException { + return 0; + } + + @Override + public float getFloat(int columnIndex) throws SQLException { + return 0; + } + + @Override + public double getDouble(int columnIndex) throws SQLException { + return 0; + } + + @Override + public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { + return null; + } + + @Override + public byte[] getBytes(int columnIndex) throws SQLException { + return new byte[0]; + } + + @Override + public Date getDate(int columnIndex) throws SQLException { + return null; + } + + @Override + public Time getTime(int columnIndex) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(int columnIndex) throws SQLException { + return null; + } + + @Override + public InputStream getAsciiStream(int columnIndex) throws SQLException { + return null; + } + + @Override + public InputStream getUnicodeStream(int columnIndex) throws SQLException { + return null; + } + + @Override + public InputStream getBinaryStream(int columnIndex) throws SQLException { + return null; + } + + @Override + public String getString(String columnLabel) throws SQLException { + return null; + } + + @Override + public boolean getBoolean(String columnLabel) throws SQLException { + return false; + } + + @Override + public byte getByte(String columnLabel) throws SQLException { + return 0; + } + + @Override + public short getShort(String columnLabel) throws SQLException { + return 0; + } + + @Override + public int getInt(String columnLabel) throws SQLException { + return 0; + } + + @Override + public long getLong(String columnLabel) throws SQLException { + return 0; + } + + @Override + public float getFloat(String columnLabel) throws SQLException { + return 0; + } + + @Override + public double getDouble(String columnLabel) throws SQLException { + return 0; + } + + @Override + public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { + return null; + } + + @Override + public byte[] getBytes(String columnLabel) throws SQLException { + return new byte[0]; + } + + @Override + public Date getDate(String columnLabel) throws SQLException { + return null; + } + + @Override + public Time getTime(String columnLabel) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(String columnLabel) throws SQLException { + return null; + } + + @Override + public InputStream getAsciiStream(String columnLabel) throws SQLException { + return null; + } + + @Override + public InputStream getUnicodeStream(String columnLabel) throws SQLException { + return null; + } + + @Override + public InputStream getBinaryStream(String columnLabel) throws SQLException { + return null; + } + + @Override + public SQLWarning getWarnings() throws SQLException { + return null; + } + + @Override + public void clearWarnings() throws SQLException { + + } + + @Override + public String getCursorName() throws SQLException { + return null; + } + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + return null; + } + + @Override + public Object getObject(int columnIndex) throws SQLException { + return null; + } + + @Override + public Object getObject(String columnLabel) throws SQLException { + return null; + } + + @Override + public int findColumn(String columnLabel) throws SQLException { + return 0; + } + + @Override + public Reader getCharacterStream(int columnIndex) throws SQLException { + return null; + } + + @Override + public Reader getCharacterStream(String columnLabel) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(int columnIndex) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(String columnLabel) throws SQLException { + return null; + } + + @Override + public boolean isBeforeFirst() throws SQLException { + return false; + } + + @Override + public boolean isAfterLast() throws SQLException { + return false; + } + + @Override + public boolean isFirst() throws SQLException { + return false; + } + + @Override + public boolean isLast() throws SQLException { + return false; + } + + @Override + public void beforeFirst() throws SQLException { + + } + + @Override + public void afterLast() throws SQLException { + + } + + @Override + public boolean first() throws SQLException { + return false; + } + + @Override + public boolean last() throws SQLException { + return false; + } + + @Override + public int getRow() throws SQLException { + return 0; + } + + @Override + public boolean absolute(int row) throws SQLException { + return false; + } + + @Override + public boolean relative(int rows) throws SQLException { + return false; + } + + @Override + public boolean previous() throws SQLException { + return false; + } + + @Override + public void setFetchDirection(int direction) throws SQLException { + + } + + @Override + public int getFetchDirection() throws SQLException { + return 0; + } + + @Override + public void setFetchSize(int rows) throws SQLException { + + } + + @Override + public int getFetchSize() throws SQLException { + return 0; + } + + @Override + public int getType() throws SQLException { + return 0; + } + + @Override + public int getConcurrency() throws SQLException { + return 0; + } + + @Override + public boolean rowUpdated() throws SQLException { + return false; + } + + @Override + public boolean rowInserted() throws SQLException { + return false; + } + + @Override + public boolean rowDeleted() throws SQLException { + return false; + } + + @Override + public void updateNull(int columnIndex) throws SQLException { + + } + + @Override + public void updateBoolean(int columnIndex, boolean x) throws SQLException { + + } + + @Override + public void updateByte(int columnIndex, byte x) throws SQLException { + + } + + @Override + public void updateShort(int columnIndex, short x) throws SQLException { + + } + + @Override + public void updateInt(int columnIndex, int x) throws SQLException { + + } + + @Override + public void updateLong(int columnIndex, long x) throws SQLException { + + } + + @Override + public void updateFloat(int columnIndex, float x) throws SQLException { + + } + + @Override + public void updateDouble(int columnIndex, double x) throws SQLException { + + } + + @Override + public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { + + } + + @Override + public void updateString(int columnIndex, String x) throws SQLException { + + } + + @Override + public void updateBytes(int columnIndex, byte[] x) throws SQLException { + + } + + @Override + public void updateDate(int columnIndex, Date x) throws SQLException { + + } + + @Override + public void updateTime(int columnIndex, Time x) throws SQLException { + + } + + @Override + public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { + + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { + + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { + + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { + + } + + @Override + public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { + + } + + @Override + public void updateObject(int columnIndex, Object x) throws SQLException { + + } + + @Override + public void updateNull(String columnLabel) throws SQLException { + + } + + @Override + public void updateBoolean(String columnLabel, boolean x) throws SQLException { + + } + + @Override + public void updateByte(String columnLabel, byte x) throws SQLException { + + } + + @Override + public void updateShort(String columnLabel, short x) throws SQLException { + + } + + @Override + public void updateInt(String columnLabel, int x) throws SQLException { + + } + + @Override + public void updateLong(String columnLabel, long x) throws SQLException { + + } + + @Override + public void updateFloat(String columnLabel, float x) throws SQLException { + + } + + @Override + public void updateDouble(String columnLabel, double x) throws SQLException { + + } + + @Override + public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { + + } + + @Override + public void updateString(String columnLabel, String x) throws SQLException { + + } + + @Override + public void updateBytes(String columnLabel, byte[] x) throws SQLException { + + } + + @Override + public void updateDate(String columnLabel, Date x) throws SQLException { + + } + + @Override + public void updateTime(String columnLabel, Time x) throws SQLException { + + } + + @Override + public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { + + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { + + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { + + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { + + } + + @Override + public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { + + } + + @Override + public void updateObject(String columnLabel, Object x) throws SQLException { + + } + + @Override + public void insertRow() throws SQLException { + + } + + @Override + public void updateRow() throws SQLException { + + } + + @Override + public void deleteRow() throws SQLException { + + } + + @Override + public void refreshRow() throws SQLException { + + } + + @Override + public void cancelRowUpdates() throws SQLException { + + } + + @Override + public void moveToInsertRow() throws SQLException { + + } + + @Override + public void moveToCurrentRow() throws SQLException { + + } + + @Override + public Statement getStatement() throws SQLException { + return null; + } + + @Override + public Object getObject(int columnIndex, Map> map) throws SQLException { + return null; + } + + @Override + public Ref getRef(int columnIndex) throws SQLException { + return null; + } + + @Override + public Blob getBlob(int columnIndex) throws SQLException { + return null; + } + + @Override + public Clob getClob(int columnIndex) throws SQLException { + return null; + } + + @Override + public Array getArray(int columnIndex) throws SQLException { + return null; + } + + @Override + public Object getObject(String columnLabel, Map> map) throws SQLException { + return null; + } + + @Override + public Ref getRef(String columnLabel) throws SQLException { + return null; + } + + @Override + public Blob getBlob(String columnLabel) throws SQLException { + return null; + } + + @Override + public Clob getClob(String columnLabel) throws SQLException { + return null; + } + + @Override + public Array getArray(String columnLabel) throws SQLException { + return null; + } + + @Override + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Date getDate(String columnLabel, Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(String columnLabel, Calendar cal) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { + return null; + } + + @Override + public URL getURL(int columnIndex) throws SQLException { + return null; + } + + @Override + public URL getURL(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateRef(int columnIndex, Ref x) throws SQLException { + + } + + @Override + public void updateRef(String columnLabel, Ref x) throws SQLException { + + } + + @Override + public void updateBlob(int columnIndex, Blob x) throws SQLException { + + } + + @Override + public void updateBlob(String columnLabel, Blob x) throws SQLException { + + } + + @Override + public void updateClob(int columnIndex, Clob x) throws SQLException { + + } + + @Override + public void updateClob(String columnLabel, Clob x) throws SQLException { + + } + + @Override + public void updateArray(int columnIndex, Array x) throws SQLException { + + } + + @Override + public void updateArray(String columnLabel, Array x) throws SQLException { + + } + + @Override + public RowId getRowId(int columnIndex) throws SQLException { + return null; + } + + @Override + public RowId getRowId(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateRowId(int columnIndex, RowId x) throws SQLException { + + } + + @Override + public void updateRowId(String columnLabel, RowId x) throws SQLException { + + } + + @Override + public int getHoldability() throws SQLException { + return 0; + } + + @Override + public boolean isClosed() throws SQLException { + return false; + } + + @Override + public void updateNString(int columnIndex, String nString) throws SQLException { + + } + + @Override + public void updateNString(String columnLabel, String nString) throws SQLException { + + } + + @Override + public void updateNClob(int columnIndex, NClob nClob) throws SQLException { + + } + + @Override + public void updateNClob(String columnLabel, NClob nClob) throws SQLException { + + } + + @Override + public NClob getNClob(int columnIndex) throws SQLException { + return null; + } + + @Override + public NClob getNClob(String columnLabel) throws SQLException { + return null; + } + + @Override + public SQLXML getSQLXML(int columnIndex) throws SQLException { + return null; + } + + @Override + public SQLXML getSQLXML(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { + + } + + @Override + public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { + + } + + @Override + public String getNString(int columnIndex) throws SQLException { + return null; + } + + @Override + public String getNString(String columnLabel) throws SQLException { + return null; + } + + @Override + public Reader getNCharacterStream(int columnIndex) throws SQLException { + return null; + } + + @Override + public Reader getNCharacterStream(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + + } + + @Override + public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { + + } + + @Override + public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { + + } + + @Override + public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { + + } + + @Override + public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { + + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { + + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { + + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { + + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { + + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { + + } + + @Override + public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { + + } + + @Override + public void updateClob(int columnIndex, Reader reader) throws SQLException { + + } + + @Override + public void updateClob(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public void updateNClob(int columnIndex, Reader reader) throws SQLException { + + } + + @Override + public void updateNClob(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public T getObject(int columnIndex, Class type) throws SQLException { + return null; + } + + @Override + public T getObject(String columnLabel, Class type) throws SQLException { + return null; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/GetColumnsResultSet 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/GetColumnsResultSet 2.java new file mode 100644 index 0000000000..e15415e037 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/GetColumnsResultSet 2.java @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + *****************************************************************************/ +package com.taosdata.jdbc; + +import java.sql.ResultSet; + +/* + * TDengine only supports a subset of the standard SQL, thus this implemetation of the + * standard JDBC API contains more or less some adjustments customized for certain + * compatibility needs. + */ +public class GetColumnsResultSet extends TSDBResultSetWrapper { + private String catalog; + private String schemaPattern; + private String tableNamePattern; + private String columnNamePattern; + + public GetColumnsResultSet(ResultSet resultSet, String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) { + super.setOriginalResultSet(resultSet); + this.catalog = catalog; + this.schemaPattern = schemaPattern; + this.tableNamePattern = tableNamePattern; + this.columnNamePattern = columnNamePattern; + } + + @Override + public String getString(int columnIndex) { + switch (columnIndex) { + case 1: + return catalog; + case 2: + return null; + case 3: + return tableNamePattern; + default: + return null; + } + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/GetTablesResultSet 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/GetTablesResultSet 2.java new file mode 100644 index 0000000000..e28f6e3c9a --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/GetTablesResultSet 2.java @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + *****************************************************************************/ +package com.taosdata.jdbc; + +import java.sql.ResultSet; +import java.sql.SQLException; + +/* + * TDengine only supports a subset of the standard SQL, thus this implemetation of the + * standard JDBC API contains more or less some adjustments customized for certain + * compatibility needs. + */ +public class GetTablesResultSet extends TSDBResultSetWrapper { + + private String catalog; + private String schemaPattern; + private String tableNamePattern; + private String[] types; + + public GetTablesResultSet(ResultSet resultSet, String catalog, String schemaPattern, String tableNamePattern, String[] types) { + super.setOriginalResultSet(resultSet); + this.catalog = catalog; + this.schemaPattern = schemaPattern; + this.tableNamePattern = tableNamePattern; + this.types = types; + } + + @Override + public String getString(int columnIndex) throws SQLException { + String ret = null; + switch (columnIndex) { + case 3: + return super.getString(1); + case 4: + return "table"; + default: + return null; + } + } + +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/SavedPreparedStatement 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/SavedPreparedStatement 2.java new file mode 100644 index 0000000000..a0aa7ec584 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/SavedPreparedStatement 2.java @@ -0,0 +1,453 @@ +package com.taosdata.jdbc; + +import com.taosdata.jdbc.bean.TSDBPreparedParam; + +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * this class is used to precompile the sql of tdengine insert or import ops + */ +public class SavedPreparedStatement { + + private TSDBPreparedStatement tsdbPreparedStatement; + + /** + * sql param List + */ + private List sqlParamList; + + /** + * init param according the sql + */ + private TSDBPreparedParam initPreparedParam; + + /** + * is table name dynamic in the prepared sql + */ + private boolean isTableNameDynamic; + + /** + * insert or import sql template pattern, the template are the following: + *

+ * insert/import into tableName [(field1, field2, ...)] [using stables tags(?, ?, ...) ] values(?, ?, ...) (?, ?, ...) + *

+ * we split it to three part: + * 1. prefix, insert/import + * 2. middle, tableName [(field1, field2, ...)] [using stables tags(?, ?, ...) ] + * 3. valueList, the content after values, for example (?, ?, ...) (?, ?, ...) + */ + private Pattern sqlPattern = Pattern.compile("(?s)(?i)^\\s*(INSERT|IMPORT)\\s+INTO\\s+((?\\S+)\\s*(\\(.*\\))?\\s+(USING\\s+(?\\S+)\\s+TAGS\\s*\\((?.+)\\))?)\\s*VALUES\\s*(?\\(.*\\)).*"); + + /** + * the raw sql template + */ + private String sql; + + /** + * the prefix part of sql + */ + private String prefix; + + /** + * the middle part of sql + */ + private String middle; + + private int middleParamSize; + + /** + * the valueList part of sql + */ + private String valueList; + + private int valueListSize; + + /** + * default param value + */ + private static final String DEFAULT_VALUE = "NULL"; + + private static final String PLACEHOLDER = "?"; + + private String tableName; + + /** + * is the parameter add to batch list + */ + private boolean isAddBatch; + + public SavedPreparedStatement(String sql, TSDBPreparedStatement tsdbPreparedStatement) throws SQLException { + this.sql = sql; + this.tsdbPreparedStatement = tsdbPreparedStatement; + this.sqlParamList = new ArrayList<>(); + + parsePreparedParam(this.sql); + } + + /** + * parse the init param according the sql param + * + * @param sql + */ + private void parsePreparedParam(String sql) throws SQLException { + + Matcher matcher = sqlPattern.matcher(sql); + + if (matcher.find()) { + + tableName = matcher.group("tablename"); + + if (tableName != null && PLACEHOLDER.equals(tableName)) { + // the table name is dynamic + this.isTableNameDynamic = true; + } + + prefix = matcher.group(1); + middle = matcher.group(2); + valueList = matcher.group("valueList"); + + if (middle != null && !"".equals(middle)) { + middleParamSize = parsePlaceholder(middle); + } + + if (valueList != null && !"".equals(valueList)) { + valueListSize = parsePlaceholder(valueList); + } + + initPreparedParam = initDefaultParam(tableName, middleParamSize, valueListSize); + + } else { + // not match + throw new SQLException(TSDBConstants.WrapErrMsg("the sql is not complete!")); + } + + } + + private TSDBPreparedParam initDefaultParam(String tableName, int middleParamSize, int valueListSize) { + + TSDBPreparedParam tsdbPreparedParam = new TSDBPreparedParam(tableName); + + tsdbPreparedParam.setMiddleParamList(getDefaultParamList(middleParamSize)); + + tsdbPreparedParam.setValueList(getDefaultParamList(valueListSize)); + + return tsdbPreparedParam; + } + + /** + * generate the default param value list + * + * @param paramSize + * @return + */ + private List getDefaultParamList(int paramSize) { + + List paramList = new ArrayList<>(paramSize); + if (paramSize > 0) { + for (int i = 0; i < paramSize; i++) { + paramList.add(i, DEFAULT_VALUE); + } + } + + return paramList; + } + + /** + * calculate the placeholder num + * + * @param value + * @return + */ + private int parsePlaceholder(String value) { + + Pattern pattern = Pattern.compile("[?]"); + + Matcher matcher = pattern.matcher(value); + + int result = 0; + while (matcher.find()) { + result++; + } + return result; + } + + /** + * set current row params + * + * @param parameterIndex the first parameter is 1, the second is 2, ... + * @param x the parameter value + */ + public void setParam(int parameterIndex, Object x) throws SQLException { + + int paramSize = this.middleParamSize + this.valueListSize; + + String errorMsg = String.format("the parameterIndex %s out of the range [1, %s]", parameterIndex, paramSize); + + if (parameterIndex < 1 || parameterIndex > paramSize) { + throw new SQLException(TSDBConstants.WrapErrMsg(errorMsg)); + } + + this.isAddBatch = false; //set isAddBatch to false + + if (x == null) { + x = DEFAULT_VALUE; // set default null string + } + + parameterIndex = parameterIndex - 1; // start from 0 in param list + + if (this.middleParamSize > 0 && parameterIndex >= 0 && parameterIndex < this.middleParamSize) { + + this.initPreparedParam.setMiddleParam(parameterIndex, x); + return; + } + + if (this.valueListSize > 0 && parameterIndex >= this.middleParamSize && parameterIndex < paramSize) { + + this.initPreparedParam.setValueParam(parameterIndex - this.middleParamSize, x); + return; + } + + throw new SQLException(TSDBConstants.WrapErrMsg(errorMsg)); + } + + public void addBatch() { + + addCurrentRowParamToList(); + this.initPreparedParam = initDefaultParam(tableName, middleParamSize, valueListSize); + } + + /** + * add current param to batch list + */ + private void addCurrentRowParamToList() { + + if (initPreparedParam != null && (this.middleParamSize > 0 || this.valueListSize > 0)) { + this.sqlParamList.add(initPreparedParam); // add current param to batch list + } + this.isAddBatch = true; + } + + + /** + * execute the sql with batch sql + * + * @return + * @throws SQLException + */ + public int[] executeBatch() throws SQLException { + + int result = executeBatchInternal(); + + return new int[]{result}; + } + + + public int executeBatchInternal() throws SQLException { + + if (!isAddBatch) { + addCurrentRowParamToList(); // add current param to batch list + } + + //1. generate batch sql + String sql = generateExecuteSql(); + //2. execute batch sql + int result = executeSql(sql); + + //3. clear batch param list + this.sqlParamList.clear(); + + return result; + } + + /** + * generate the batch sql + * + * @return + */ + private String generateExecuteSql() { + + StringBuilder stringBuilder = new StringBuilder(); + + stringBuilder.append(prefix); + stringBuilder.append(" into "); + + if (!isTableNameDynamic) { + // tablename will not need to be replaced + String middleValue = replaceMiddleListParam(middle, sqlParamList); + stringBuilder.append(middleValue); + stringBuilder.append(" values"); + + stringBuilder.append(replaceValueListParam(valueList, sqlParamList)); + + } else { + // need to replace tablename + + if (sqlParamList.size() > 0) { + + TSDBPreparedParam firstPreparedParam = sqlParamList.get(0); + + //replace middle part and value part of first row + String firstRow = replaceMiddleAndValuePart(firstPreparedParam); + stringBuilder.append(firstRow); + + //the first param in the middleParamList is the tableName + String lastTableName = firstPreparedParam.getMiddleParamList().get(0).toString(); + + if (sqlParamList.size() > 1) { + + for (int i = 1; i < sqlParamList.size(); i++) { + TSDBPreparedParam currentParam = sqlParamList.get(i); + String currentTableName = currentParam.getMiddleParamList().get(0).toString(); + if (lastTableName.equalsIgnoreCase(currentTableName)) { + // tablename is same with the last row ,so only need to append the part of value + + String values = replaceTemplateParam(valueList, currentParam.getValueList()); + stringBuilder.append(values); + + } else { + // tablename difference with the last row + //need to replace middle part and value part + String row = replaceMiddleAndValuePart(currentParam); + stringBuilder.append(row); + lastTableName = currentTableName; + } + } + } + + } else { + + stringBuilder.append(middle); + stringBuilder.append(" values"); + stringBuilder.append(valueList); + } + + } + + return stringBuilder.toString(); + } + + /** + * replace the middle and value part + * + * @param tsdbPreparedParam + * @return + */ + private String replaceMiddleAndValuePart(TSDBPreparedParam tsdbPreparedParam) { + + StringBuilder stringBuilder = new StringBuilder(" "); + + String middlePart = replaceTemplateParam(middle, tsdbPreparedParam.getMiddleParamList()); + + stringBuilder.append(middlePart); + stringBuilder.append(" values "); + + String valuePart = replaceTemplateParam(valueList, tsdbPreparedParam.getValueList()); + stringBuilder.append(valuePart); + stringBuilder.append(" "); + + return stringBuilder.toString(); + } + + /** + * replace the placeholder of the middle part of sql template with TSDBPreparedParam list + * + * @param template + * @param sqlParamList + * @return + */ + private String replaceMiddleListParam(String template, List sqlParamList) { + + if (sqlParamList.size() > 0) { + + //becase once the subTableName is static then will be ignore the tag which after the first setTag + return replaceTemplateParam(template, sqlParamList.get(0).getMiddleParamList()); + + } + + return template; + } + + + /** + * replace the placeholder of the template with TSDBPreparedParam list + * + * @param template + * @param sqlParamList + * @return + */ + private String replaceValueListParam(String template, List sqlParamList) { + + StringBuilder stringBuilder = new StringBuilder(); + + if (sqlParamList.size() > 0) { + + for (TSDBPreparedParam tsdbPreparedParam : sqlParamList) { + + String tmp = replaceTemplateParam(template, tsdbPreparedParam.getValueList()); + + stringBuilder.append(tmp); + } + + } else { + stringBuilder.append(template); + } + + return stringBuilder.toString(); + } + + /** + * replace the placeholder of the template with paramList + * + * @param template + * @param paramList + * @return + */ + private String replaceTemplateParam(String template, List paramList) { + + if (paramList.size() > 0) { + + String tmp = template; + + for (int i = 0; i < paramList.size(); ++i) { + + String paraStr = getParamString(paramList.get(i)); + + tmp = tmp.replaceFirst("[" + PLACEHOLDER + "]", paraStr); + + } + + return tmp; + + } else { + return template; + } + + } + + /** + * get the string of param object + * + * @param paramObj + * @return + */ + private String getParamString(Object paramObj) { + + String paraStr = paramObj.toString(); + if (paramObj instanceof Timestamp || (paramObj instanceof String && !DEFAULT_VALUE.equalsIgnoreCase(paraStr))) { + paraStr = "'" + paraStr + "'"; + } + return paraStr; + } + + + private int executeSql(String sql) throws SQLException { + + return tsdbPreparedStatement.executeUpdate(sql); + } + +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection 2.java new file mode 100644 index 0000000000..4640f6b446 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConnection 2.java @@ -0,0 +1,352 @@ +/*************************************************************************** + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + *****************************************************************************/ +package com.taosdata.jdbc; + +import java.sql.Array; +import java.sql.Blob; +import java.sql.CallableStatement; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.NClob; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLClientInfoException; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Savepoint; +import java.sql.Statement; +import java.sql.Struct; +import java.util.Enumeration; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.Executor; + +public class TSDBConnection implements Connection { + + private TSDBJNIConnector connector = null; + + protected Properties props = null; + + private String catalog = null; + + private TSDBDatabaseMetaData dbMetaData = null; + + private Properties clientInfoProps = new Properties(); + + private int timeoutMilliseconds = 0; + + private String tsCharSet = ""; + + public TSDBConnection(Properties info, TSDBDatabaseMetaData meta) throws SQLException { + this.dbMetaData = meta; + connect(info.getProperty(TSDBDriver.PROPERTY_KEY_HOST), + Integer.parseInt(info.getProperty(TSDBDriver.PROPERTY_KEY_PORT, "0")), + info.getProperty(TSDBDriver.PROPERTY_KEY_DBNAME), info.getProperty(TSDBDriver.PROPERTY_KEY_USER), + info.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD)); + } + + private void connect(String host, int port, String dbName, String user, String password) throws SQLException { + this.connector = new TSDBJNIConnector(); + this.connector.connect(host, port, dbName, user, password); + + try { + this.setCatalog(dbName); + } catch (SQLException e) { + e.printStackTrace(); + } + + this.dbMetaData.setConnection(this); + } + + public TSDBJNIConnector getConnection() { + return this.connector; + } + + public Statement createStatement() throws SQLException { + if (!this.connector.isClosed()) { + return new TSDBStatement(this.connector); + } else { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } + } + + public PreparedStatement prepareStatement(String sql) throws SQLException { + if (!this.connector.isClosed()) { + return new TSDBPreparedStatement(this.connector, sql); + } else { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } + } + + public CallableStatement prepareCall(String sql) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public String nativeSQL(String sql) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setAutoCommit(boolean autoCommit) throws SQLException { + } + + public boolean getAutoCommit() throws SQLException { + return true; + } + + public void commit() throws SQLException { + } + + public void rollback() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void close() throws SQLException { + if (this.connector != null && !this.connector.isClosed()) { + this.connector.closeConnection(); + } else { + throw new SQLException(TSDBConstants.WrapErrMsg("connection is already closed!")); + } + } + + public boolean isClosed() throws SQLException { + return this.connector.isClosed(); + } + + /** + * A connection's database is able to provide information describing its tables, + * its supported SQL grammar, its stored procedures, the capabilities of this + * connection, etc. This information is made available through a + * DatabaseMetaData object. + * + * @return a DatabaseMetaData object for this connection + * @exception SQLException + * if a database access error occurs + */ + public DatabaseMetaData getMetaData() throws SQLException { + return this.dbMetaData; + } + + /** + * This readOnly option is not supported by TDengine. However, the method is intentionally left blank here to + * support HikariCP connection. + * @param readOnly + * @throws SQLException + */ + public void setReadOnly(boolean readOnly) throws SQLException { + } + + public boolean isReadOnly() throws SQLException { + return true; + } + + public void setCatalog(String catalog) throws SQLException { + this.catalog = catalog; + } + + public String getCatalog() throws SQLException { + return this.catalog; + } + + /** + * The transaction isolation level option is not supported by TDengine. + * This method is intentionally left empty to support HikariCP connection. + * @param level + * @throws SQLException + */ + public void setTransactionIsolation(int level) throws SQLException { + } + + /** + * The transaction isolation level option is not supported by TDengine. + * @return + * @throws SQLException + */ + public int getTransactionIsolation() throws SQLException { + return Connection.TRANSACTION_NONE; + } + + public SQLWarning getWarnings() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void clearWarnings() throws SQLException { + // left blank to support HikariCP connection + //todo: implement getWarnings according to the warning messages returned from TDengine + } + + public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + // This method is implemented in the current way to support Spark + if (resultSetType != ResultSet.TYPE_FORWARD_ONLY) { + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + } + + if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY) { + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + } + + return this.prepareStatement(sql); + } + + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Map> getTypeMap() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setTypeMap(Map> map) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setHoldability(int holdability) throws SQLException { + // intentionally left empty to support druid connection pool. + } + + /** + * the transaction is not supported by TDengine, so the opened ResultSet Objects will remain open + * @return + * @throws SQLException + */ + public int getHoldability() throws SQLException { + //intentionally left empty to support HikariCP connection. + return ResultSet.HOLD_CURSORS_OVER_COMMIT; + } + + public Savepoint setSavepoint() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Savepoint setSavepoint(String name) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void rollback(Savepoint savepoint) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void releaseSavepoint(Savepoint savepoint) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + return this.prepareStatement(sql, resultSetType, resultSetConcurrency); + } + + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Clob createClob() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Blob createBlob() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public NClob createNClob() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public SQLXML createSQLXML() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isValid(int timeout) throws SQLException { + return !this.isClosed(); + } + + public void setClientInfo(String name, String value) throws SQLClientInfoException { + clientInfoProps.setProperty(name, value); + } + + public void setClientInfo(Properties properties) throws SQLClientInfoException { + for (Enumeration enumer = properties.keys(); enumer.hasMoreElements();) { + String name = (String) enumer.nextElement(); + clientInfoProps.put(name, properties.getProperty(name)); + } + } + + public String getClientInfo(String name) throws SQLException { + return clientInfoProps.getProperty(name); + } + + public Properties getClientInfo() throws SQLException { + return clientInfoProps; + } + + public Array createArrayOf(String typeName, Object[] elements) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Struct createStruct(String typeName, Object[] attributes) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setSchema(String schema) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public String getSchema() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void abort(Executor executor) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { + this.timeoutMilliseconds = milliseconds; + } + + public int getNetworkTimeout() throws SQLException { + return this.timeoutMilliseconds; + } + + public T unwrap(Class iface) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants 2.java new file mode 100644 index 0000000000..3940e80930 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants 2.java @@ -0,0 +1,86 @@ +/*************************************************************************** + * 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.util.HashMap; +import java.util.Map; + +public abstract class TSDBConstants { + + public static final String DEFAULT_PORT = "6200"; + public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!"; + public static final String INVALID_VARIABLES = "invalid variables"; + public static Map DATATYPE_MAP = null; + + public static final long JNI_NULL_POINTER = 0L; + + public static final int JNI_SUCCESS = 0; + public static final int JNI_TDENGINE_ERROR = -1; + public static final int JNI_CONNECTION_NULL = -2; + public static final int JNI_RESULT_SET_NULL = -3; + public static final int JNI_NUM_OF_FIELDS_0 = -4; + public static final int JNI_SQL_NULL = -5; + public static final int JNI_FETCH_END = -6; + + public static final int TSDB_DATA_TYPE_NULL = 0; + public static final int TSDB_DATA_TYPE_BOOL = 1; + public static final int TSDB_DATA_TYPE_TINYINT = 2; + public static final int TSDB_DATA_TYPE_SMALLINT = 3; + public static final int TSDB_DATA_TYPE_INT = 4; + public static final int TSDB_DATA_TYPE_BIGINT = 5; + public static final int TSDB_DATA_TYPE_FLOAT = 6; + public static final int TSDB_DATA_TYPE_DOUBLE = 7; + public static final int TSDB_DATA_TYPE_BINARY = 8; + public static final int TSDB_DATA_TYPE_TIMESTAMP = 9; + public static final int TSDB_DATA_TYPE_NCHAR = 10; + + public static String WrapErrMsg(String msg) { + return "TDengine Error: " + msg; + } + + public static String FixErrMsg(int code) { + switch (code) { + case JNI_TDENGINE_ERROR: + return WrapErrMsg("internal error of database!"); + case JNI_CONNECTION_NULL: + return WrapErrMsg("invalid tdengine connection!"); + case JNI_RESULT_SET_NULL: + return WrapErrMsg("invalid resultset pointer!"); + case JNI_NUM_OF_FIELDS_0: + return WrapErrMsg("invalid num of fields!"); + case JNI_SQL_NULL: + return WrapErrMsg("can't execute empty sql!"); + case JNI_FETCH_END: + return WrapErrMsg("fetch to the end of resultset"); + default: + break; + } + return WrapErrMsg("unkown error!"); + } + + static { + DATATYPE_MAP = new HashMap(); + DATATYPE_MAP.put(1, "BOOL"); + DATATYPE_MAP.put(2, "TINYINT"); + DATATYPE_MAP.put(3, "SMALLINT"); + DATATYPE_MAP.put(4, "INT"); + DATATYPE_MAP.put(5, "BIGINT"); + DATATYPE_MAP.put(6, "FLOAT"); + DATATYPE_MAP.put(7, "DOUBLE"); + DATATYPE_MAP.put(8, "BINARY"); + DATATYPE_MAP.put(9, "TIMESTAMP"); + DATATYPE_MAP.put(10, "NCHAR"); + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData 2.java new file mode 100644 index 0000000000..6cb3263e56 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData 2.java @@ -0,0 +1,800 @@ +/*************************************************************************** + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + *****************************************************************************/ +package com.taosdata.jdbc; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + +public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { + + private String dbProductName = null; + private String url = null; + private String userName = null; + private Connection conn = null; + + public TSDBDatabaseMetaData(String dbProductName, String url, String userName) { + this.dbProductName = dbProductName; + this.url = url; + this.userName = userName; + } + + public void setConnection(Connection conn) { + this.conn = conn; + } + + public T unwrap(Class iface) throws SQLException { + return null; + } + + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } + + public boolean allProceduresAreCallable() throws SQLException { + return false; + } + + public boolean allTablesAreSelectable() throws SQLException { + return false; + } + + public String getURL() throws SQLException { + return this.url; + } + + public String getUserName() throws SQLException { + return this.userName; + } + + public boolean isReadOnly() throws SQLException { + return false; + } + + public boolean nullsAreSortedHigh() throws SQLException { + return false; + } + + public boolean nullsAreSortedLow() throws SQLException { + return false; + } + + public boolean nullsAreSortedAtStart() throws SQLException { + return false; + } + + public boolean nullsAreSortedAtEnd() throws SQLException { + return false; + } + + public String getDatabaseProductName() throws SQLException { + return this.dbProductName; + } + + public String getDatabaseProductVersion() throws SQLException { + return "1.5.1"; + } + + public String getDriverName() throws SQLException { + return TSDBDriver.class.getName(); + } + + public String getDriverVersion() throws SQLException { + return "1.0.0"; + } + + public int getDriverMajorVersion() { + return 0; + } + + public int getDriverMinorVersion() { + return 0; + } + + 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 ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) + throws SQLException { + if (conn != null && !conn.isClosed()) { + Statement stmt = conn.createStatement(); + if (catalog == null || catalog.length() < 1) { + catalog = conn.getCatalog(); + } + stmt.executeUpdate("use " + catalog); + ResultSet resultSet0 = stmt.executeQuery("show tables"); + GetTablesResultSet getTablesResultSet = new GetTablesResultSet(resultSet0, catalog, schemaPattern, tableNamePattern, types); + return getTablesResultSet; + } else { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } + } + + public ResultSet getSchemas() throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getCatalogs() throws SQLException { + + if (conn != null && !conn.isClosed()) { + Statement stmt = conn.createStatement(); + ResultSet resultSet0 = stmt.executeQuery("show databases"); + CatalogResultSet resultSet = new CatalogResultSet(resultSet0); + return resultSet; + } else { + return getEmptyResultSet(); + } + } + + public ResultSet getTableTypes() throws SQLException { + DatabaseMetaDataResultSet resultSet = new DatabaseMetaDataResultSet(); + + // set up ColumnMetaDataList + List columnMetaDataList = new ArrayList(1); + ColumnMetaData colMetaData = new ColumnMetaData(); + colMetaData.setColIndex(0); + colMetaData.setColName("TABLE_TYPE"); + colMetaData.setColSize(10); + colMetaData.setColType(TSDBConstants.TSDB_DATA_TYPE_BINARY); + columnMetaDataList.add(colMetaData); + + // set up rowDataList + List rowDataList = new ArrayList(2); + TSDBResultSetRowData rowData = new TSDBResultSetRowData(); + rowData.setString(0, "TABLE"); + rowDataList.add(rowData); + rowData = new TSDBResultSetRowData(); + rowData.setString(0, "STABLE"); + rowDataList.add(rowData); + + resultSet.setColumnMetaDataList(columnMetaDataList); + resultSet.setRowDataList(rowDataList); + return resultSet; + } + + public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, + String foreignCatalog, String foreignSchema, String foreignTable) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getTypeInfo() throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) + throws SQLException { + return getEmptyResultSet(); + } + + public boolean supportsResultSetType(int type) throws SQLException { + return false; + } + + public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { + return false; + } + + public boolean ownUpdatesAreVisible(int type) throws SQLException { + return false; + } + + public boolean ownDeletesAreVisible(int type) throws SQLException { + return false; + } + + public boolean ownInsertsAreVisible(int type) throws SQLException { + return false; + } + + public boolean othersUpdatesAreVisible(int type) throws SQLException { + return false; + } + + public boolean othersDeletesAreVisible(int type) throws SQLException { + return false; + } + + public boolean othersInsertsAreVisible(int type) throws SQLException { + return false; + } + + public boolean updatesAreDetected(int type) throws SQLException { + return false; + } + + public boolean deletesAreDetected(int type) throws SQLException { + return false; + } + + public boolean insertsAreDetected(int type) throws SQLException { + return false; + } + + public boolean supportsBatchUpdates() throws SQLException { + return false; + } + + public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) + throws SQLException { + return getEmptyResultSet(); + } + + public Connection getConnection() throws SQLException { + return null; + } + + public boolean supportsSavepoints() throws SQLException { + return false; + } + + public boolean supportsNamedParameters() throws SQLException { + return false; + } + + public boolean supportsMultipleOpenResults() throws SQLException { + return false; + } + + public boolean supportsGetGeneratedKeys() throws SQLException { + return false; + } + + public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, + String attributeNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public boolean supportsResultSetHoldability(int holdability) throws SQLException { + return false; + } + + public int getResultSetHoldability() throws SQLException { + return 0; + } + + public int getDatabaseMajorVersion() throws SQLException { + return 0; + } + + public int getDatabaseMinorVersion() throws SQLException { + return 0; + } + + public int getJDBCMajorVersion() throws SQLException { + return 0; + } + + public int getJDBCMinorVersion() throws SQLException { + return 0; + } + + public int getSQLStateType() throws SQLException { + return 0; + } + + public boolean locatorsUpdateCopy() throws SQLException { + return false; + } + + public boolean supportsStatementPooling() throws SQLException { + return false; + } + + public RowIdLifetime getRowIdLifetime() throws SQLException { + return null; + } + + public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { + return null; + } + + public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { + return false; + } + + public boolean autoCommitFailureClosesAllResultSets() throws SQLException { + return false; + } + + public ResultSet getClientInfoProperties() throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) + throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, + String columnNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, + String columnNamePattern) throws SQLException { + return getEmptyResultSet(); + } + + public boolean generatedKeyAlwaysReturned() throws SQLException { + return false; + } + + private ResultSet getEmptyResultSet() { + return new EmptyResultSet(); + } +} \ No newline at end of file diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver 2.java new file mode 100755 index 0000000000..c297fb67b0 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver 2.java @@ -0,0 +1,358 @@ +/*************************************************************************** + * 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 org.apache.commons.lang3.StringUtils; + +import java.sql.*; +import java.util.Properties; +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 implements java.sql.Driver { + + @Deprecated + private static final String URL_PREFIX1 = "jdbc:TSDB://"; + + private static final String URL_PREFIX = "jdbc:TAOS://"; + + /** + * 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 host value from the properties instance passed to + * the driver. + */ + public static final String PROPERTY_KEY_HOST = "host"; + /** + * 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 port number value from the properties instance + * passed to the driver. + */ + public static final String PROPERTY_KEY_PORT = "port"; + + /** + * Key used to retrieve the user value from the properties instance passed to + * the driver. + */ + public static final String PROPERTY_KEY_USER = "user"; + + /** + * 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"; + + public static final String PROPERTY_KEY_PROTOCOL = "protocol"; + + /** + * Index for port coming out of parseHostPortPair(). + */ + public final static int PORT_NUMBER_INDEX = 1; + + /** + * Index for host coming out of parseHostPortPair(). + */ + public final static int HOST_NAME_INDEX = 0; + + private TSDBDatabaseMetaData dbMetaData = null; + + static { + try { + java.sql.DriverManager.registerDriver(new TSDBDriver()); + } catch (SQLException E) { + throw new RuntimeException(TSDBConstants.WrapErrMsg("can't register tdengine jdbc driver!")); + } + } + + public Connection connect(String url, Properties info) throws SQLException { + if (url == null) { + throw new SQLException(TSDBConstants.WrapErrMsg("url is not set!")); + } + + Properties props = null; + + if ((props = parseURL(url, info)) == null) { + return null; + } + + try { + TSDBJNIConnector.init((String) props.get(PROPERTY_KEY_CONFIG_DIR), (String) props.get(PROPERTY_KEY_LOCALE), (String) props.get(PROPERTY_KEY_CHARSET), + (String) props.get(PROPERTY_KEY_TIME_ZONE)); + Connection newConn = new TSDBConnection(props, this.dbMetaData); + return newConn; + } catch (SQLWarning sqlWarning) { + sqlWarning.printStackTrace(); + Connection newConn = new TSDBConnection(props, this.dbMetaData); + return newConn; + } catch (SQLException sqlEx) { + throw sqlEx; + } catch (Exception ex) { + SQLException sqlEx = new SQLException("SQLException:" + ex.toString()); + sqlEx.initCause(ex); + throw sqlEx; + } + } + + /** + * Parses hostPortPair in the form of [host][:port] into an array, with the + * element of index HOST_NAME_INDEX being the host (or null if not specified), + * and the element of index PORT_NUMBER_INDEX being the port (or null if not + * specified). + * + * @param hostPortPair + * host and port in form of of [host][:port] + * + * @return array containing host and port as Strings + * + * @throws SQLException + * if a parse error occurs + */ + protected static String[] parseHostPortPair(String hostPortPair) throws SQLException { + String[] splitValues = new String[2]; + + int portIndex = hostPortPair.indexOf(":"); + + String hostname = null; + + if (portIndex != -1) { + if ((portIndex + 1) < hostPortPair.length()) { + String portAsString = hostPortPair.substring(portIndex + 1); + hostname = hostPortPair.substring(0, portIndex); + + splitValues[HOST_NAME_INDEX] = hostname; + + splitValues[PORT_NUMBER_INDEX] = portAsString; + } else { + throw new SQLException(TSDBConstants.WrapErrMsg("port is not proper!")); + } + } else { + splitValues[HOST_NAME_INDEX] = hostPortPair; + splitValues[PORT_NUMBER_INDEX] = null; + } + + return splitValues; + } + + public boolean acceptsURL(String url) throws SQLException { + return true; + } + + public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { + if (info == null) { + info = new Properties(); + } + + if ((url != null) && (url.startsWith(URL_PREFIX) || url.startsWith(URL_PREFIX1))) { + info = parseURL(url, info); + } + + DriverPropertyInfo hostProp = new DriverPropertyInfo(PROPERTY_KEY_HOST, info.getProperty(PROPERTY_KEY_HOST)); + hostProp.required = true; + + DriverPropertyInfo portProp = new DriverPropertyInfo(PROPERTY_KEY_PORT, + info.getProperty(PROPERTY_KEY_PORT, TSDBConstants.DEFAULT_PORT)); + portProp.required = false; + + DriverPropertyInfo dbProp = new DriverPropertyInfo(PROPERTY_KEY_DBNAME, info.getProperty(PROPERTY_KEY_DBNAME)); + dbProp.required = false; + dbProp.description = "Database name"; + + DriverPropertyInfo userProp = new DriverPropertyInfo(PROPERTY_KEY_USER, info.getProperty(PROPERTY_KEY_USER)); + userProp.required = true; + + DriverPropertyInfo passwordProp = new DriverPropertyInfo(PROPERTY_KEY_PASSWORD, + info.getProperty(PROPERTY_KEY_PASSWORD)); + passwordProp.required = true; + + DriverPropertyInfo[] propertyInfo = new DriverPropertyInfo[5]; + propertyInfo[0] = hostProp; + propertyInfo[1] = portProp; + propertyInfo[2] = dbProp; + propertyInfo[3] = userProp; + propertyInfo[4] = passwordProp; + + return propertyInfo; + } + + /** + * example: jdbc:TSDB://127.0.0.1:0/db?user=root&password=your_password + */ + + public Properties parseURL(String url, Properties defaults) throws java.sql.SQLException { + Properties urlProps = (defaults != null) ? defaults : new Properties(); + if (url == null) { + return null; + } + + if (!StringUtils.startsWithIgnoreCase(url, URL_PREFIX) && !StringUtils.startsWithIgnoreCase(url, URL_PREFIX1)) { + return null; + } + + String urlForMeta = url; + + String dbProductName = url.substring(url.indexOf(":") + 1); + dbProductName = dbProductName.substring(0, dbProductName.indexOf(":")); + int beginningOfSlashes = url.indexOf("//"); + url = url.substring(beginningOfSlashes + 2); + + String host = url.substring(0, url.indexOf(":")); + url = url.substring(url.indexOf(":") + 1); + urlProps.setProperty(PROPERTY_KEY_HOST, host); + + String port = url.substring(0, url.indexOf("/")); + urlProps.setProperty(PROPERTY_KEY_PORT, port); + url = url.substring(url.indexOf("/") + 1); + + if (url.indexOf("?") != -1) { + String dbName = url.substring(0, url.indexOf("?")); + urlProps.setProperty(PROPERTY_KEY_DBNAME, dbName); + url = url.trim().substring(1); + } else { + // without user & password so return + String dbName = url.trim(); + urlProps.setProperty(PROPERTY_KEY_DBNAME, dbName); + this.dbMetaData = new TSDBDatabaseMetaData(dbProductName, urlForMeta, urlProps.getProperty("user")); + return urlProps; + } + + String[] queryStrings = url.trim().split("&"); + String user = ""; + for (String queryStr : queryStrings) { + String[] kvPair = queryStr.trim().split("="); + if (kvPair.length < 2){ + continue; + } + switch (kvPair[0].toLowerCase()) { + case PROPERTY_KEY_USER: + urlProps.setProperty(PROPERTY_KEY_USER, kvPair[1]); + user = kvPair[1]; + break; + case PROPERTY_KEY_PASSWORD: + urlProps.setProperty(PROPERTY_KEY_PASSWORD, kvPair[1]); + break; + case PROPERTY_KEY_TIME_ZONE: + urlProps.setProperty(PROPERTY_KEY_TIME_ZONE, kvPair[1]); + break; + case PROPERTY_KEY_LOCALE: + urlProps.setProperty(PROPERTY_KEY_LOCALE, kvPair[1]); + break; + case PROPERTY_KEY_CHARSET: + urlProps.setProperty(PROPERTY_KEY_CHARSET, kvPair[1]); + break; + case PROPERTY_KEY_CONFIG_DIR: + urlProps.setProperty(PROPERTY_KEY_CONFIG_DIR, kvPair[1]); + break; + } + } + + this.dbMetaData = new TSDBDatabaseMetaData(dbProductName, urlForMeta, user); + + return urlProps; + } + + public int getMajorVersion() { + return 1; + } + + public int getMinorVersion() { + return 1; + } + + public boolean jdbcCompliant() { + return false; + } + + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + return null; + } + + /** + * Returns the host property + * + * @param props + * the java.util.Properties instance to retrieve the hostname from. + * + * @return the host + */ + public String host(Properties props) { + return props.getProperty(PROPERTY_KEY_HOST, "localhost"); + } + + /** + * Returns the port number property + * + * @param props + * the properties to get the port number from + * + * @return the port number + */ + public int port(Properties props) { + return Integer.parseInt(props.getProperty(PROPERTY_KEY_PORT, TSDBConstants.DEFAULT_PORT)); + } + + /** + * Returns the database property from props + * + * @param props + * the Properties to look for the database property. + * + * @return the database name. + */ + public String database(Properties props) { + return props.getProperty(PROPERTY_KEY_DBNAME); + } +} \ No newline at end of file diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError 2.java new file mode 100644 index 0000000000..7d5b02606e --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError 2.java @@ -0,0 +1,223 @@ +/*************************************************************************** + * 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.util.HashMap; +import java.util.Map; + +/** + * + * TDengine error code and error message enumeration. + * + */ +public enum TSDBError { + + TSDB_CODE_SUCCESS(0, "success"), + TSDB_CODE_ACTION_IN_PROGRESS(1, "in progress"), + TSDB_CODE_LAST_SESSION_NOT_FINISHED(5, "last session not finished"), + TSDB_CODE_INVALID_SESSION_ID(6, "invalid session ID"), + TSDB_CODE_INVALID_TRAN_ID(7, "invalid tran ID"), + TSDB_CODE_INVALID_MSG_TYPE(8, "invalid msg type"), + TSDB_CODE_ALREADY_PROCESSED(9, "alredy processed"), + TSDB_CODE_AUTH_FAILURE(10, "authentication failure"), + TSDB_CODE_WRONG_MSG_SIZE(11, "wrong msg size"), + TSDB_CODE_UNEXPECTED_RESPONSE(12, "unexpected response"), + TSDB_CODE_INVALID_RESPONSE_TYPE(13, "invalid response type"), + TSDB_CODE_NO_RESOURCE(14, "no resource"), + TSDB_CODE_INVALID_TIME_STAMP(15, "invalid time stamp"), + TSDB_CODE_MISMATCHED_METER_ID(16, "mismatched meter ID"), + TSDB_CODE_ACTION_TRANS_NOT_FINISHED(17, "transcation not finished"), + TSDB_CODE_ACTION_NOT_ONLINE(18, "not online"), + TSDB_CODE_ACTION_SEND_FAILD(19, "send failed"), + TSDB_CODE_NOT_ACTIVE_SESSION(20, "not active session"), + TSDB_CODE_INSERT_FAILED(21, "insert failed"), + TSDB_CODE_APP_ERROR(22, "App error"), + TSDB_CODE_INVALID_IE(23, "invalid IE"), + TSDB_CODE_INVALID_VALUE(24, "invalid value"), + TSDB_CODE_REDIRECT(25, "service not available"), + TSDB_CODE_ALREADY_THERE(26, "already there"), + TSDB_CODE_INVALID_METER_ID(27, "invalid meter ID"), + TSDB_CODE_INVALID_SQL(28, "invalid SQL"), // this message often comes with additional info which will vary based on the specific error situation + TSDB_CODE_NETWORK_UNAVAIL(29, "failed to connect to server"), + TSDB_CODE_INVALID_MSG_LEN(30, "invalid msg len"), + TSDB_CODE_INVALID_DB(31, "invalid DB"), + TSDB_CODE_INVALID_TABLE(32, "invalid table"), + TSDB_CODE_DB_ALREADY_EXIST(33, "DB already there"), + TSDB_CODE_TABLE_ALREADY_EXIST(34, "table already there"), + TSDB_CODE_INVALID_USER(35, "invalid user name"), + TSDB_CODE_INVALID_ACCT(36, "invalid acct name"), + TSDB_CODE_INVALID_PASS(37, "invalid password"), + TSDB_CODE_DB_NOT_SELECTED(38, "DB not selected"), + TSDB_CODE_MEMORY_CORRUPTED(39, "memory corrupted"), + TSDB_CODE_USER_ALREADY_EXIST(40, "user name exists"), + TSDB_CODE_NO_RIGHTS(41, "not authorized"), + TSDB_CODE_DISCONNECTED(42, "login disconnected), login again"), + TSDB_CODE_NO_MASTER(43, "mgmt master node not available"), + TSDB_CODE_NOT_CONFIGURED(44, "not configured"), + TSDB_CODE_INVALID_OPTION(45, "invalid option"), + TSDB_CODE_NODE_OFFLINE(46, "node offline"), + TSDB_CODE_SYNC_REQUIRED(47, "sync required"), + TSDB_CODE_NO_ENOUGH_DNODES(48, "more dnodes are needed"), + TSDB_CODE_UNSYNCED(49, "node in unsynced state"), + TSDB_CODE_TOO_SLOW(50, "too slow"), + TSDB_CODE_OTHERS(51, "others"), + TSDB_CODE_NO_REMOVE_MASTER(52, "can't remove dnode which is master"), + TSDB_CODE_WRONG_SCHEMA(53, "wrong schema"), + TSDB_CODE_NO_RESULT(54, "no results"), + TSDB_CODE_TOO_MANY_USERS(55, "num of users execeed maxUsers"), + TSDB_CODE_TOO_MANY_DATABSES(56, "num of databases execeed maxDbs"), + TSDB_CODE_TOO_MANY_TABLES(57, "num of tables execeed maxTables"), + TSDB_CODE_TOO_MANY_DNODES(58, "num of dnodes execeed maxDnodes"), + TSDB_CODE_TOO_MANY_ACCTS(59, "num of accounts execeed maxAccts"), + TSDB_CODE_ACCT_ALREADY_EXIST(60, "accout name exists"), + TSDB_CODE_DNODE_ALREADY_EXIST(61, "dnode ip exists"), + TSDB_CODE_SDB_ERROR(62, "sdb error"), + TSDB_CODE_METRICMETA_EXPIRED(63, "metric meta expired"), // local cached metric-meta expired causes error in metric query + TSDB_CODE_NOT_READY(64, "not ready"), // peer is not ready to process data + TSDB_CODE_MAX_SESSIONS(65, "too many sessions on server"), // too many sessions + TSDB_CODE_MAX_CONNECTIONS(66, "too many sessions from app"), // too many connections + TSDB_CODE_SESSION_ALREADY_EXIST(67, "session to dest is already there"), + TSDB_CODE_NO_QSUMMARY(68, "query list not there), please show again"), + TSDB_CODE_SERV_OUT_OF_MEMORY(69, "server out of memory"), + TSDB_CODE_INVALID_QHANDLE(70, "invalid query handle"), + TSDB_CODE_RELATED_TABLES_EXIST(71, "tables related to metric exist"), + TSDB_CODE_MONITOR_DB_FORBEIDDEN(72, "can't drop monitor database or tables"), + TSDB_CODE_VG_COMMITLOG_INIT_FAILED(73, "commit log init failed"), + TSDB_CODE_VG_INIT_FAILED(74, "vgroup init failed"), + TSDB_CODE_DATA_ALREADY_IMPORTED(75, "data is already imported"), + TSDB_CODE_OPS_NOT_SUPPORT(76, "not supported operation"), + TSDB_CODE_INVALID_QUERY_ID(77, "invalid query id string"), + TSDB_CODE_INVALID_STREAM_ID(78, "invalid stream id string"), + TSDB_CODE_INVALID_CONNECTION(79, "invalid connection string"), + TSDB_CODE_ACTION_NOT_BALANCED(80, "dnode not balanced"), + TSDB_CODE_CLI_OUT_OF_MEMORY(81, "client out of memory"), + TSDB_CODE_DATA_OVERFLOW(82, "data value overflow"), + TSDB_CODE_QUERY_CANCELLED(83, "query cancelled"), + TSDB_CODE_GRANT_POINT_LIMITED(84, "grant points limited"), + TSDB_CODE_GRANT_EXPIRED(85, "grant expired"), + TSDB_CODE_CLI_NO_DISKSPACE(86, "client no disk space"), + TSDB_CODE_FILE_CORRUPTED(87, "DB file corrupted"), + TSDB_CODE_INVALID_CLIENT_VERSION(88, "version of client and server not match"); + + private long errCode; + private String errMessage; + private static Map errorCodeMap = new HashMap<>(86); + static { + errorCodeMap.put(0, "success"); + errorCodeMap.put(1, "in progress"); + errorCodeMap.put(5, "last session not finished"); + errorCodeMap.put(6, "invalid session ID"); + errorCodeMap.put(7, "invalid tran ID"); + errorCodeMap.put(8, "invalid msg type"); + errorCodeMap.put(9, "alredy processed"); + errorCodeMap.put(10, "authentication failure"); + errorCodeMap.put(11, "wrong msg size"); + errorCodeMap.put(12, "unexpected response"); + errorCodeMap.put(13, "invalid response type"); + errorCodeMap.put(14, "no resource"); + errorCodeMap.put(15, "invalid time stamp"); + errorCodeMap.put(16, "mismatched meter ID"); + errorCodeMap.put(17, "transcation not finished"); + errorCodeMap.put(18, "not online"); + errorCodeMap.put(19, "send failed"); + errorCodeMap.put(20, "not active session"); + errorCodeMap.put(21, "insert failed"); + errorCodeMap.put(22, "App error"); + errorCodeMap.put(23, "invalid IE"); + errorCodeMap.put(24, "invalid value"); + errorCodeMap.put(25, "service not available"); + errorCodeMap.put(26, "already there"); + errorCodeMap.put(27, "invalid meter ID"); + errorCodeMap.put(28, "invalid SQL"); // this message often comes with additional info which will vary based on the specific error situation + errorCodeMap.put(29, "failed to connect to server"); + errorCodeMap.put(30, "invalid msg len"); + errorCodeMap.put(31, "invalid DB"); + errorCodeMap.put(32, "invalid table"); + errorCodeMap.put(33, "DB already there"); + errorCodeMap.put(34, "table already there"); + errorCodeMap.put(35, "invalid user name"); + errorCodeMap.put(36, "invalid acct name"); + errorCodeMap.put(37, "invalid password"); + errorCodeMap.put(38, "DB not selected"); + errorCodeMap.put(39, "memory corrupted"); + errorCodeMap.put(40, "user name exists"); + errorCodeMap.put(41, "not authorized"); + errorCodeMap.put(42, "login disconnected); login again"); + errorCodeMap.put(43, "mgmt master node not available"); + errorCodeMap.put(44, "not configured"); + errorCodeMap.put(45, "invalid option"); + errorCodeMap.put(46, "node offline"); + errorCodeMap.put(47, "sync required"); + errorCodeMap.put(48, "more dnodes are needed"); + errorCodeMap.put(49, "node in unsynced state"); + errorCodeMap.put(50, "too slow"); + errorCodeMap.put(51, "others"); + errorCodeMap.put(52, "can't remove dnode which is master"); + errorCodeMap.put(53, "wrong schema"); + errorCodeMap.put(54, "no results"); + errorCodeMap.put(55, "num of users execeed maxUsers"); + errorCodeMap.put(56, "num of databases execeed maxDbs"); + errorCodeMap.put(57, "num of tables execeed maxTables"); + errorCodeMap.put(58, "num of dnodes execeed maxDnodes"); + errorCodeMap.put(59, "num of accounts execeed maxAccts"); + errorCodeMap.put(60, "accout name exists"); + errorCodeMap.put(61, "dnode ip exists"); + errorCodeMap.put(62, "sdb error"); + errorCodeMap.put(63, "metric meta expired"); // local cached metric-meta expired causes error in metric query + errorCodeMap.put(64, "not ready"); // peer is not ready to process data + errorCodeMap.put(65, "too many sessions on server"); // too many sessions + errorCodeMap.put(66, "too many sessions from app"); // too many connections + errorCodeMap.put(67, "session to dest is already there"); + errorCodeMap.put(68, "query list not there); please show again"); + errorCodeMap.put(69, "server out of memory"); + errorCodeMap.put(70, "invalid query handle"); + errorCodeMap.put(71, "tables related to metric exist"); + errorCodeMap.put(72, "can't drop monitor database or tables"); + errorCodeMap.put(73, "commit log init failed"); + errorCodeMap.put(74, "vgroup init failed"); + errorCodeMap.put(75, "data is already imported"); + errorCodeMap.put(76, "not supported operation"); + errorCodeMap.put(77, "invalid query id string"); + errorCodeMap.put(78, "invalid stream id string"); + errorCodeMap.put(79, "invalid connection string"); + errorCodeMap.put(80, "dnode not balanced"); + errorCodeMap.put(81, "client out of memory"); + errorCodeMap.put(82, "data value overflow"); + errorCodeMap.put(83, "query cancelled"); + errorCodeMap.put(84, "grant points limited"); + errorCodeMap.put(85, "grant expired"); + errorCodeMap.put(86, "client no disk space"); + errorCodeMap.put(87, "DB file corrupted"); + errorCodeMap.put(88, "version of client and server not match"); + } + + TSDBError(long code, String message) { + this.errCode = code; + this.errMessage = message; + } + + public long getErrCode() { + return this.errCode; + } + + public String getErrMessage() { + return this.errMessage; + } + + public static String getErrMessageByCode(long errCode) { + return errorCodeMap.get(errCode); + } + +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector 2.java new file mode 100755 index 0000000000..3adb601822 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector 2.java @@ -0,0 +1,300 @@ +/*************************************************************************** + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + *****************************************************************************/ +package com.taosdata.jdbc; + +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.util.List; + +public class TSDBJNIConnector { + static volatile Boolean isInitialized = false; + + static { + System.loadLibrary("taos"); + System.out.println("java.library.path:" + System.getProperty("java.library.path")); + } + + /** + * Connection pointer used in C + */ + private long taos = TSDBConstants.JNI_NULL_POINTER; + + /** + * Result set pointer for the current connection + */ + private long taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER; + + /** + * result set status in current connection + */ + private boolean isResultsetClosed = true; + private int affectedRows = -1; + + /** + * Whether the connection is closed + */ + public boolean isClosed() { + return this.taos == TSDBConstants.JNI_NULL_POINTER; + } + + /** + * Returns the status of last result set in current connection + * + * @return + */ + public boolean isResultsetClosed() { + return this.isResultsetClosed; + } + + /** + * Initialize static variables in JNI to optimize performance + */ + public static void init(String configDir, String locale, String charset, String timezone) throws SQLWarning { + synchronized (isInitialized) { + if (!isInitialized) { + initImp(configDir); + if (setOptions(0, locale) < 0) { + throw new SQLWarning(TSDBConstants.WrapErrMsg("Failed to set locale: " + locale + ". System default will be used.")); + } + if (setOptions(1, charset) < 0) { + throw new SQLWarning(TSDBConstants.WrapErrMsg("Failed to set charset: " + charset + ". System default will be used.")); + } + if (setOptions(2, timezone) < 0) { + throw new SQLWarning(TSDBConstants.WrapErrMsg("Failed to set timezone: " + timezone + ". System default will be used.")); + } + isInitialized = true; + TaosGlobalConfig.setCharset(getTsCharset()); + } + } + } + + public static native void initImp(String configDir); + + public static native int setOptions(int optionIndex, String optionValue); + + public static native String getTsCharset(); + + /** + * Get connection pointer + * + * @throws SQLException + */ + public boolean connect(String host, int port, String dbName, String user, String password) throws SQLException { + if (this.taos != TSDBConstants.JNI_NULL_POINTER) { + this.closeConnectionImp(this.taos); + this.taos = TSDBConstants.JNI_NULL_POINTER; + } + + this.taos = this.connectImp(host, port, dbName, user, password); + if (this.taos == TSDBConstants.JNI_NULL_POINTER) { + throw new SQLException(TSDBConstants.WrapErrMsg(this.getErrMsg()), "", this.getErrCode()); + } + + return true; + } + + private native long connectImp(String host, int port, String dbName, String user, String password); + + /** + * Execute DML/DDL operation + * + * @throws SQLException + */ + public int executeQuery(String sql) throws SQLException { + if (!this.isResultsetClosed) { + freeResultSet(taosResultSetPointer); + } + + int code; + try { + code = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos); + } catch (Exception e) { + e.printStackTrace(); + throw new SQLException(TSDBConstants.WrapErrMsg("Unsupported encoding")); + } + affectedRows = code; + if (code < 0) { + affectedRows = -1; + if (code == TSDBConstants.JNI_TDENGINE_ERROR) { + throw new SQLException(TSDBConstants.WrapErrMsg(this.getErrMsg()), "", this.getErrCode()); + } else { + throw new SQLException(TSDBConstants.FixErrMsg(code), "", this.getErrCode()); + } + } + + // Try retrieving result set for the executed SQL using the current connection pointer. If the executed + // SQL is a DML/DDL which doesn't return a result set, then taosResultSetPointer should be 0L. Otherwise, + // taosResultSetPointer should be a non-zero value. + taosResultSetPointer = this.getResultSetImp(this.taos); + if (taosResultSetPointer != TSDBConstants.JNI_NULL_POINTER) { + isResultsetClosed = false; + } + return code; + } + + private native int executeQueryImp(byte[] sqlBytes, long connection); + + /** + * Get recent error code by connection + */ + public int getErrCode() { + return Math.abs(this.getErrCodeImp(this.taos)); + } + + private native int getErrCodeImp(long connection); + + /** + * Get recent error message by connection + */ + public String getErrMsg() { + return this.getErrMsgImp(this.taos); + } + + private native String getErrMsgImp(long connection); + + /** + * Get resultset pointer + * Each connection should have a single open result set at a time + */ + public long getResultSet() { + return taosResultSetPointer; + } + + private native long getResultSetImp(long connection); + + /** + * Free resultset operation from C to release resultset pointer by JNI + */ + public int freeResultSet(long result) { + int res = TSDBConstants.JNI_SUCCESS; + if (result != taosResultSetPointer && taosResultSetPointer != TSDBConstants.JNI_NULL_POINTER) { + throw new RuntimeException("Invalid result set pointer"); + } else if (taosResultSetPointer != TSDBConstants.JNI_NULL_POINTER) { + res = this.freeResultSetImp(this.taos, result); + isResultsetClosed = true; // reset resultSetPointer to 0 after freeResultSetImp() return + taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER; + } else { + isResultsetClosed = true; + } + return res; + } + + /** + * Close the open result set which is associated to the current connection. If the result set is already + * closed, return 0 for success. + * + * @return + */ + public int freeResultSet() { + int resCode = TSDBConstants.JNI_SUCCESS; + if (!isResultsetClosed) { + resCode = this.freeResultSetImp(this.taos, this.taosResultSetPointer); + taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER; + isResultsetClosed = true; + } + return resCode; + } + + private native int freeResultSetImp(long connection, long result); + + /** + * Get affected rows count + */ + public int getAffectedRows() { + int affectedRows = this.affectedRows; + if (affectedRows < 0) { + affectedRows = this.getAffectedRowsImp(this.taos); + } + return affectedRows; + } + + private native int getAffectedRowsImp(long connection); + + /** + * Get schema metadata + */ + public int getSchemaMetaData(long resultSet, List columnMetaData) { + return this.getSchemaMetaDataImp(this.taos, resultSet, columnMetaData); + } + + 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); + + /** + * Execute close operation from C to release connection pointer by JNI + * + * @throws SQLException + */ + public void closeConnection() throws SQLException { + int code = this.closeConnectionImp(this.taos); + if (code < 0) { + throw new SQLException(TSDBConstants.FixErrMsg(code), "", this.getErrCode()); + } else if (code == 0) { + this.taos = TSDBConstants.JNI_NULL_POINTER; + } else { + throw new SQLException("Undefined error code returned by TDengine when closing a connection"); + } + } + + private native int closeConnectionImp(long connection); + + /** + * Subscribe to a table in TSDB + */ + public long subscribe(String host, String user, String password, String database, String table, long time, int period) { + return subscribeImp(host, user, password, database, table, time, period); + } + + private native long subscribeImp(String host, String user, String password, String database, String table, long time, int period); + + /** + * Consume a subscribed table + */ + public TSDBResultSetRowData consume(long subscription) { + return this.consumeImp(subscription); + } + + private native TSDBResultSetRowData consumeImp(long subscription); + + /** + * Unsubscribe a table + * + * @param subscription + */ + public void unsubscribe(long subscription) { + unsubscribeImp(subscription); + } + + private native void unsubscribeImp(long subscription); + + /** + * Validate if a create table sql statement is correct without actually creating that table + */ + public boolean validateCreateTableSql(String sql) { + long connection = taos; + int res = validateCreateTableSqlImp(connection, sql.getBytes()); + return res != 0 ? false : true; + } + + private native int validateCreateTableSqlImp(long connection, byte[] sqlBytes); +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBParameterMetaData 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBParameterMetaData 2.java new file mode 100644 index 0000000000..d9227523d4 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBParameterMetaData 2.java @@ -0,0 +1,75 @@ +/*************************************************************************** + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + *****************************************************************************/ +package com.taosdata.jdbc; + +import java.sql.ParameterMetaData; +import java.sql.SQLException; + +public class TSDBParameterMetaData implements ParameterMetaData { + @Override + public int getParameterCount() throws SQLException { + return 0; + } + + @Override + public int isNullable(int param) throws SQLException { + return 0; + } + + @Override + public boolean isSigned(int param) throws SQLException { + return false; + } + + @Override + public int getPrecision(int param) throws SQLException { + return 0; + } + + @Override + public int getScale(int param) throws SQLException { + return 0; + } + + @Override + public int getParameterType(int param) throws SQLException { + return 0; + } + + @Override + public String getParameterTypeName(int param) throws SQLException { + return null; + } + + @Override + public String getParameterClassName(int param) throws SQLException { + return null; + } + + @Override + public int getParameterMode(int param) throws SQLException { + return 0; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement 2.java new file mode 100644 index 0000000000..6097ad9c43 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement 2.java @@ -0,0 +1,478 @@ +/*************************************************************************** + * 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.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.*; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/* + * TDengine only supports a subset of the standard SQL, thus this implemetation of the + * standard JDBC API contains more or less some adjustments customized for certain + * compatibility needs. + */ +public class TSDBPreparedStatement extends TSDBStatement implements PreparedStatement { + protected String rawSql; + protected String sql; + protected ArrayList parameters = new ArrayList(); + + //start with insert or import and is case-insensitive + private static Pattern savePattern = Pattern.compile("(?i)^\\s*(insert|import)"); + + // is insert or import + private boolean isSaved; + + private SavedPreparedStatement savedPreparedStatement; + + TSDBPreparedStatement(TSDBJNIConnector connecter, String sql) { + super(connecter); + init(sql); + } + + private void init(String sql) { + this.rawSql = sql; + preprocessSql(); + + this.isSaved = isSavedSql(this.rawSql); + if (this.isSaved) { + + try { + this.savedPreparedStatement = new SavedPreparedStatement(this.rawSql, this); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + /** + * if the precompiled sql is insert or import + * + * @param sql + * @return + */ + private boolean isSavedSql(String sql) { + Matcher matcher = savePattern.matcher(sql); + return matcher.find(); + } + + @Override + public int[] executeBatch() throws SQLException { + if (isSaved) { + return this.savedPreparedStatement.executeBatch(); + } else { + return super.executeBatch(); + } + } + + public ArrayList getParameters() { + return parameters; + } + + public void setParameters(ArrayList parameters) { + this.parameters = parameters; + } + + public String getRawSql() { + return rawSql; + } + + /* + * 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*****/ + // should replace it first + this.rawSql = this.rawSql.replaceAll("or (.*) is null", ""); + this.rawSql = this.rawSql.replaceAll(" where ", " WHERE "); + this.rawSql = this.rawSql.replaceAll(" or ", " OR "); + this.rawSql = this.rawSql.replaceAll(" and ", " AND "); + this.rawSql = this.rawSql.replaceAll(" is null", " IS NULL"); + this.rawSql = this.rawSql.replaceAll(" is not null", " IS NOT NULL"); + + // 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("\"", ""); + + // SELECT 1 FROM db.tb + this.rawSql = this.rawSql.replaceAll("SELECT 1 FROM", "SELECT * FROM"); + + // SELECT "ts","val" FROM db.tb WHERE ts < 33 or ts is null + this.rawSql = this.rawSql.replaceAll("OR (.*) IS NULL", ""); + + // SELECT "ts","val" FROM db.tb WHERE ts is null or ts < 33 + this.rawSql = this.rawSql.replaceAll("(.*) IS NULL OR", ""); + + // SELECT 1 FROM db.tb WHERE (("val" IS NOT NULL) AND ("val" > 50)) AND (ts >= 66) + this.rawSql = this.rawSql.replaceAll("\\(\\((.*) IS NOT NULL\\) AND", "("); + + // SELECT 1 FROM db.tb WHERE ("val" IS NOT NULL) AND ("val" > 50) AND (ts >= 66) + this.rawSql = this.rawSql.replaceAll("\\((.*) IS NOT NULL\\) AND", ""); + + // SELECT "ts","val" FROM db.tb WHERE (("val" IS NOT NULL)) AND (ts < 33 or ts is null) + this.rawSql = this.rawSql.replaceAll("\\(\\((.*) IS NOT NULL\\)\\) AND", ""); + + /***** 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); + } + /***** for inner queries *****/ + + } + + /** + * Populate parameters into prepared sql statements + * + * @return a string of the native sql statement for TSDB + */ + private String getNativeSql() { + this.sql = this.rawSql; + for (int i = 0; i < parameters.size(); ++i) { + Object para = parameters.get(i); + if (para != null) { + String paraStr = para.toString(); + if (para instanceof Timestamp || para instanceof String) { + paraStr = "'" + paraStr + "'"; + } + this.sql = this.sql.replaceFirst("[?]", paraStr); + } else { + this.sql = this.sql.replaceFirst("[?]", "NULL"); + } + } + parameters.clear(); + return sql; + } + + @Override + public ResultSet executeQuery() throws SQLException { + if (isSaved) { + this.savedPreparedStatement.executeBatchInternal(); + return null; + } else { + return super.executeQuery(getNativeSql()); + } + } + + @Override + public int executeUpdate() throws SQLException { + if (isSaved) { + return this.savedPreparedStatement.executeBatchInternal(); + } else { + return super.executeUpdate(getNativeSql()); + } + } + + @Override + public void setNull(int parameterIndex, int sqlType) throws SQLException { + setObject(parameterIndex, new String("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); + } + + @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, x); + } + + @Override + public void setTime(int parameterIndex, Time x) throws SQLException { + setObject(parameterIndex, x); + } + + @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 { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void clearParameters() throws SQLException { + parameters.clear(); + } + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setObject(int parameterIndex, Object x) throws SQLException { + if (isSaved) { + this.savedPreparedStatement.setParam(parameterIndex, x); + } else { + parameters.add(x); + } + } + + @Override + public boolean execute() throws SQLException { + if (isSaved) { + int result = this.savedPreparedStatement.executeBatchInternal(); + return result > 0; + } else { + return super.execute(getNativeSql()); + } + } + + @Override + public void addBatch() throws SQLException { + if (isSaved) { + this.savedPreparedStatement.addBatch(); + } else { + + if (this.batchedArgs == null) { + batchedArgs = new ArrayList(); + } + super.addBatch(getNativeSql()); + } + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setRef(int parameterIndex, Ref x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setBlob(int parameterIndex, Blob x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setClob(int parameterIndex, Clob x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setArray(int parameterIndex, Array x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setURL(int parameterIndex, URL x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public ParameterMetaData getParameterMetaData() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setRowId(int parameterIndex, RowId x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setNString(int parameterIndex, String value) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setNClob(int parameterIndex, NClob value) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setClob(int parameterIndex, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public void setNClob(int parameterIndex, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet 2.java new file mode 100644 index 0000000000..8acf779756 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSet 2.java @@ -0,0 +1,1033 @@ +/*************************************************************************** + * 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.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +@SuppressWarnings("unused") +public class TSDBResultSet implements ResultSet { + private TSDBJNIConnector jniConnector = null; + + private long resultSetPointer = 0L; + private List columnMetaDataList = new ArrayList(); + + private TSDBResultSetRowData rowData; + + private boolean lastWasNull = false; + private final int COLUMN_INDEX_START_VALUE = 1; + + public TSDBJNIConnector getJniConnector() { + return jniConnector; + } + + public void setJniConnector(TSDBJNIConnector jniConnector) { + this.jniConnector = jniConnector; + } + + public long getResultSetPointer() { + return resultSetPointer; + } + + public void setResultSetPointer(long resultSetPointer) { + this.resultSetPointer = resultSetPointer; + } + + public List getColumnMetaDataList() { + return columnMetaDataList; + } + + public void setColumnMetaDataList(List columnMetaDataList) { + this.columnMetaDataList = columnMetaDataList; + } + + public TSDBResultSetRowData getRowData() { + return rowData; + } + + public void setRowData(TSDBResultSetRowData rowData) { + this.rowData = rowData; + } + + public boolean isLastWasNull() { + return lastWasNull; + } + + public void setLastWasNull(boolean lastWasNull) { + this.lastWasNull = lastWasNull; + } + + public TSDBResultSet() { + } + + public TSDBResultSet(TSDBJNIConnector connecter, long resultSetPointer) throws SQLException { + this.jniConnector = connecter; + this.resultSetPointer = resultSetPointer; + int code = this.jniConnector.getSchemaMetaData(this.resultSetPointer, this.columnMetaDataList); + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); + } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_NUM_OF_FIELDS_0)); + } + + this.rowData = new TSDBResultSetRowData(this.columnMetaDataList.size()); + } + + public T unwrap(Class iface) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean next() throws SQLException { + if (rowData != null) { + this.rowData.clear(); + } + + int code = this.jniConnector.fetchRow(this.resultSetPointer, this.rowData); + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); + } else if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_NUM_OF_FIELDS_0)); + } else if (code == TSDBConstants.JNI_FETCH_END) { + return false; + } else { + return true; + } + } + + public void close() throws SQLException { + if (this.jniConnector != null) { + int code = this.jniConnector.freeResultSet(this.resultSetPointer); + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); + } + } + } + + public boolean wasNull() throws SQLException { + return this.lastWasNull; + } + + public String getString(int columnIndex) throws SQLException { + String res = null; + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getString(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } + + public boolean getBoolean(int columnIndex) throws SQLException { + boolean res = false; + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getBoolean(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } + + public byte getByte(int columnIndex) throws SQLException { + byte res = 0; + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = (byte) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } + + public short getShort(int columnIndex) throws SQLException { + short res = 0; + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = (short) this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } + + public int getInt(int columnIndex) throws SQLException { + int res = 0; + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getInt(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } + + public long getLong(int columnIndex) throws SQLException { + long res = 0l; + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } + + public float getFloat(int columnIndex) throws SQLException { + float res = 0; + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getFloat(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } + + public double getDouble(int columnIndex) throws SQLException { + double res = 0; + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getDouble(colIndex, this.columnMetaDataList.get(colIndex).getColType()); + } + return res; + } + + /* + * (non-Javadoc) + * + * @see java.sql.ResultSet#getBigDecimal(int, int) + * + * @deprecated Use {@code getBigDecimal(int columnIndex)} or {@code + * getBigDecimal(String columnLabel)} + */ + @Deprecated + public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { + BigDecimal res = null; + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = new BigDecimal(this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType())); + } + return res; + } + + public byte[] getBytes(int columnIndex) throws SQLException { + byte[] res = null; + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getString(colIndex, this.columnMetaDataList.get(colIndex).getColType()).getBytes(); + } + return res; + } + + public Date getDate(int columnIndex) throws SQLException { + int colIndex = getTrueColumnIndex(columnIndex); + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Time getTime(int columnIndex) throws SQLException { + int colIndex = getTrueColumnIndex(columnIndex); + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Timestamp getTimestamp(int columnIndex) throws SQLException { + Timestamp res = null; + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + if (!lastWasNull) { + res = this.rowData.getTimestamp(colIndex); + } + return res; + } + + public InputStream getAsciiStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + /* + * (non-Javadoc) + * + * @see java.sql.ResultSet#getUnicodeStream(int) + * + * * @deprecated use getCharacterStream in place of + * getUnicodeStream + */ + @Deprecated + public InputStream getUnicodeStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public InputStream getBinaryStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public String getString(String columnLabel) throws SQLException { + return this.getString(this.findColumn(columnLabel)); + } + + public boolean getBoolean(String columnLabel) throws SQLException { + return this.getBoolean(this.findColumn(columnLabel)); + } + + public byte getByte(String columnLabel) throws SQLException { + return this.getByte(this.findColumn(columnLabel)); + } + + public short getShort(String columnLabel) throws SQLException { + return this.getShort(this.findColumn(columnLabel)); + } + + public int getInt(String columnLabel) throws SQLException { + return this.getInt(this.findColumn(columnLabel)); + } + + public long getLong(String columnLabel) throws SQLException { + return this.getLong(this.findColumn(columnLabel)); + } + + public float getFloat(String columnLabel) throws SQLException { + return this.getFloat(this.findColumn(columnLabel)); + } + + public double getDouble(String columnLabel) throws SQLException { + return this.getDouble(this.findColumn(columnLabel)); + } + + /* + * used by spark + */ + @Deprecated + public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { + return this.getBigDecimal(this.findColumn(columnLabel), scale); + } + + public byte[] getBytes(String columnLabel) throws SQLException { + return this.getBytes(this.findColumn(columnLabel)); + } + + public Date getDate(String columnLabel) throws SQLException { + return this.getDate(this.findColumn(columnLabel)); + } + + public Time getTime(String columnLabel) throws SQLException { + return this.getTime(this.findColumn(columnLabel)); + } + + public Timestamp getTimestamp(String columnLabel) throws SQLException { + return this.getTimestamp(this.findColumn(columnLabel)); + } + + public InputStream getAsciiStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Deprecated + public InputStream getUnicodeStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public InputStream getBinaryStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public SQLWarning getWarnings() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void clearWarnings() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public String getCursorName() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public ResultSetMetaData getMetaData() throws SQLException { + return new TSDBResultSetMetaData(this.columnMetaDataList); + } + + public Object getObject(int columnIndex) throws SQLException { + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + return this.rowData.get(colIndex); + } + + public Object getObject(String columnLabel) throws SQLException { + return this.getObject(this.findColumn(columnLabel)); + } + + public int findColumn(String columnLabel) throws SQLException { + Iterator colMetaDataIt = this.columnMetaDataList.iterator(); + while (colMetaDataIt.hasNext()) { + ColumnMetaData colMetaData = colMetaDataIt.next(); + if (colMetaData.getColName() != null && colMetaData.getColName().equalsIgnoreCase(columnLabel)) { + return colMetaData.getColIndex() + 1; + } + } + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + } + + public Reader getCharacterStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Reader getCharacterStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + /* + * used by spark + */ + public BigDecimal getBigDecimal(int columnIndex) throws SQLException { + int colIndex = getTrueColumnIndex(columnIndex); + + this.lastWasNull = this.rowData.wasNull(colIndex); + return new BigDecimal(this.rowData.getLong(colIndex, this.columnMetaDataList.get(colIndex).getColType())); + } + + public BigDecimal getBigDecimal(String columnLabel) throws SQLException { + return this.getBigDecimal(this.findColumn(columnLabel)); + } + + public boolean isBeforeFirst() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isAfterLast() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isFirst() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isLast() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void beforeFirst() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void afterLast() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean first() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean last() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean absolute(int row) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean relative(int rows) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean previous() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setFetchDirection(int direction) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getFetchDirection() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setFetchSize(int rows) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getFetchSize() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getType() throws SQLException { + return ResultSet.TYPE_FORWARD_ONLY; + } + + public int getConcurrency() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean rowUpdated() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean rowInserted() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean rowDeleted() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNull(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBoolean(int columnIndex, boolean x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateByte(int columnIndex, byte x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateShort(int columnIndex, short x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateInt(int columnIndex, int x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateLong(int columnIndex, long x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateFloat(int columnIndex, float x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateDouble(int columnIndex, double x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateString(int columnIndex, String x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBytes(int columnIndex, byte[] x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateDate(int columnIndex, Date x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateTime(int columnIndex, Time x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateObject(int columnIndex, Object x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNull(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBoolean(String columnLabel, boolean x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateByte(String columnLabel, byte x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateShort(String columnLabel, short x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateInt(String columnLabel, int x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateLong(String columnLabel, long x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateFloat(String columnLabel, float x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateDouble(String columnLabel, double x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateString(String columnLabel, String x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBytes(String columnLabel, byte[] x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateDate(String columnLabel, Date x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateTime(String columnLabel, Time x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateObject(String columnLabel, Object x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void insertRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void deleteRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void refreshRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void cancelRowUpdates() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void moveToInsertRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void moveToCurrentRow() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Statement getStatement() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Object getObject(int columnIndex, Map> map) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Ref getRef(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Blob getBlob(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Clob getClob(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Array getArray(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Object getObject(String columnLabel, Map> map) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Ref getRef(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Blob getBlob(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Clob getClob(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Array getArray(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Date getDate(String columnLabel, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Time getTime(String columnLabel, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public URL getURL(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public URL getURL(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateRef(int columnIndex, Ref x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateRef(String columnLabel, Ref x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBlob(int columnIndex, Blob x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBlob(String columnLabel, Blob x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateClob(int columnIndex, Clob x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateClob(String columnLabel, Clob x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateArray(int columnIndex, Array x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateArray(String columnLabel, Array x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public RowId getRowId(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public RowId getRowId(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateRowId(int columnIndex, RowId x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateRowId(String columnLabel, RowId x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getHoldability() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isClosed() throws SQLException { + boolean isClosed = true; + if (jniConnector != null) { + isClosed = jniConnector.isResultsetClosed(); + } + return isClosed; + } + + public void updateNString(int columnIndex, String nString) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNString(String columnLabel, String nString) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNClob(int columnIndex, NClob nClob) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNClob(String columnLabel, NClob nClob) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public NClob getNClob(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public NClob getNClob(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public SQLXML getSQLXML(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public SQLXML getSQLXML(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public String getNString(int columnIndex) throws SQLException { + int colIndex = getTrueColumnIndex(columnIndex); + return (String) rowData.get(colIndex); + } + + public String getNString(String columnLabel) throws SQLException { + return (String) this.getString(columnLabel); + } + + public Reader getNCharacterStream(int columnIndex) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public Reader getNCharacterStream(String columnLabel) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateClob(int columnIndex, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateClob(String columnLabel, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNClob(int columnIndex, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void updateNClob(String columnLabel, Reader reader) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public T getObject(int columnIndex, Class type) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public T getObject(String columnLabel, Class type) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + private int getTrueColumnIndex(int columnIndex) throws SQLException { + if (columnIndex < this.COLUMN_INDEX_START_VALUE) { + throw new SQLException("Column Index out of range, " + columnIndex + " < " + this.COLUMN_INDEX_START_VALUE); + } + + int numOfCols = this.columnMetaDataList.size(); + if (columnIndex > numOfCols) { + throw new SQLException("Column Index out of range, " + columnIndex + " > " + numOfCols); + } + + return columnIndex - 1; + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData 2.java new file mode 100644 index 0000000000..d6d69bd8b0 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetMetaData 2.java @@ -0,0 +1,213 @@ +/*************************************************************************** + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + *****************************************************************************/ +package com.taosdata.jdbc; + +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.sql.Types; +import java.util.List; + +public class TSDBResultSetMetaData implements ResultSetMetaData { + + List colMetaDataList = null; + + public TSDBResultSetMetaData(List metaDataList) { + this.colMetaDataList = metaDataList; + } + + public T unwrap(Class iface) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getColumnCount() throws SQLException { + return colMetaDataList.size(); + } + + public boolean isAutoIncrement(int column) throws SQLException { + return false; + } + + public boolean isCaseSensitive(int column) throws SQLException { + return false; + } + + public boolean isSearchable(int column) throws SQLException { + if (column == 1) { + return true; + } + return false; + } + + public boolean isCurrency(int column) throws SQLException { + return false; + } + + public int isNullable(int column) throws SQLException { + if (column == 1) { + return columnNoNulls; + } + return columnNullable; + } + + public boolean isSigned(int column) throws SQLException { + ColumnMetaData meta = this.colMetaDataList.get(column - 1); + switch (meta.getColType()) { + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: + case TSDBConstants.TSDB_DATA_TYPE_INT: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: + return true; + default: + return false; + } + } + + public int getColumnDisplaySize(int column) throws SQLException { + return colMetaDataList.get(column - 1).getColSize(); + } + + public String getColumnLabel(int column) throws SQLException { + return colMetaDataList.get(column - 1).getColName(); + } + + public String getColumnName(int column) throws SQLException { + return colMetaDataList.get(column - 1).getColName(); + } + + public String getSchemaName(int column) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getPrecision(int column) throws SQLException { + ColumnMetaData columnMetaData = this.colMetaDataList.get(column - 1); + switch (columnMetaData.getColType()) { + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: + return 5; + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: + return 9; + case TSDBConstants.TSDB_DATA_TYPE_BINARY: + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + return columnMetaData.getColSize(); + default: + return 0; + } + } + + public int getScale(int column) throws SQLException { + ColumnMetaData meta = this.colMetaDataList.get(column - 1); + switch (meta.getColType()) { + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: + return 5; + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: + return 9; + default: + return 0; + } + } + + public String getTableName(int column) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public String getCatalogName(int column) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getColumnType(int column) throws SQLException { + ColumnMetaData meta = this.colMetaDataList.get(column - 1); + switch (meta.getColType()) { + case TSDBConstants.TSDB_DATA_TYPE_BOOL: + return java.sql.Types.BIT; + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: + return java.sql.Types.TINYINT; + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: + return java.sql.Types.SMALLINT; + case TSDBConstants.TSDB_DATA_TYPE_INT: + return java.sql.Types.INTEGER; + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: + return java.sql.Types.BIGINT; + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: + return java.sql.Types.FLOAT; + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: + return java.sql.Types.DOUBLE; + case TSDBConstants.TSDB_DATA_TYPE_BINARY: + return java.sql.Types.CHAR; + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + return java.sql.Types.BIGINT; + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + return java.sql.Types.CHAR; + } + throw new SQLException(TSDBConstants.INVALID_VARIABLES); + } + + public String getColumnTypeName(int column) throws SQLException { + ColumnMetaData meta = this.colMetaDataList.get(column - 1); + return TSDBConstants.DATATYPE_MAP.get(meta.getColType()); + } + + public boolean isReadOnly(int column) throws SQLException { + return true; + } + + public boolean isWritable(int column) throws SQLException { + return false; + } + + public boolean isDefinitelyWritable(int column) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public String getColumnClassName(int column) throws SQLException { + int columnType = getColumnType(column); + String columnClassName = ""; + switch (columnType) { + case Types.TIMESTAMP: + columnClassName = Timestamp.class.getName(); + break; + case Types.CHAR: + columnClassName = String.class.getName(); + break; + case Types.DOUBLE: + columnClassName = Double.class.getName(); + break; + case Types.FLOAT: + columnClassName = Float.class.getName(); + break; + case Types.BIGINT: + columnClassName = Long.class.getName(); + break; + case Types.INTEGER: + columnClassName = Integer.class.getName(); + break; + case Types.SMALLINT: + columnClassName = Short.class.getName(); + break; + case Types.TINYINT: + columnClassName = Byte.class.getName(); + break; + case Types.BIT: + columnClassName = Boolean.class.getName(); + break; + } + return columnClassName; + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData 2.java new file mode 100644 index 0000000000..8efcac9000 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData 2.java @@ -0,0 +1,222 @@ +/*************************************************************************** + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + *****************************************************************************/ +package com.taosdata.jdbc; + +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Collections; + +public class TSDBResultSetRowData { + private ArrayList data = null; + private int colSize = 0; + + public TSDBResultSetRowData(int colSize) { + this.setColSize(colSize); + } + + public TSDBResultSetRowData() { + this.data = new ArrayList(); + this.setColSize(0); + } + + public void clear() { + if(this.data != null) { + this.data.clear(); + } + if (this.colSize == 0) { + return; + } + this.data = new ArrayList(colSize); + this.data.addAll(Collections.nCopies(this.colSize, null)); + } + + public boolean wasNull(int col) { + return data.get(col) == null; + } + + public void setBoolean(int col, boolean value) { + data.set(col, value); + } + + public boolean getBoolean(int col, int srcType) throws SQLException { + Object obj = data.get(col); + + switch(srcType) { + case TSDBConstants.TSDB_DATA_TYPE_BOOL: return (Boolean) obj; + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj) == 1.0? Boolean.TRUE:Boolean.FALSE; + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double) obj) == 1.0? Boolean.TRUE:Boolean.FALSE; + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return ((Byte) obj) == 1? Boolean.TRUE:Boolean.FALSE; + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return ((Short)obj) == 1? Boolean.TRUE:Boolean.FALSE; + case TSDBConstants.TSDB_DATA_TYPE_INT: return ((Integer)obj) == 1? Boolean.TRUE:Boolean.FALSE; + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return ((Long) obj) == 1L? Boolean.TRUE:Boolean.FALSE; + } + + return Boolean.TRUE; + } + + public void setByte(int col, byte value) { + data.set(col, value); + } + + public void setShort(int col, short value) { + data.set(col, value); + } + + public void setInt(int col, int value) { + data.set(col, value); + } + + public int getInt(int col, int srcType) throws SQLException { + Object obj = data.get(col); + + switch(srcType) { + case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0; + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).intValue(); + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double)obj).intValue(); + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj; + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return (Short) obj; + case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj; + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return ((Long) obj).intValue(); + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Integer.parseInt((String) obj); + } + + return 0; + } + + public void setLong(int col, long value) { + data.set(col, value); + } + + public long getLong(int col, int srcType) throws SQLException { + Object obj = data.get(col); + + switch(srcType) { + case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0; + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).longValue(); + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double) obj).longValue(); + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj; + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return (Short) obj; + case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj; + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj; + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Long.parseLong((String) obj); + } + + return 0; + } + + public void setFloat(int col, float value) { + data.set(col, value); + } + + public float getFloat(int col, int srcType) throws SQLException { + Object obj = data.get(col); + + switch(srcType) { + case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0; + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return (Float) obj; + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double) obj).floatValue(); + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj; + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT: return (Short) obj; + case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj; + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj; + } + + return 0; + } + + public void setDouble(int col, double value) { + data.set(col, value); + } + + public double getDouble(int col, int srcType) throws SQLException { + Object obj = data.get(col); + + switch(srcType) { + case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0; + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return (Float) obj; + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return (Double) obj; + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj; + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return (Short) obj; + case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj; + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj; + } + + return 0; + } + + public void setString(int col, String value) { + data.set(col, value); + } + + public void setByteArray(int col, byte[] value) { + try { + data.set(col, new String(value, TaosGlobalConfig.getCharset())); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * The original type may not be a string type, but will be converted to by calling this method + * @param col column index + * @return + * @throws SQLException + */ + public String getString(int col, int srcType) throws SQLException { + if (srcType == TSDBConstants.TSDB_DATA_TYPE_BINARY || srcType == TSDBConstants.TSDB_DATA_TYPE_NCHAR) { + return (String) data.get(col); + } else { + return String.valueOf(data.get(col)); + } + } + + public void setTimestamp(int col, long ts) { + data.set(col, ts); + } + + public Timestamp getTimestamp(int col) { + return new Timestamp((Long) data.get(col)); + } + + public Object get(int col) { + return data.get(col); + } + + public int getColSize() { + return colSize; + } + + public void setColSize(int colSize) { + this.colSize = colSize; + this.clear(); + } + + public ArrayList getData() { + return data; + } + + public void setData(ArrayList data) { + this.data = (ArrayList) data.clone(); + } + +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetWrapper 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetWrapper 2.java new file mode 100644 index 0000000000..059962a7a1 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetWrapper 2.java @@ -0,0 +1,1172 @@ +/*************************************************************************** + * 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.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.*; +import java.util.Calendar; +import java.util.Map; + +/* + * TDengine only supports a subset of the standard SQL, thus this implemetation of the + * standard JDBC API contains more or less some adjustments customized for certain + * compatibility needs. + */ +public class TSDBResultSetWrapper implements ResultSet { + + private ResultSet originalResultSet; + + public ResultSet getOriginalResultSet() { + return originalResultSet; + } + + public void setOriginalResultSet(ResultSet originalResultSet) { + this.originalResultSet = originalResultSet; + } + + @Override + public boolean next() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.next(); + } + + @Override + public void close() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + this.originalResultSet.close(); + } + + @Override + public boolean wasNull() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.wasNull(); + } + + @Override + public String getString(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getString(columnIndex); + } + + @Override + public boolean getBoolean(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getBoolean(columnIndex); + } + + @Override + public byte getByte(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getByte(columnIndex); + } + + @Override + public short getShort(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getShort(columnIndex); + } + + @Override + public int getInt(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getInt(columnIndex); + } + + @Override + public long getLong(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getLong(columnIndex); + } + + @Override + public float getFloat(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getFloat(columnIndex); + } + + @Override + public double getDouble(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getDouble(columnIndex); + } + + @Override + public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getBigDecimal(columnIndex, scale); + } + + @Override + public byte[] getBytes(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + if (columnIndex <= 1) { + return this.originalResultSet.getBytes(columnIndex); + } else { + return null; + } + } + + @Override + public Date getDate(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getDate(columnIndex); + } + + @Override + public Time getTime(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getTime(columnIndex); + } + + @Override + public Timestamp getTimestamp(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getTimestamp(columnIndex); + } + + @Override + public InputStream getAsciiStream(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getAsciiStream(columnIndex); + } + + @Override + public InputStream getUnicodeStream(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getUnicodeStream(columnIndex); + } + + @Override + public InputStream getBinaryStream(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getBinaryStream(columnIndex); + } + + @Override + public String getString(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getString(columnLabel); + } + + @Override + public boolean getBoolean(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getBoolean(columnLabel); + } + + @Override + public byte getByte(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getByte(columnLabel); + } + + @Override + public short getShort(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getShort(columnLabel); + } + + @Override + public int getInt(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getInt(columnLabel); + } + + @Override + public long getLong(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getLong(columnLabel); + } + + @Override + public float getFloat(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getFloat(columnLabel); + } + + @Override + public double getDouble(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getDouble(columnLabel); + } + + @Override + public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getBigDecimal(columnLabel, scale); + } + + @Override + public byte[] getBytes(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getBytes(columnLabel); + } + + @Override + public Date getDate(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getDate(columnLabel); + } + + @Override + public Time getTime(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getTime(columnLabel); + } + + @Override + public Timestamp getTimestamp(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getTimestamp(columnLabel); + } + + @Override + public InputStream getAsciiStream(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getAsciiStream(columnLabel); + } + + @Override + public InputStream getUnicodeStream(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getUnicodeStream(columnLabel); + } + + @Override + public InputStream getBinaryStream(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getBinaryStream(columnLabel); + } + + @Override + public SQLWarning getWarnings() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getWarnings(); + } + + @Override + public void clearWarnings() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + this.originalResultSet.clearWarnings(); + } + + @Override + public String getCursorName() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getCursorName(); + } + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getMetaData(); + } + + @Override + public Object getObject(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getObject(columnIndex); + } + + @Override + public Object getObject(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getObject(columnLabel); + } + + @Override + public int findColumn(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.findColumn(columnLabel); + } + + @Override + public Reader getCharacterStream(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getCharacterStream(columnIndex); + } + + @Override + public Reader getCharacterStream(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getCharacterStream(columnLabel); + } + + @Override + public BigDecimal getBigDecimal(int columnIndex) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getBigDecimal(columnIndex); + } + + @Override + public BigDecimal getBigDecimal(String columnLabel) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getBigDecimal(columnLabel); + } + + @Override + public boolean isBeforeFirst() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.isBeforeFirst(); + } + + @Override + public boolean isAfterLast() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.isAfterLast(); + } + + @Override + public boolean isFirst() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.isFirst(); + } + + @Override + public boolean isLast() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.isLast(); + } + + @Override + public void beforeFirst() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + this.originalResultSet.beforeFirst(); + } + + @Override + public void afterLast() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + this.originalResultSet.afterLast(); + } + + @Override + public boolean first() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.first(); + } + + @Override + public boolean last() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.last(); + } + + @Override + public int getRow() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.getRow(); + } + + @Override + public boolean absolute(int row) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.absolute(row); + } + + @Override + public boolean relative(int rows) throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.relative(rows); + } + + @Override + public boolean previous() throws SQLException { + if (originalResultSet == null) { + throw new SQLException("No original result set is injected"); + } + return this.originalResultSet.previous(); + } + + @Override + public void setFetchDirection(int direction) throws SQLException { + this.originalResultSet.setFetchDirection(direction); + } + + @Override + public int getFetchDirection() throws SQLException { + return this.originalResultSet.getFetchDirection(); + } + + @Override + public void setFetchSize(int rows) throws SQLException { + this.originalResultSet.setFetchSize(rows); + } + + @Override + public int getFetchSize() throws SQLException { + return this.originalResultSet.getFetchSize(); + } + + @Override + public int getType() throws SQLException { + return this.originalResultSet.getType(); + } + + @Override + public int getConcurrency() throws SQLException { + return this.originalResultSet.getConcurrency(); + } + + @Override + public boolean rowUpdated() throws SQLException { + return this.originalResultSet.rowUpdated(); + } + + @Override + public boolean rowInserted() throws SQLException { + return this.originalResultSet.rowInserted(); + } + + @Override + public boolean rowDeleted() throws SQLException { + return this.originalResultSet.rowDeleted(); + } + + @Override + public void updateNull(int columnIndex) throws SQLException { + this.originalResultSet.updateNull(columnIndex); + } + + @Override + public void updateBoolean(int columnIndex, boolean x) throws SQLException { + this.originalResultSet.updateBoolean(columnIndex, x); + } + + @Override + public void updateByte(int columnIndex, byte x) throws SQLException { + this.originalResultSet.updateByte(columnIndex, x); + } + + @Override + public void updateShort(int columnIndex, short x) throws SQLException { + this.originalResultSet.updateShort(columnIndex, x); + } + + @Override + public void updateInt(int columnIndex, int x) throws SQLException { + this.originalResultSet.updateInt(columnIndex, x); + } + + @Override + public void updateLong(int columnIndex, long x) throws SQLException { + this.originalResultSet.updateLong(columnIndex, x); + } + + @Override + public void updateFloat(int columnIndex, float x) throws SQLException { + this.originalResultSet.updateFloat(columnIndex, x); + } + + @Override + public void updateDouble(int columnIndex, double x) throws SQLException { + this.originalResultSet.updateDouble(columnIndex, x); + } + + @Override + public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { + this.originalResultSet.updateBigDecimal(columnIndex, x); + } + + @Override + public void updateString(int columnIndex, String x) throws SQLException { + this.originalResultSet.updateString(columnIndex, x); + } + + @Override + public void updateBytes(int columnIndex, byte[] x) throws SQLException { + this.originalResultSet.updateBytes(columnIndex, x); + } + + @Override + public void updateDate(int columnIndex, Date x) throws SQLException { + this.originalResultSet.updateDate(columnIndex, x); + } + + @Override + public void updateTime(int columnIndex, Time x) throws SQLException { + this.originalResultSet.updateTime(columnIndex, x); + } + + @Override + public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { + this.originalResultSet.updateTimestamp(columnIndex, x); + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { + this.originalResultSet.updateAsciiStream(columnIndex, x, length); + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { + this.originalResultSet.updateBinaryStream(columnIndex, x, length); + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { + this.originalResultSet.updateCharacterStream(columnIndex, x, length); + } + + @Override + public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { + this.originalResultSet.updateObject(columnIndex, x, scaleOrLength); + } + + @Override + public void updateObject(int columnIndex, Object x) throws SQLException { + this.originalResultSet.updateObject(columnIndex, x); + } + + @Override + public void updateNull(String columnLabel) throws SQLException { + this.originalResultSet.updateNull(columnLabel); + } + + @Override + public void updateBoolean(String columnLabel, boolean x) throws SQLException { + this.originalResultSet.updateBoolean(columnLabel, x); + } + + @Override + public void updateByte(String columnLabel, byte x) throws SQLException { + this.originalResultSet.updateByte(columnLabel, x); + } + + @Override + public void updateShort(String columnLabel, short x) throws SQLException { + this.originalResultSet.updateShort(columnLabel, x); + } + + @Override + public void updateInt(String columnLabel, int x) throws SQLException { + this.originalResultSet.updateInt(columnLabel, x); + } + + @Override + public void updateLong(String columnLabel, long x) throws SQLException { + this.originalResultSet.updateLong(columnLabel, x); + } + + @Override + public void updateFloat(String columnLabel, float x) throws SQLException { + this.originalResultSet.updateFloat(columnLabel, x); + } + + @Override + public void updateDouble(String columnLabel, double x) throws SQLException { + this.originalResultSet.updateDouble(columnLabel, x); + } + + @Override + public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { + this.originalResultSet.updateBigDecimal(columnLabel, x); + } + + @Override + public void updateString(String columnLabel, String x) throws SQLException { + this.originalResultSet.updateString(columnLabel, x); + } + + @Override + public void updateBytes(String columnLabel, byte[] x) throws SQLException { + this.originalResultSet.updateBytes(columnLabel, x); + } + + @Override + public void updateDate(String columnLabel, Date x) throws SQLException { + this.originalResultSet.updateDate(columnLabel, x); + } + + @Override + public void updateTime(String columnLabel, Time x) throws SQLException { + this.originalResultSet.updateTime(columnLabel, x); + } + + @Override + public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { + this.originalResultSet.updateTimestamp(columnLabel, x); + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { + this.originalResultSet.updateAsciiStream(columnLabel, x, length); + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { + this.originalResultSet.updateBinaryStream(columnLabel, x, length); + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { + this.originalResultSet.updateCharacterStream(columnLabel, reader, length); + } + + @Override + public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { + this.originalResultSet.updateObject(columnLabel, x, scaleOrLength); + } + + @Override + public void updateObject(String columnLabel, Object x) throws SQLException { + this.originalResultSet.updateObject(columnLabel, x); + } + + @Override + public void insertRow() throws SQLException { + this.originalResultSet.insertRow(); + } + + @Override + public void updateRow() throws SQLException { + this.originalResultSet.updateRow(); + } + + @Override + public void deleteRow() throws SQLException { + this.originalResultSet.deleteRow(); + } + + @Override + public void refreshRow() throws SQLException { + this.originalResultSet.refreshRow(); + } + + @Override + public void cancelRowUpdates() throws SQLException { + this.originalResultSet.cancelRowUpdates(); + } + + @Override + public void moveToInsertRow() throws SQLException { + this.originalResultSet.moveToInsertRow(); + } + + @Override + public void moveToCurrentRow() throws SQLException { + this.originalResultSet.moveToCurrentRow(); + } + + @Override + public Statement getStatement() throws SQLException { + return this.originalResultSet.getStatement(); + } + + @Override + public Object getObject(int columnIndex, Map> map) throws SQLException { + return this.originalResultSet.getObject(columnIndex, map); + } + + @Override + public Ref getRef(int columnIndex) throws SQLException { + return this.originalResultSet.getRef(columnIndex); + } + + @Override + public Blob getBlob(int columnIndex) throws SQLException { + return this.originalResultSet.getBlob(columnIndex); + } + + @Override + public Clob getClob(int columnIndex) throws SQLException { + return this.originalResultSet.getClob(columnIndex); + } + + @Override + public Array getArray(int columnIndex) throws SQLException { + return this.originalResultSet.getArray(columnIndex); + } + + @Override + public Object getObject(String columnLabel, Map> map) throws SQLException { + return this.originalResultSet.getObject(columnLabel, map); + } + + @Override + public Ref getRef(String columnLabel) throws SQLException { + return this.originalResultSet.getRef(columnLabel); + } + + @Override + public Blob getBlob(String columnLabel) throws SQLException { + return this.originalResultSet.getBlob(columnLabel); + } + + @Override + public Clob getClob(String columnLabel) throws SQLException { + return this.originalResultSet.getClob(columnLabel); + } + + @Override + public Array getArray(String columnLabel) throws SQLException { + return this.originalResultSet.getArray(columnLabel); + } + + @Override + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + return this.originalResultSet.getDate(columnIndex, cal); + } + + @Override + public Date getDate(String columnLabel, Calendar cal) throws SQLException { + return this.originalResultSet.getDate(columnLabel, cal); + } + + @Override + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + return this.originalResultSet.getTime(columnIndex, cal); + } + + @Override + public Time getTime(String columnLabel, Calendar cal) throws SQLException { + return this.originalResultSet.getTime(columnLabel, cal); + } + + @Override + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + return this.originalResultSet.getTimestamp(columnIndex, cal); + } + + @Override + public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { + return this.originalResultSet.getTimestamp(columnLabel, cal); + } + + @Override + public URL getURL(int columnIndex) throws SQLException { + return this.originalResultSet.getURL(columnIndex); + } + + @Override + public URL getURL(String columnLabel) throws SQLException { + return this.originalResultSet.getURL(columnLabel); + } + + @Override + public void updateRef(int columnIndex, Ref x) throws SQLException { + this.originalResultSet.updateRef(columnIndex, x); + } + + @Override + public void updateRef(String columnLabel, Ref x) throws SQLException { + this.originalResultSet.updateRef(columnLabel, x); + } + + @Override + public void updateBlob(int columnIndex, Blob x) throws SQLException { + this.originalResultSet.updateBlob(columnIndex, x); + } + + @Override + public void updateBlob(String columnLabel, Blob x) throws SQLException { + this.originalResultSet.updateBlob(columnLabel, x); + } + + @Override + public void updateClob(int columnIndex, Clob x) throws SQLException { + this.originalResultSet.updateClob(columnIndex, x); + } + + @Override + public void updateClob(String columnLabel, Clob x) throws SQLException { + this.originalResultSet.updateClob(columnLabel, x); + } + + @Override + public void updateArray(int columnIndex, Array x) throws SQLException { + this.originalResultSet.updateArray(columnIndex, x); + } + + @Override + public void updateArray(String columnLabel, Array x) throws SQLException { + this.originalResultSet.updateArray(columnLabel, x); + } + + @Override + public RowId getRowId(int columnIndex) throws SQLException { + return this.originalResultSet.getRowId(columnIndex); + } + + @Override + public RowId getRowId(String columnLabel) throws SQLException { + return this.originalResultSet.getRowId(columnLabel); + } + + @Override + public void updateRowId(int columnIndex, RowId x) throws SQLException { + this.originalResultSet.updateRowId(columnIndex, x); + } + + @Override + public void updateRowId(String columnLabel, RowId x) throws SQLException { + this.originalResultSet.updateRowId(columnLabel, x); + } + + @Override + public int getHoldability() throws SQLException { + return this.originalResultSet.getHoldability(); + } + + @Override + public boolean isClosed() throws SQLException { + return this.originalResultSet.isClosed(); + } + + @Override + public void updateNString(int columnIndex, String nString) throws SQLException { + this.originalResultSet.updateNString(columnIndex, nString); + } + + @Override + public void updateNString(String columnLabel, String nString) throws SQLException { + this.originalResultSet.updateNString(columnLabel, nString); + } + + @Override + public void updateNClob(int columnIndex, NClob nClob) throws SQLException { + this.originalResultSet.updateNClob(columnIndex, nClob); + } + + @Override + public void updateNClob(String columnLabel, NClob nClob) throws SQLException { + this.originalResultSet.updateNClob(columnLabel, nClob); + } + + @Override + public NClob getNClob(int columnIndex) throws SQLException { + return this.originalResultSet.getNClob(columnIndex); + } + + @Override + public NClob getNClob(String columnLabel) throws SQLException { + return this.originalResultSet.getNClob(columnLabel); + } + + @Override + public SQLXML getSQLXML(int columnIndex) throws SQLException { + return this.originalResultSet.getSQLXML(columnIndex); + } + + @Override + public SQLXML getSQLXML(String columnLabel) throws SQLException { + return this.originalResultSet.getSQLXML(columnLabel); + } + + @Override + public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { + this.originalResultSet.updateSQLXML(columnIndex, xmlObject); + } + + @Override + public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { + this.originalResultSet.updateSQLXML(columnLabel, xmlObject); + } + + @Override + public String getNString(int columnIndex) throws SQLException { + return this.originalResultSet.getNString(columnIndex); + } + + @Override + public String getNString(String columnLabel) throws SQLException { + return this.originalResultSet.getNString(columnLabel); + } + + @Override + public Reader getNCharacterStream(int columnIndex) throws SQLException { + return this.originalResultSet.getNCharacterStream(columnIndex); + } + + @Override + public Reader getNCharacterStream(String columnLabel) throws SQLException { + return this.originalResultSet.getNCharacterStream(columnLabel); + } + + @Override + public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + this.originalResultSet.updateNCharacterStream(columnIndex, x, length); + } + + @Override + public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + this.originalResultSet.updateNCharacterStream(columnLabel, reader, length); + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { + this.originalResultSet.updateAsciiStream(columnIndex, x, length); + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { + this.originalResultSet.updateBinaryStream(columnIndex, x, length); + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + this.originalResultSet.updateCharacterStream(columnIndex, x, length); + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { + this.originalResultSet.updateAsciiStream(columnLabel, x, length); + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { + this.originalResultSet.updateBinaryStream(columnLabel, x, length); + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + this.originalResultSet.updateCharacterStream(columnLabel, reader, length); + } + + @Override + public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { + this.originalResultSet.updateBlob(columnIndex, inputStream, length); + } + + @Override + public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { + this.originalResultSet.updateBlob(columnLabel, inputStream, length); + } + + @Override + public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { + this.originalResultSet.updateClob(columnIndex, reader, length); + } + + @Override + public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { + this.originalResultSet.updateClob(columnLabel, reader, length); + } + + @Override + public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { + this.originalResultSet.updateNClob(columnIndex, reader, length); + } + + @Override + public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { + this.originalResultSet.updateNClob(columnLabel, reader, length); + } + + @Override + public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { + this.originalResultSet.updateNCharacterStream(columnIndex, x); + } + + @Override + public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { + this.originalResultSet.updateNCharacterStream(columnLabel, reader); + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { + this.originalResultSet.updateAsciiStream(columnIndex, x); + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { + this.originalResultSet.updateBinaryStream(columnIndex, x); + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { + this.originalResultSet.updateCharacterStream(columnIndex, x); + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { + this.originalResultSet.updateAsciiStream(columnLabel, x); + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { + this.originalResultSet.updateBinaryStream(columnLabel, x); + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { + this.originalResultSet.updateCharacterStream(columnLabel, reader); + } + + @Override + public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { + this.originalResultSet.updateBlob(columnIndex, inputStream); + } + + @Override + public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { + this.originalResultSet.updateBlob(columnLabel, inputStream); + } + + @Override + public void updateClob(int columnIndex, Reader reader) throws SQLException { + this.originalResultSet.updateClob(columnIndex, reader); + } + + @Override + public void updateClob(String columnLabel, Reader reader) throws SQLException { + this.originalResultSet.updateClob(columnLabel, reader); + } + + @Override + public void updateNClob(int columnIndex, Reader reader) throws SQLException { + this.originalResultSet.updateNClob(columnIndex, reader); + } + + @Override + public void updateNClob(String columnLabel, Reader reader) throws SQLException { + this.originalResultSet.updateNClob(columnLabel, reader); + } + + public T getObject(int columnIndex, Class type) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public T getObject(String columnLabel, Class type) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + @Override + public T unwrap(Class iface) throws SQLException { + return this.originalResultSet.unwrap(iface); + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return this.originalResultSet.isWrapperFor(iface); + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement 2.java new file mode 100644 index 0000000000..455b73bb92 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement 2.java @@ -0,0 +1,294 @@ +/*************************************************************************** + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + *****************************************************************************/ +package com.taosdata.jdbc; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + +public class TSDBStatement implements Statement { + private TSDBJNIConnector connecter = null; + + /** To store batched commands */ + protected List batchedArgs; + + /** Timeout for a query */ + protected int queryTimeout = 0; + + /** + * Status of current statement + */ + private boolean isClosed = true; + + TSDBStatement(TSDBJNIConnector connecter) { + this.connecter = connecter; + this.isClosed = false; + } + + public T unwrap(Class iface) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public ResultSet executeQuery(String sql) throws SQLException { + if (isClosed) { + throw new SQLException("Invalid method call on a closed statement."); + } + this.connecter.executeQuery(sql); + + long resultSetPointer = this.connecter.getResultSet(); + + if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) { + return null; + } else { + return new TSDBResultSet(this.connecter, resultSetPointer); + } + } + + public int executeUpdate(String sql) throws SQLException { + if (isClosed) { + throw new SQLException("Invalid method call on a closed statement."); + } + int res = this.connecter.executeQuery(sql); + long resultSetPointer = this.connecter.getResultSet(); + + if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } else if (resultSetPointer != TSDBConstants.JNI_NULL_POINTER) { + this.connecter.freeResultSet(); + throw new SQLException("The executed SQL is not a DML or a DDL"); + } else { + return res; + } + } + + public String getErrorMsg() { + return this.connecter.getErrMsg(); + } + + public void close() throws SQLException { + if (!isClosed) { + if (!this.connecter.isResultsetClosed()) { + this.connecter.freeResultSet(); + } + isClosed = true; + } + } + + public int getMaxFieldSize() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setMaxFieldSize(int max) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getMaxRows() throws SQLException { + // always set maxRows to zero, meaning unlimitted rows in a resultSet + return 0; + } + + public void setMaxRows(int max) throws SQLException { + // always set maxRows to zero, meaning unlimitted rows in a resultSet + } + + public void setEscapeProcessing(boolean enable) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getQueryTimeout() throws SQLException { + return queryTimeout; + } + + public void setQueryTimeout(int seconds) throws SQLException { + this.queryTimeout = seconds; + } + + public void cancel() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public SQLWarning getWarnings() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void clearWarnings() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setCursorName(String name) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean execute(String sql) throws SQLException { + if (isClosed) { + throw new SQLException("Invalid method call on a closed statement."); + } + boolean res = true; + this.connecter.executeQuery(sql); + long resultSetPointer = this.connecter.getResultSet(); + + if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) { + // no result set is retrieved + res = false; + } + return res; + } + + public ResultSet getResultSet() throws SQLException { + if (isClosed) { + throw new SQLException("Invalid method call on a closed statement."); + } + long resultSetPointer = connecter.getResultSet(); + TSDBResultSet resSet = null; + if (resultSetPointer != TSDBConstants.JNI_NULL_POINTER) { + resSet = new TSDBResultSet(connecter, resultSetPointer); + } + return resSet; + } + + public int getUpdateCount() throws SQLException { + if (isClosed) { + throw new SQLException("Invalid method call on a closed statement."); + } + return this.connecter.getAffectedRows(); + } + + public boolean getMoreResults() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void setFetchDirection(int direction) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getFetchDirection() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + /* + * used by spark + */ + public void setFetchSize(int rows) throws SQLException { + } + + /* + * used by spark + */ + public int getFetchSize() throws SQLException { + return 4096; + } + + public int getResultSetConcurrency() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getResultSetType() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void addBatch(String sql) throws SQLException { + if (batchedArgs == null) { + batchedArgs = new ArrayList(); + } + batchedArgs.add(sql); + } + + public void clearBatch() throws SQLException { + batchedArgs.clear(); + } + + public int[] executeBatch() throws SQLException { + if (isClosed) { + throw new SQLException("Invalid method call on a closed statement."); + } + if (batchedArgs == null) { + throw new SQLException(TSDBConstants.WrapErrMsg("Batch is empty!")); + } else { + int[] res = new int[batchedArgs.size()]; + for (int i = 0; i < batchedArgs.size(); i++) { + res[i] = executeUpdate(batchedArgs.get(i)); + } + return res; + } + } + + public Connection getConnection() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean getMoreResults(int current) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public ResultSet getGeneratedKeys() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int executeUpdate(String sql, String[] columnNames) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean execute(String sql, int[] columnIndexes) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean execute(String sql, String[] columnNames) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public int getResultSetHoldability() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isClosed() throws SQLException { + return isClosed; + } + + public void setPoolable(boolean poolable) throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isPoolable() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public void closeOnCompletion() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } + + public boolean isCloseOnCompletion() throws SQLException { + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TaosGlobalConfig 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TaosGlobalConfig 2.java new file mode 100644 index 0000000000..171189763b --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TaosGlobalConfig 2.java @@ -0,0 +1,30 @@ +/*************************************************************************** + * 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; + +public class TaosGlobalConfig { + static String charset = ""; + + public static String getCharset() { + if (charset == null || charset.isEmpty()) { + charset = System.getProperty("file.encoding"); + } + return charset; + } + + public static void setCharset(String tsCharset) { + TaosGlobalConfig.charset = tsCharset; + } +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/bean/TSDBPreparedParam 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/bean/TSDBPreparedParam 2.java new file mode 100644 index 0000000000..ef78292de6 --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/bean/TSDBPreparedParam 2.java @@ -0,0 +1,62 @@ +package com.taosdata.jdbc.bean; + +import java.util.List; + +/** + * tdengine batch insert or import param object + */ +public class TSDBPreparedParam { + + /** + * tableName, if sTable Name is not null, and this is sub table name. + */ + private String tableName; + + /** + * sub middle param list + */ + private List middleParamList; + + /** + * value list + */ + private List valueList; + + public TSDBPreparedParam(String tableName) { + this.tableName = tableName; + } + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public List getMiddleParamList() { + return middleParamList; + } + + public void setMiddleParamList(List middleParamList) { + this.middleParamList = middleParamList; + } + + public void setMiddleParam(int parameterIndex, Object x) { + this.middleParamList.set(parameterIndex, x); + } + + public List getValueList() { + return valueList; + } + + public void setValueList(List valueList) { + this.valueList = valueList; + } + + + public void setValueParam(int parameterIndex, Object x) { + this.valueList.set(parameterIndex, x); + } + +} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator 2.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator 2.java new file mode 100644 index 0000000000..7e144cbe0f --- /dev/null +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator 2.java @@ -0,0 +1,45 @@ +/*************************************************************************** + * 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.utils; + +import com.taosdata.jdbc.TSDBConnection; +import com.taosdata.jdbc.TSDBJNIConnector; + +import java.sql.Connection; +import java.sql.SQLException; + +public class SqlSyntaxValidator { + + private TSDBConnection tsdbConnection; + public SqlSyntaxValidator(Connection 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; + } +} diff --git a/src/connector/jdbc/src/main/resources/META-INF/services/.java.sql 2.Driver.icloud b/src/connector/jdbc/src/main/resources/META-INF/services/.java.sql 2.Driver.icloud new file mode 100644 index 0000000000000000000000000000000000000000..a834ea1b5fe8d33b63527efc729d37fd67ad0520 GIT binary patch literal 166 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?4zf!K}oxM7`p|90emim!izF)FJ`dcmWx#8iG>OOLG#7IQV7sz2XuWz<`kv MLNl;KX&6-x0NpRpc; - pInfo->sourceIp = pConn->peerIp; - pInfo->sourcePort = pConn->peerPort; + pInfo->clientIp = pConn->peerIp; + pInfo->clientPort = pConn->peerPort; + pInfo->serverIp = pConn->destIp; strcpy(pInfo->user, pConn->user); } @@ -546,6 +548,7 @@ SRpcConn *rpcSetConnToServer(SRpcInfo *pRpc, SRpcIpSet ipSet) { char ipstr[20] = {0}; tinet_ntoa(ipstr, ipSet.ip[ipSet.index]); pConn = rpcOpenConn(pRpc, ipstr, ipSet.port); + pConn->destIp = ipSet.ip[ipSet.index]; } return pConn; @@ -772,11 +775,13 @@ static void *rpcProcessMsgFromPeer(void *msg, int msgLen, uint32_t ip, uint16_t static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) { SRpcInfo *pRpc = pConn->pRpc; + pHead = rpcDecompressRpcMsg(pHead); - int contLen = rpcContLenFromMsg(pHead->msgLen); - uint8_t *pCont = pHead->content; + int contLen = rpcContLenFromMsg(pHead->msgLen); + uint8_t *pCont = pHead->content; if ( rpcIsReq(pHead->msgType) ) { + pConn->destIp = pHead->destIp; taosTmrReset(rpcProcessProgressTimer, tsRpcTimer/2, pConn, pRpc->tmrCtrl, &pConn->pTimer); (*(pRpc->cfp))(pHead->msgType, pCont, contLen, pConn, 0); } else { @@ -886,6 +891,7 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) { pHead->tranId = pConn->tranId; pHead->sourceId = pConn->ownId; pHead->destId = pConn->peerId; + pHead->destIp = pConn->destIp; pHead->port = 0; pHead->uid = (uint32_t)((int64_t)pConn + (int64_t)getpid()); memcpy(pHead->user, pConn->user, tListLen(pHead->user)); diff --git a/tests/comparisonTest/cassandra/cassandratest/src/main/java/com/cassandra/test/CassandraTest 2.java b/tests/comparisonTest/cassandra/cassandratest/src/main/java/com/cassandra/test/CassandraTest 2.java new file mode 100644 index 0000000000..a3f72de13c --- /dev/null +++ b/tests/comparisonTest/cassandra/cassandratest/src/main/java/com/cassandra/test/CassandraTest 2.java @@ -0,0 +1,200 @@ +import com.datastax.oss.driver.api.core.CqlSession; +import com.datastax.oss.driver.api.core.cql.*; +import com.datastax.oss.driver.api.core.session.*; +import com.datastax.oss.driver.api.core.config.*; +import com.datastax.oss.driver.api.core.cql.ResultSet; +import com.datastax.oss.driver.api.core.cql.Row; +//import com.datastax.driver.core.Cluster; +//import com.datastax.driver.core.Cluster; + +import java.io.BufferedWriter; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.FileReader; +import java.io.IOException; +import java.text.DecimalFormat; +import java.util.Random; +import java.math.*; +import java.lang.reflect.Method; + + +public class CassandraTest{ + + public static void main(String args[]) { + + + // begin to parse argument + String datadir = "/home/ubuntu/testdata"; + String sqlfile = "/home/ubuntu/fang/cassandra/q1.txt"; + String cfgfile = "/home/ubuntu/fang/cassandra/application.conf"; + boolean q4flag = false; + int numOfRows = 1000000; + int numOfFiles =0; + int numOfClients =0; + int rowsPerRequest =0; + for (int i = 0; i < args.length; ++i) { + if (args[i].equalsIgnoreCase("-dataDir")) { + if (i < args.length - 1) { + datadir = args[++i]; + } + } else if (args[i].equalsIgnoreCase("-numofFiles")) { + if (i < args.length - 1) { + numOfFiles = Integer.parseInt(args[++i]); + } + } else if (args[i].equalsIgnoreCase("-rowsPerRequest")) { + if (i < args.length - 1) { + rowsPerRequest = Integer.parseInt(args[++i]); + } + } else if (args[i].equalsIgnoreCase("-writeClients")) { + if (i < args.length - 1) { + numOfClients = Integer.parseInt(args[++i]); + } + } else if (args[i].equalsIgnoreCase("-sql")) { + sqlfile = args[++i]; + } else if (args[i].equalsIgnoreCase("-timetest")) { + q4flag = true; + } else if (args[i].equalsIgnoreCase("-conf")) { + cfgfile = args[++i]; + } + } + // file below to make sure no timeout error + File confile = new File(cfgfile); + + System.out.println("parameters\n"); + + if (numOfFiles >0) { + // write data + System.out.printf("----dataDir:%s\n", datadir); + System.out.printf("----numOfFiles:%d\n", numOfFiles); + System.out.printf("----numOfClients:%d\n", numOfClients); + System.out.printf("----rowsPerRequest:%d\n", rowsPerRequest); + + // connect to cassandra server + System.out.printf("----connecting to cassandra server\n"); + try { + CqlSession session = CqlSession.builder() + .withConfigLoader(DriverConfigLoader.fromFile(confile)) + .build(); + + session.execute("drop keyspace if exists cassandra"); + session.execute("CREATE KEYSPACE if not exists cassandra WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}"); + if (q4flag) { + session.execute("create table if not exists cassandra.test (devid int, devname text, devgroup int, ts bigint, minute bigint, temperature int, humidity float ,primary key (minute,ts,devgroup,devid,devname))"); + } else { + session.execute("create table if not exists cassandra.test (devid int, devname text, devgroup int, ts bigint, temperature int, humidity float ,primary key (devgroup,devid,devname,ts))"); + } + session.close(); + System.out.printf("----created keyspace cassandra and table test\n"); + + // begin to insert data + System.out.printf("----begin to insert data\n"); + long startTime = System.currentTimeMillis(); + int a = numOfFiles/numOfClients; + int b = numOfFiles%numOfClients; + int last = 0; + + WriteThread[] writethreads = new WriteThread[numOfClients]; + int[] wargs = new int[2]; // data file start, end + wargs[0] = numOfRows; //rows to be read from each file + wargs[1] = rowsPerRequest; + int fstart =0; + int fend =0; + for (int i = 0; i10) { + long startTime = System.currentTimeMillis(); + // begin to query one line command // + // end querying one line command + try { + + ResultSet results = session.execute(line); + long icounter = 0; + for (Row row : results) { + icounter++; + } + + long stopTime = System.currentTimeMillis(); + float elapseTime = stopTime - startTime; + elapseTime = elapseTime/1000; + System.out.printf("----spend %f seconds to query: %s\n", elapseTime, line); + } catch (Exception ex) { + ex.printStackTrace(); + System.out.printf("---- query failed!\n"); + System.exit(1); + } + + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + session.close(); + } + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + System.out.println("query end:----\n"); + } + } // end write or query + System.exit(0); + }// end main +}// end class diff --git a/tests/comparisonTest/cassandra/cassandratest/src/main/java/com/cassandra/test/WriteThread 2.java b/tests/comparisonTest/cassandra/cassandratest/src/main/java/com/cassandra/test/WriteThread 2.java new file mode 100644 index 0000000000..7d8679a303 --- /dev/null +++ b/tests/comparisonTest/cassandra/cassandratest/src/main/java/com/cassandra/test/WriteThread 2.java @@ -0,0 +1,99 @@ +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.math.*; + +import com.datastax.oss.driver.api.core.CqlSession; +import com.datastax.oss.driver.api.core.cql.*; +import com.datastax.oss.driver.api.core.session.*; +import com.datastax.oss.driver.api.core.config.*; + + +public class WriteThread extends Thread { + + private int[] wargs; // fstart, fend, rows to be read, rows perrequest + private String fdir; + private int fstart; + private int fend; + private boolean q4flag; + + public WriteThread (int fstart, int fend,int[] wargs, String fdir, boolean q4flag) { + this.fstart = fstart; + this.fend = fend; + this.fdir = fdir; + this.wargs = wargs; + this.q4flag = q4flag; + } + + // begin to insert in this thread + public void run() { + /* + // this configuration file makes sure no timeout error + File confile = new File("/home/ubuntu/fang/cassandra/application.conf"); + */ + // connect to server + try { + CqlSession session = CqlSession.builder() + //.withConfigLoader(DriverConfigLoader.fromFile(confile)) + .build(); + //session.execute("use cassandra"); + int tominute = 6000; + for (int i=fstart; i<=fend; i++) { + String csvfile; + csvfile = fdir + "/testdata"+ Integer.toString(i)+".csv"; + BufferedReader br = null; + String line = ""; + String cvsSplitBy = " "; + try { + br = new BufferedReader(new FileReader(csvfile)); + System.out.println("---- begin to read file " +csvfile+"\n"); + for (int itotalrow =0; itotalrow0) { + // write data + System.out.printf("----dataDir:%s\n", datadir); + System.out.printf("----numOfFiles:%d\n", numOfFiles); + System.out.printf("----numOfClients:%d\n", numOfClients); + System.out.printf("----rowsPerRequest:%d\n", rowsPerRequest); + try { + // begin to insert data + System.out.printf("----begin to insert data\n"); + long startTime = System.currentTimeMillis(); + int a = numOfFiles/numOfClients; + int b = numOfFiles%numOfClients; + int last = 0; + + WriteThread[] writethreads = new WriteThread[numOfClients]; + int[] wargs = new int[2]; // data file start, end + wargs[0] = numOfRows; //rows to be read from each file + wargs[1] = rowsPerRequest; + int fstart =0; + int fend =0; + for (int i = 0; ir3IGGQD_{Ts literal 0 HcmV?d00001 diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/TSDBSyncSample 2.java b/tests/examples/JDBC/JDBCDemo/src/main/java/TSDBSyncSample 2.java new file mode 100644 index 0000000000..c093b604da --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/TSDBSyncSample 2.java @@ -0,0 +1,205 @@ +import java.sql.*; + +public class TSDBSyncSample { + private static final String JDBC_PROTOCAL = "jdbc:TAOS://"; + private static final String TSDB_DRIVER = "com.taosdata.jdbc.TSDBDriver"; + + private String host = "127.0.0.1"; + private String user = "root"; + private String password = "taosdata"; + private int port = 0; + private String jdbcUrl = ""; + + private String databaseName = "db"; + private String metricsName = "mt"; + private String tablePrefix = "t"; + + private int tablesCount = 1; + private int loopCount = 2; + private int batchSize = 10; + private long beginTimestamp = 1519833600000L; + + private long rowsInserted = 0; + + static { + try { + Class.forName(TSDB_DRIVER); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * @param args + */ + public static void main(String[] args) { + TSDBSyncSample tester = new TSDBSyncSample(); + tester.doReadArgument(args); + + System.out.println("---------------------------------------------------------------"); + System.out.println("Start testing..."); + System.out.println("---------------------------------------------------------------"); + + tester.doMakeJdbcUrl(); + tester.doCreateDbAndTable(); + tester.doExecuteInsert(); + tester.doExecuteQuery(); + + System.out.println("\n---------------------------------------------------------------"); + System.out.println("Stop testing..."); + System.out.println("---------------------------------------------------------------"); + } + + private void doReadArgument(String[] args) { + System.out.println("Arguments format: host tables loop batchs"); + if (args.length >= 1) { + this.host = args[0]; + } + + if (args.length >= 2) { + this.tablesCount = Integer.parseInt(args[1]); + } + + if (args.length >= 3) { + this.loopCount = Integer.parseInt(args[2]); + } + + if (args.length >= 4) { + this.batchSize = Integer.parseInt(args[3]); + } + } + + private void doMakeJdbcUrl() { + // jdbc:TSDB://127.0.0.1:0/dbname?user=root&password=taosdata + System.out.println("\nJDBC URL to use:"); + this.jdbcUrl = String.format("%s%s:%d/%s?user=%s&password=%s", JDBC_PROTOCAL, this.host, this.port, "", + this.user, this.password); + System.out.println(this.jdbcUrl); + } + + private void doCreateDbAndTable() { + System.out.println("\n---------------------------------------------------------------"); + System.out.println("Start creating databases and tables..."); + String sql = ""; + try (Connection conn = DriverManager.getConnection(jdbcUrl); + Statement stmt = conn.createStatement()){ + + sql = "create database if not exists " + this.databaseName; + stmt.executeUpdate(sql); + System.out.printf("Successfully executed: %s\n", sql); + + sql = "use " + this.databaseName; + stmt.executeUpdate(sql); + System.out.printf("Successfully executed: %s\n", sql); + + sql = "create table if not exists " + this.metricsName + " (ts timestamp, v1 int) tags(t1 int)"; + stmt.executeUpdate(sql); + System.out.printf("Successfully executed: %s\n", sql); + + for (int i = 0; i < this.tablesCount; i++) { + sql = String.format("create table if not exists %s%d using %s tags(%d)", this.tablePrefix, i, + this.metricsName, i); + stmt.executeUpdate(sql); + System.out.printf("Successfully executed: %s\n", sql); + } + } catch (SQLException e) { + e.printStackTrace(); + System.out.printf("Failed to execute SQL: %s\n", sql); + System.exit(4); + } catch (Exception e) { + e.printStackTrace(); + System.exit(4); + } + System.out.println("Successfully created databases and tables"); + } + + public void doExecuteInsert() { + System.out.println("\n---------------------------------------------------------------"); + System.out.println("Start inserting data..."); + int start = (int) System.currentTimeMillis(); + StringBuilder sql = new StringBuilder(""); + try (Connection conn = DriverManager.getConnection(jdbcUrl); + Statement stmt = conn.createStatement()){ + stmt.executeUpdate("use " + databaseName); + for (int loop = 0; loop < this.loopCount; loop++) { + for (int table = 0; table < this.tablesCount; ++table) { + sql = new StringBuilder("insert into "); + sql.append(this.tablePrefix).append(table).append(" values"); + for (int batch = 0; batch < this.batchSize; ++batch) { + int rows = loop * this.batchSize + batch; + sql.append("(").append(this.beginTimestamp + rows).append(",").append(rows).append(")"); + } + int affectRows = stmt.executeUpdate(sql.toString()); + this.rowsInserted += affectRows; + } + } + } catch (SQLException e) { + e.printStackTrace(); + System.out.printf("Failed to execute SQL: %s\n", sql.toString()); + System.exit(4); + } catch (Exception e) { + e.printStackTrace(); + System.exit(4); + } + int end = (int) System.currentTimeMillis(); + System.out.println("Inserting completed!"); + System.out.printf("Total %d rows inserted, %d rows failed, time spend %d seconds.\n", this.rowsInserted, + this.loopCount * this.batchSize - this.rowsInserted, (end - start) / 1000); + } + + public void doExecuteQuery() { + System.out.println("\n---------------------------------------------------------------"); + System.out.println("Starting querying data..."); + ResultSet resSet = null; + StringBuilder sql = new StringBuilder(""); + StringBuilder resRow = new StringBuilder(""); + try (Connection conn = DriverManager.getConnection(jdbcUrl); + Statement stmt = conn.createStatement()){ + stmt.executeUpdate("use " + databaseName); + for (int i = 0; i < this.tablesCount; ++i) { + sql = new StringBuilder("select * from ").append(this.tablePrefix).append(i); + + resSet = stmt.executeQuery(sql.toString()); + if (resSet == null) { + System.out.println(sql + " failed"); + System.exit(4); + } + + ResultSetMetaData metaData = resSet.getMetaData(); + System.out.println("Retrieve metadata of " + tablePrefix + i); + for (int column = 1; column <= metaData.getColumnCount(); ++column) { + System.out.printf("Column%d: name = %s, type = %d, type name = %s, display size = %d\n", column, metaData.getColumnName(column), metaData.getColumnType(column), + metaData.getColumnTypeName(column), metaData.getColumnDisplaySize(column)); + } + int rows = 0; + System.out.println("Retrieve data of " + tablePrefix + i); + while (resSet.next()) { + resRow = new StringBuilder(); + for (int col = 1; col <= metaData.getColumnCount(); col++) { + resRow.append(metaData.getColumnName(col)).append("=").append(resSet.getObject(col)) + .append(" "); + } + System.out.println(resRow.toString()); + rows++; + } + + try { + if (resSet != null) + resSet.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + System.out.printf("Successfully executed query: %s;\nTotal rows returned: %d\n", sql.toString(), rows); + } + } catch (SQLException e) { + e.printStackTrace(); + System.out.printf("Failed to execute query: %s\n", sql.toString()); + System.exit(4); + } catch (Exception e) { + e.printStackTrace(); + System.exit(4); + } + System.out.println("Query completed!"); + } + +} diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/App 2.java b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/App 2.java new file mode 100644 index 0000000000..3230af46a8 --- /dev/null +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/java/com/taosdata/jdbc/App 2.java @@ -0,0 +1,44 @@ +package com.taosdata.jdbc; + + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.util.CollectionUtils; + +import java.util.List; +import java.util.Map; + +public class App { + + public static void main( String[] args ) { + + ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); + + JdbcTemplate jdbcTemplate = (JdbcTemplate) ctx.getBean("jdbcTemplate"); + + // create database + jdbcTemplate.execute("create database if not exists db "); + + // create table + jdbcTemplate.execute("create table if not exists db.tb (ts timestamp, temperature int, humidity float)"); + + String insertSql = "insert into db.tb values(now, 23, 10.3) (now + 1s, 20, 9.3)"; + + // insert rows + int affectedRows = jdbcTemplate.update(insertSql); + + System.out.println("insert success " + affectedRows + " rows."); + + // query for list + List> resultList = jdbcTemplate.queryForList("select * from db.tb"); + + if(!CollectionUtils.isEmpty(resultList)){ + for (Map row : resultList){ + System.out.printf("%s, %d, %s\n", row.get("ts"), row.get("temperature"), row.get("humidity")); + } + } + + } + +} diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext 2.xml b/tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext 2.xml new file mode 100644 index 0000000000..41128148ec --- /dev/null +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/main/resources/applicationContext 2.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + diff --git a/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/jdbc/AppTest 2.java b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/jdbc/AppTest 2.java new file mode 100644 index 0000000000..d6a699598e --- /dev/null +++ b/tests/examples/JDBC/SpringJdbcTemplate/src/test/java/com/taosdata/jdbc/AppTest 2.java @@ -0,0 +1,20 @@ +package com.taosdata.jdbc; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigorous Test :-) + */ + @Test + public void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplication 2.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplication 2.java new file mode 100644 index 0000000000..69cd3e0ced --- /dev/null +++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplication 2.java @@ -0,0 +1,15 @@ +package com.taosdata.jdbc.springbootdemo; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@MapperScan(basePackages = {"com.taosdata.jdbc.springbootdemo.dao"}) +@SpringBootApplication +public class SpringbootdemoApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringbootdemoApplication.class, args); + } + +} diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/controller/WeatherController 2.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/controller/WeatherController 2.java new file mode 100644 index 0000000000..9123abd97b --- /dev/null +++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/controller/WeatherController 2.java @@ -0,0 +1,60 @@ +package com.taosdata.jdbc.springbootdemo.controller; + +import com.taosdata.jdbc.springbootdemo.domain.Weather; +import com.taosdata.jdbc.springbootdemo.service.WeatherService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RequestMapping("/weather") +@RestController +public class WeatherController { + + @Autowired + private WeatherService weatherService; + + /** + * create database and table + * @return + */ + @GetMapping("/init") + public boolean init(){ + return weatherService.init(); + } + + /** + * Pagination Query + * @param limit + * @param offset + * @return + */ + @GetMapping("/{limit}/{offset}") + public List queryWeather(@PathVariable Long limit, @PathVariable Long offset){ + return weatherService.query(limit, offset); + } + + /** + * upload single weather info + * @param temperature + * @param humidity + * @return + */ + @PostMapping("/{temperature}/{humidity}") + public int saveWeather(@PathVariable int temperature, @PathVariable float humidity){ + + return weatherService.save(temperature, humidity); + } + + /** + * upload multi weather info + * @param weatherList + * @return + */ + @PostMapping("/batch") + public int batchSaveWeather(@RequestBody List weatherList){ + + return weatherService.save(weatherList); + } + +} diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/WeatherMapper 2.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/WeatherMapper 2.java new file mode 100644 index 0000000000..1e3db1f491 --- /dev/null +++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/dao/WeatherMapper 2.java @@ -0,0 +1,19 @@ +package com.taosdata.jdbc.springbootdemo.dao; + +import com.taosdata.jdbc.springbootdemo.domain.Weather; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface WeatherMapper { + + int insert(Weather weather); + + int batchInsert(List weatherList); + + List select(@Param("limit") Long limit, @Param("offset")Long offset); + + void createDB(); + + void createTable(); +} diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/Weather 2.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/Weather 2.java new file mode 100644 index 0000000000..9547a8a89b --- /dev/null +++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/domain/Weather 2.java @@ -0,0 +1,36 @@ +package com.taosdata.jdbc.springbootdemo.domain; + +import java.sql.Timestamp; + +public class Weather { + + private Timestamp ts; + + private int temperature; + + private float humidity; + + public Timestamp getTs() { + return ts; + } + + public void setTs(Timestamp ts) { + this.ts = ts; + } + + public int getTemperature() { + return temperature; + } + + public void setTemperature(int temperature) { + this.temperature = temperature; + } + + public float getHumidity() { + return humidity; + } + + public void setHumidity(float humidity) { + this.humidity = humidity; + } +} diff --git a/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/service/WeatherService 2.java b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/service/WeatherService 2.java new file mode 100644 index 0000000000..396d70bf92 --- /dev/null +++ b/tests/examples/JDBC/springbootdemo/src/main/java/com/taosdata/jdbc/springbootdemo/service/WeatherService 2.java @@ -0,0 +1,40 @@ +package com.taosdata.jdbc.springbootdemo.service; + +import com.taosdata.jdbc.springbootdemo.dao.WeatherMapper; +import com.taosdata.jdbc.springbootdemo.domain.Weather; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class WeatherService { + + @Autowired + private WeatherMapper weatherMapper; + + public boolean init() { + + weatherMapper.createDB(); + weatherMapper.createTable(); + + return true; + } + + public List query(Long limit, Long offset) { + return weatherMapper.select(limit, offset); + } + + public int save(int temperature, float humidity) { + Weather weather = new Weather(); + weather.setTemperature(temperature); + weather.setHumidity(humidity); + + return weatherMapper.insert(weather); + } + + public int save(List weatherList) { + return weatherMapper.batchInsert(weatherList); + } + +} diff --git a/tests/examples/JDBC/springbootdemo/src/main/resources/application 2.properties b/tests/examples/JDBC/springbootdemo/src/main/resources/application 2.properties new file mode 100644 index 0000000000..dc77e144f0 --- /dev/null +++ b/tests/examples/JDBC/springbootdemo/src/main/resources/application 2.properties @@ -0,0 +1,26 @@ +# datasource config +spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver +spring.datasource.url=jdbc:TAOS://127.0.0.1:6030/log +spring.datasource.username=root +spring.datasource.password=taosdata + +spring.datasource.druid.initial-size=5 +spring.datasource.druid.min-idle=5 +spring.datasource.druid.max-active=5 +# max wait time for get connection, ms +spring.datasource.druid.max-wait=60000 + +spring.datasource.druid.validation-query=describe log.dn +spring.datasource.druid.validation-query-timeout=5000 +spring.datasource.druid.test-on-borrow=false +spring.datasource.druid.test-on-return=false +spring.datasource.druid.test-while-idle=true +spring.datasource.druid.time-between-eviction-runs-millis=60000 +spring.datasource.druid.min-evictable-idle-time-millis=600000 +spring.datasource.druid.max-evictable-idle-time-millis=900000 + + +#mybatis +mybatis.mapper-locations=classpath:mapper/*.xml + +logging.level.com.taosdata.jdbc.springbootdemo.dao=debug \ No newline at end of file diff --git a/tests/examples/JDBC/springbootdemo/src/main/resources/mapper/WeatherMapper 2.xml b/tests/examples/JDBC/springbootdemo/src/main/resources/mapper/WeatherMapper 2.xml new file mode 100644 index 0000000000..e894f9a658 --- /dev/null +++ b/tests/examples/JDBC/springbootdemo/src/main/resources/mapper/WeatherMapper 2.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + create database if not exists test; + + + + create table if not exists test.weather(ts timestamp, temperature int, humidity float); + + + + ts, temperature, humidity + + + + + + insert into test.weather (ts, temperature, humidity) values (now, #{temperature,jdbcType=INTEGER}, #{humidity,jdbcType=FLOAT}) + + + + insert into test.weather (ts, temperature, humidity) values + + (now + #{index}a, #{weather.temperature}, #{weather.humidity}) + + + + + \ No newline at end of file diff --git a/tests/examples/JDBC/springbootdemo/src/test/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplicationTests 2.java b/tests/examples/JDBC/springbootdemo/src/test/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplicationTests 2.java new file mode 100644 index 0000000000..23a7420dab --- /dev/null +++ b/tests/examples/JDBC/springbootdemo/src/test/java/com/taosdata/jdbc/springbootdemo/SpringbootdemoApplicationTests 2.java @@ -0,0 +1,13 @@ +package com.taosdata.jdbc.springbootdemo; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SpringbootdemoApplicationTests { + + @Test + void contextLoads() { + } + +} -- GitLab