├── .github └── workflows │ └── build.yml ├── .gitignore ├── CHANGELOG.md ├── CMakeLists.txt ├── LICENSE ├── README-CN.md ├── README.md ├── cliff.toml ├── connection-type-en.webp ├── deploy-pom.xml ├── pom.xml └── src ├── main ├── assembly │ ├── assembly-jar.xml │ └── assembly.xml ├── java │ └── com │ │ └── taosdata │ │ └── jdbc │ │ ├── AbstractConnection.java │ │ ├── AbstractDatabaseMetaData.java │ │ ├── AbstractDriver.java │ │ ├── AbstractParameterMetaData.java │ │ ├── AbstractResultSet.java │ │ ├── AbstractStatement.java │ │ ├── BlockData.java │ │ ├── ColumnMetaData.java │ │ ├── DatabaseMetaDataResultSet.java │ │ ├── EmptyResultSet.java │ │ ├── SchemalessResp.java │ │ ├── SchemalessWriter.java │ │ ├── TSDBConnection.java │ │ ├── TSDBConstants.java │ │ ├── TSDBDatabaseMetaData.java │ │ ├── TSDBDriver.java │ │ ├── TSDBError.java │ │ ├── TSDBErrorNumbers.java │ │ ├── TSDBException.java │ │ ├── TSDBJNIConnector.java │ │ ├── TSDBParameterMetaData.java │ │ ├── TSDBPreparedStatement.java │ │ ├── TSDBResultSet.java │ │ ├── TSDBResultSetBlockData.java │ │ ├── TSDBResultSetMetaData.java │ │ ├── TSDBResultSetRowData.java │ │ ├── TSDBStatement.java │ │ ├── TableVGroupID.java │ │ ├── TaosGlobalConfig.java │ │ ├── TaosPrepareStatement.java │ │ ├── VGroupIDResp.java │ │ ├── WrapperImpl.java │ │ ├── common │ │ ├── AutoExpandingBuffer.java │ │ ├── Column.java │ │ ├── ColumnInfo.java │ │ ├── Consumer.java │ │ ├── ConsumerFactory.java │ │ ├── ConsumerManager.java │ │ ├── DataLengthCfg.java │ │ ├── SerializeBlock.java │ │ └── TableInfo.java │ │ ├── enums │ │ ├── BindType.java │ │ ├── ConnectionType.java │ │ ├── DataType.java │ │ ├── FieldBindType.java │ │ ├── SchemalessProtocolType.java │ │ ├── SchemalessTimestampType.java │ │ ├── TimestampPrecision.java │ │ ├── TmqMessageType.java │ │ └── WSFunction.java │ │ ├── rs │ │ ├── ConnectionParam.java │ │ ├── RestfulConnection.java │ │ ├── RestfulDatabaseMetaData.java │ │ ├── RestfulDriver.java │ │ ├── RestfulParameterMetaData.java │ │ ├── RestfulPreparedStatement.java │ │ ├── RestfulResultSet.java │ │ ├── RestfulResultSetMetaData.java │ │ └── RestfulStatement.java │ │ ├── tmq │ │ ├── Assignment.java │ │ ├── ConsumerRecord.java │ │ ├── ConsumerRecords.java │ │ ├── Deserializer.java │ │ ├── DeserializerException.java │ │ ├── JNIConsumer.java │ │ ├── JNIConsumerFactory.java │ │ ├── MapDeserializer.java │ │ ├── MapEnhanceDeserializer.java │ │ ├── OffsetAndMetadata.java │ │ ├── OffsetCommitCallback.java │ │ ├── OffsetWaitCallback.java │ │ ├── ReferenceDeserializer.java │ │ ├── TMQConnector.java │ │ ├── TMQConstants.java │ │ ├── TMQEnhMap.java │ │ ├── TMQResultSet.java │ │ ├── TaosConsumer.java │ │ └── TopicPartition.java │ │ ├── utils │ │ ├── CompletableFutureTimeout.java │ │ ├── DataTypeConverUtil.java │ │ ├── DateTimeUtils.java │ │ ├── DecimalUtil.java │ │ ├── HttpClientPoolUtil.java │ │ ├── JsonUtil.java │ │ ├── OSUtils.java │ │ ├── ReqId.java │ │ ├── SqlSyntaxValidator.java │ │ ├── StringUtils.java │ │ ├── SyncObj.java │ │ ├── TaosInfo.java │ │ ├── TaosInfoMBean.java │ │ ├── UInt64Deserializer.java │ │ ├── UInt64Serializer.java │ │ ├── UnsignedDataUtils.java │ │ └── Utils.java │ │ └── ws │ │ ├── AbsWSPreparedStatement.java │ │ ├── AbstractWSResultSet.java │ │ ├── BlockResultSet.java │ │ ├── CustomWebSocketClientHandshaker.java │ │ ├── CustomWebSocketFrameEncoder.java │ │ ├── FutureResponse.java │ │ ├── InFlightRequest.java │ │ ├── TSWSPreparedStatement.java │ │ ├── Transport.java │ │ ├── WSClient.java │ │ ├── WSConnection.java │ │ ├── WSEWPreparedStatement.java │ │ ├── WSParameterMetaData.java │ │ ├── WSRowPreparedStatement.java │ │ ├── WSStatement.java │ │ ├── WebSocketClientHandler.java │ │ ├── WebSocketDriver.java │ │ ├── WebSocketHandshakeHandler.java │ │ ├── WebsocketNotConnectedException.java │ │ ├── entity │ │ ├── Action.java │ │ ├── Code.java │ │ ├── CommonResp.java │ │ ├── ConnectReq.java │ │ ├── ConnectResp.java │ │ ├── FetchBlockNewResp.java │ │ ├── FetchReq.java │ │ ├── FetchResp.java │ │ ├── Payload.java │ │ ├── QueryReq.java │ │ ├── QueryResp.java │ │ ├── Request.java │ │ ├── RequestFactory.java │ │ └── Response.java │ │ ├── schemaless │ │ ├── ConnReq.java │ │ ├── InsertReq.java │ │ └── SchemalessAction.java │ │ ├── stmt2 │ │ └── entity │ │ │ ├── CloseReq.java │ │ │ ├── ExecReq.java │ │ │ ├── Field.java │ │ │ ├── InitReq.java │ │ │ ├── PrepareReq.java │ │ │ ├── RequestFactory.java │ │ │ ├── ResultReq.java │ │ │ ├── ResultResp.java │ │ │ ├── Stmt2ExecResp.java │ │ │ ├── Stmt2PrepareResp.java │ │ │ └── Stmt2Resp.java │ │ └── tmq │ │ ├── ConsumerAction.java │ │ ├── WSConsumer.java │ │ ├── WSConsumerFactory.java │ │ ├── WSConsumerResultSet.java │ │ ├── entity │ │ ├── AssignmentReq.java │ │ ├── AssignmentResp.java │ │ ├── CommitOffsetReq.java │ │ ├── CommitOffsetResp.java │ │ ├── CommitReq.java │ │ ├── CommitResp.java │ │ ├── CommittedReq.java │ │ ├── CommittedResp.java │ │ ├── ConsumerParam.java │ │ ├── FetchJsonMetaData.java │ │ ├── FetchJsonMetaReq.java │ │ ├── FetchJsonMetaResp.java │ │ ├── FetchRawBlockResp.java │ │ ├── FetchRawReq.java │ │ ├── FetchResp.java │ │ ├── ListTopicsReq.java │ │ ├── ListTopicsResp.java │ │ ├── PollReq.java │ │ ├── PollResp.java │ │ ├── PositionReq.java │ │ ├── PositionResp.java │ │ ├── SeekReq.java │ │ ├── SeekResp.java │ │ ├── SubscribeReq.java │ │ ├── SubscribeResp.java │ │ ├── TMQRequestFactory.java │ │ ├── UnsubscribeReq.java │ │ └── UnsubscribeResp.java │ │ └── meta │ │ ├── AlterType.java │ │ ├── AlterTypeDeserializer.java │ │ ├── ChildTableInfo.java │ │ ├── Column.java │ │ ├── Meta.java │ │ ├── MetaAlterTable.java │ │ ├── MetaCreateChildTable.java │ │ ├── MetaCreateNormalTable.java │ │ ├── MetaCreateSuperTable.java │ │ ├── MetaDeserializer.java │ │ ├── MetaDropSuperTable.java │ │ ├── MetaDropTable.java │ │ ├── MetaType.java │ │ ├── MetaTypeDeserializer.java │ │ ├── TableType.java │ │ ├── TableTypeDeserializer.java │ │ ├── Tag.java │ │ └── TagAlter.java └── resources │ ├── META-INF │ └── services │ │ ├── com.taosdata.jdbc.common.ConsumerFactory │ │ └── java.sql.Driver │ └── taos-jdbc-version.properties └── test ├── java └── com │ └── taosdata │ └── jdbc │ ├── AbstractConnectionTest.java │ ├── AbstractDatabaseMetaDataColumnTest.java │ ├── AbstractDatabaseMetaDataVesionTest.java │ ├── AbstractResultSetTest.java │ ├── DatabaseMetaDataResultSetTest.java │ ├── EmptyResultSetTest.java │ ├── GeometryTest.java │ ├── JsonTagTest.java │ ├── ParameterBindTest.java │ ├── SchemalessConnectionTest.java │ ├── SchemalessInsertNewTest.java │ ├── SchemalessInsertTest.java │ ├── SchemalessRawInsertNewTest.java │ ├── SchemalessRawInsertTest.java │ ├── SetConfigurationInJNITest.java │ ├── TSDBConnectionTest.java │ ├── TSDBDatabaseMetaDataTest.java │ ├── TSDBDriverTest.java │ ├── TSDBJNIConnectorTest.java │ ├── TSDBParameterMetaDataTest.java │ ├── TSDBPreparedStatementPerfTest.java │ ├── TSDBPreparedStatementTest.java │ ├── TSDBResultSetRowDataTest.java │ ├── TSDBResultSetTest.java │ ├── TSDBStatementTest.java │ ├── VarbinaryTest.java │ ├── WasNullTest.java │ ├── annotation │ ├── CatalogClass.java │ ├── CatalogListener.java │ ├── CatalogMethod.java │ ├── CatalogRunner.java │ ├── Description.java │ └── TestTarget.java │ ├── block │ ├── TSDBBlockJsonTagTest.java │ └── TSDBBlockResultSetTest.java │ ├── cases │ ├── AppMemoryLeakTest.java │ ├── AuthenticationTest.java │ ├── BatchErrorIgnoreTest.java │ ├── BatchInsertTest.java │ ├── ConnectMultiTaosdByRestfulWithDifferentTokenTest.java │ ├── ConnectWrongDatabaseTest.java │ ├── DatetimeBefore1970Test.java │ ├── DoubleQuoteInSqlTest.java │ ├── DriverAutoloadTest.java │ ├── FailOverTest.java │ ├── GetLongWithDifferentTimestampPrecision.java │ ├── GroupByFetchBlockJNITest.java │ ├── GroupByFetchBlockTest.java │ ├── ImportTest.java │ ├── InsertDbwithoutUseDbTest.java │ ├── InsertSpecialCharacterJniTest.java │ ├── InsertSpecialCharacterRestfulTest.java │ ├── InvalidResultSetPointerTest.java │ ├── JDBCTypeAndTypeCompareTest.java │ ├── MicroSecondPrecisionJNITest.java │ ├── MicroSecondPrecisionRestfulTest.java │ ├── MultiConnectionWithDifferentDbTest.java │ ├── NanoSecondTimestampJNITest.java │ ├── NanoSecondTimestampRestfulTest.java │ ├── NullValueInResultSetJNITest.java │ ├── NullValueInResultSetRestfulTest.java │ ├── NullValueInResultSetTest.java │ ├── PreparedStatementBatchInsertJNITest.java │ ├── PreparedStatementBatchInsertRestfulTest.java │ ├── QueryDataTest.java │ ├── QueryTimeoutTest.java │ ├── RawBlockBinaryLengthTest.java │ ├── ResetQueryCacheTest.java │ ├── ResultSetMetaShouldNotBeNullRestfulTest.java │ ├── SelectTest.java │ ├── StableTest.java │ ├── TimestampPrecisionInNanoInJniTest.java │ ├── TimestampPrecisionInNanoRestTest.java │ ├── UnsignedNumberJniTest.java │ ├── UnsignedNumberRestfulTest.java │ └── UseNowInsertTimestampTest.java │ ├── cloud │ ├── CloudSchemalessNewTest.java │ ├── CloudSchemalessTest.java │ ├── CloudTest.java │ └── ConsumerTest.java │ ├── common │ └── AutoExpandingBufferTest.java │ ├── confprops │ ├── BadLocaleSettingTest.java │ ├── BatchFetchTest.java │ ├── CharsetTest.java │ ├── HttpKeepAliveTest.java │ ├── TaosInfoMonitorTest.java │ ├── TimeZoneTest.java │ └── TimestampFormatTest.java │ ├── rs │ ├── DatabaseSpecifiedTest.java │ ├── RestfulCompressTest.java │ ├── RestfulConnectionParamTest.java │ ├── RestfulConnectionTest.java │ ├── RestfulDatabaseMetaDataTest.java │ ├── RestfulDriverTest.java │ ├── RestfulJDBCTest.java │ ├── RestfulJsonTagTest.java │ ├── RestfulParameterMetaDataTest.java │ ├── RestfulPreparedStatementTest.java │ ├── RestfulResponseCodeTest.java │ ├── RestfulResultSetMetaDataTest.java │ ├── RestfulResultSetTest.java │ ├── RestfulStatementTest.java │ ├── SQLTest.java │ └── WasNullTest.java │ ├── tmq │ ├── ConsumerCommitTest.java │ ├── ConsumerTopicTest.java │ ├── DeserializerNullTest.java │ ├── OffsetSeekTest.java │ ├── ResultBean.java │ ├── ResultDeserializer.java │ ├── TMQResultSetTest.java │ └── TaosConsumerTest.java │ ├── utils │ ├── DataTypeConverUtilTest.java │ ├── HttpClientPoolUtilTest.java │ ├── InsertSqlPatternTest.java │ ├── JsonUtilTest.java │ ├── OSUtilsTest.java │ ├── ReqIdTest.java │ ├── RuntimeUtils.java │ ├── SpecifyAddress.java │ ├── StringUtilsTest.java │ ├── TestUtils.java │ ├── TimestampUtil.java │ ├── UInt64SerializerTest.java │ └── UtilsTest.java │ └── ws │ ├── ConsumerCommittedTest.java │ ├── PrepareStatementBenchTest.java │ ├── PrepareStatementUseDBTest.java │ ├── SchemaConnectTest.java │ ├── TSWSPreparedStatementTest.java │ ├── TaosAdapterMock.java │ ├── WSAppInfoTest.java │ ├── WSBigQueryTest.java │ ├── WSCompressTest.java │ ├── WSConFailOverTest.java │ ├── WSConnectionTest.java │ ├── WSConsumerAutoCommitTest.java │ ├── WSConsumerMetaTest.java │ ├── WSConsumerNullTest.java │ ├── WSConsumerOffsetSeekTest.java │ ├── WSConsumerResultSetTest.java │ ├── WSConsumerSubscribeDBTest.java │ ├── WSConsumerTest.java │ ├── WSConsumerWithDiffTypeTest.java │ ├── WSDatabaseMetaDataTest.java │ ├── WSDriverBaseTest.java │ ├── WSGeometryTest.java │ ├── WSJsonTagTest.java │ ├── WSMasterSlaveTest.java │ ├── WSQueryBIModeTest.java │ ├── WSQueryTest.java │ ├── WSSchemalessNewTest.java │ ├── WSSchemalessTest.java │ ├── WSSelectTest.java │ ├── WSTimeZoneTest.java │ ├── WSVarbinaryTest.java │ ├── WebSocketDriverTest.java │ ├── stmt │ ├── WsEfficientWritingTest.java │ ├── WsPStmtAllTypeNullTest.java │ ├── WsPStmtLineModeNullTest.java │ ├── WsPstmtAllTypeTest.java │ ├── WsPstmtLineModeAllTypeTest.java │ ├── WsPstmtNsTest.java │ ├── WsPstmtStmt2Test.java │ ├── WsPstmtSubTableTest.java │ └── WsPstmtTest.java │ └── tmq │ └── entity │ └── TMQRequestFactoryTest.java └── resources ├── commons-logging.properties └── simplelog.properties /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - '3.0' 8 | paths-ignore: 9 | - 'LICENSE' 10 | - '*.md' 11 | - '*.txt' 12 | pull_request: 13 | branches: 14 | - main 15 | - '3.0' 16 | paths-ignore: 17 | - 'LICENSE' 18 | - '*.md' 19 | - '*.txt' 20 | 21 | jobs: 22 | build: 23 | strategy: 24 | matrix: 25 | # os: [ ubuntu-latest,macos-latest,windows-latest ] 26 | os: [ Ubuntu-22.04 ] 27 | java: [ 8 ] 28 | maven: [ '3.6.3' ] 29 | runs-on: ${{ matrix.os }} 30 | steps: 31 | - name: checkout TDengine 32 | uses: actions/checkout@v3 33 | with: 34 | repository: 'taosdata/TDengine' 35 | path: 'TDengine' 36 | ref: ${{ github.base_ref }} 37 | 38 | - name: prepare install 39 | run: | 40 | sudo apt-get install -y libgeos-dev 41 | geos-config --version 42 | 43 | - name: install TDengine 44 | run: cd TDengine && mkdir debug && cd debug && cmake .. -DBUILD_JDBC=false -DBUILD_TOOLS=false -DBUILD_HTTP=false -DBUILD_DEPENDENCY_TESTS=false && make && sudo make install 45 | 46 | - name: shell 47 | run: | 48 | cat >start.sh< 4 | 5 | dist 6 | 7 | jar 8 | 9 | false 10 | 11 | 12 | / 13 | true 14 | true 15 | runtime 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/main/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 4 | dist 5 | 6 | tar.gz 7 | 8 | 9 | 10 | true 11 | / 12 | 13 | 14 | 24 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ColumnMetaData.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc; 2 | 3 | public class ColumnMetaData { 4 | 5 | private int colType = 0; //taosType 6 | private String colName = null; 7 | private int colSize = -1; 8 | private int colIndex = 0; 9 | 10 | public int getColSize() { 11 | return colSize; 12 | } 13 | 14 | public void setColSize(int colSize) { 15 | this.colSize = colSize; 16 | } 17 | 18 | public int getColType() { 19 | return colType; 20 | } 21 | 22 | public void setColType(int colType) { 23 | this.colType = colType; 24 | } 25 | 26 | public String getColName() { 27 | return colName; 28 | } 29 | 30 | public void setColName(String colName) { 31 | this.colName = colName; 32 | } 33 | 34 | public int getColIndex() { 35 | return colIndex; 36 | } 37 | 38 | public void setColIndex(int colIndex) { 39 | this.colIndex = colIndex; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "ColumnMetaData{" + 45 | "colType=" + colType + 46 | ", colName='" + colName + '\'' + 47 | ", colSize=" + colSize + 48 | ", colIndex=" + colIndex + 49 | '}'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/SchemalessResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc; 2 | 3 | public class SchemalessResp { 4 | private int totalRows; 5 | private int code; 6 | private String msg; 7 | 8 | public int getTotalRows() { 9 | return totalRows; 10 | } 11 | 12 | public void setTotalRows(int totalRows) { 13 | this.totalRows = totalRows; 14 | } 15 | 16 | public int getCode() { 17 | return code; 18 | } 19 | 20 | public void setCode(int code) { 21 | this.code = code; 22 | } 23 | 24 | public String getMsg() { 25 | return msg; 26 | } 27 | 28 | public void setMsg(String msg) { 29 | this.msg = msg; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/TSDBException.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc; 2 | 3 | public class TSDBException { 4 | private int code; 5 | private String message; 6 | 7 | public int getCode() { 8 | return code; 9 | } 10 | 11 | public void setCode(int code) { 12 | this.code = code; 13 | } 14 | 15 | public String getMessage() { 16 | return message; 17 | } 18 | 19 | public void setMessage(String message) { 20 | this.message = message; 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/TSDBParameterMetaData.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc; 2 | 3 | public class TSDBParameterMetaData extends AbstractParameterMetaData { 4 | 5 | public TSDBParameterMetaData(Object[] parameters) { 6 | super(parameters); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/TableVGroupID.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | 6 | public class TableVGroupID { 7 | public TableVGroupID(Connection connection) throws SQLException { 8 | if (!(connection instanceof TSDBConnection)) { 9 | throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD, "only supported by TSDBConnection"); 10 | } 11 | 12 | this.connection = (TSDBConnection) connection; 13 | } 14 | 15 | private TableVGroupID() { 16 | } 17 | 18 | 19 | /** 20 | * getTableVgID. get table's v-group id. 21 | * 22 | * @param db db name 23 | * @param table table name 24 | * @return v-group id 25 | * @throws SQLException throws exception if fail. 26 | */ 27 | public int getTableVgID(String db, String table) throws SQLException { 28 | return this.connection.getConnector().getTableVGroupID(db, table); 29 | } 30 | 31 | private TSDBConnection connection; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/TaosGlobalConfig.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc; 2 | 3 | public class TaosGlobalConfig { 4 | static String charset = ""; 5 | 6 | public static String getCharset() { 7 | if (charset == null || charset.isEmpty()) { 8 | charset = System.getProperty("file.encoding"); 9 | } 10 | return charset; 11 | } 12 | 13 | public static void setCharset(String tsCharset) { 14 | TaosGlobalConfig.charset = tsCharset; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/TaosPrepareStatement.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc; 2 | 3 | import java.math.BigInteger; 4 | import java.sql.PreparedStatement; 5 | import java.sql.SQLException; 6 | import java.sql.Timestamp; 7 | import java.util.List; 8 | 9 | public interface TaosPrepareStatement extends PreparedStatement { 10 | 11 | void setTableName(String name) throws SQLException; 12 | 13 | void setTagNull(int index, int type) throws SQLException; 14 | 15 | void setTagBoolean(int index, boolean value); 16 | 17 | void setTagByte(int index, byte value); 18 | 19 | void setTagShort(int index, short value); 20 | 21 | void setTagInt(int index, int value); 22 | 23 | void setTagLong(int index, long value); 24 | 25 | void setTagBigInteger(int index, BigInteger value) throws SQLException; 26 | 27 | void setTagFloat(int index, float value); 28 | 29 | void setTagDouble(int index, double value); 30 | 31 | void setTagTimestamp(int index, long value); 32 | 33 | void setTagTimestamp(int index, Timestamp value); 34 | 35 | void setTagString(int index, String value); 36 | 37 | void setTagVarbinary(int index, byte[] value); 38 | void setTagGeometry(int index, byte[] value); 39 | 40 | void setTagNString(int index, String value); 41 | 42 | void setTagJson(int index, String value); 43 | void setInt(int columnIndex, List list) throws SQLException; 44 | void setFloat(int columnIndex, List list) throws SQLException; 45 | 46 | void setTimestamp(int columnIndex, List list) throws SQLException; 47 | 48 | void setLong(int columnIndex, List list) throws SQLException; 49 | void setBigInteger(int columnIndex, List list) throws SQLException; 50 | 51 | void setDouble(int columnIndex, List list) throws SQLException; 52 | 53 | void setBoolean(int columnIndex, List list) throws SQLException; 54 | 55 | void setByte(int columnIndex, List list) throws SQLException; 56 | 57 | void setShort(int columnIndex, List list) throws SQLException; 58 | 59 | void setString(int columnIndex, List list, int size) throws SQLException; 60 | 61 | void setVarbinary(int columnIndex, List list, int size) throws SQLException; 62 | void setGeometry(int columnIndex, List list, int size) throws SQLException; 63 | // note: expand the required space for each NChar character 64 | void setNString(int columnIndex, List list, int size) throws SQLException; 65 | 66 | void columnDataAddBatch() throws SQLException; 67 | 68 | void columnDataExecuteBatch() throws SQLException; 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/VGroupIDResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc; 2 | 3 | public class VGroupIDResp { 4 | private int code = 0; 5 | private int vgID = 0; 6 | 7 | public int getCode() { 8 | return code; 9 | } 10 | 11 | public void setCode(int code) { 12 | this.code = code; 13 | } 14 | 15 | public int getVgID() { 16 | return vgID; 17 | } 18 | 19 | public void setVgID(int vgID) { 20 | this.vgID = vgID; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/WrapperImpl.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc; 2 | 3 | import java.sql.SQLException; 4 | import java.sql.Wrapper; 5 | 6 | public class WrapperImpl implements Wrapper { 7 | 8 | @Override 9 | public T unwrap(Class iface) throws SQLException { 10 | try { 11 | return iface.cast(this); 12 | } catch (ClassCastException cce) { 13 | throw new SQLException("Unable to unwrap to " + iface.toString()); 14 | } 15 | } 16 | 17 | @Override 18 | public boolean isWrapperFor(Class iface) throws SQLException { 19 | return iface.isInstance(this); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/common/Column.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.common; 2 | 3 | public class Column { 4 | private final Object data; 5 | // taos data type 6 | private final int type; 7 | 8 | public Object getData() { 9 | return data; 10 | } 11 | 12 | public int getType() { 13 | return type; 14 | } 15 | 16 | public int getIndex() { 17 | return index; 18 | } 19 | 20 | private final int index; 21 | 22 | public Column(Object data, int type, int index) { 23 | this.data = data; 24 | this.type = type; 25 | this.index = index; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/common/ColumnInfo.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.common; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class ColumnInfo implements Comparable { 7 | private List dataList; 8 | // taos data type 9 | private final int type; 10 | private final int index; 11 | 12 | 13 | 14 | private int serializeSize; 15 | 16 | // public ColumnInfo(int columnIndex, Object data, int type) { 17 | // this.index = columnIndex; 18 | // this.dataList.add(data); 19 | // this.type = type; 20 | // } 21 | 22 | public ColumnInfo(int columnIndex, List dataList, int type) { 23 | this.index = columnIndex; 24 | this.dataList = dataList; 25 | this.type = type; 26 | } 27 | 28 | public void add(Object data) { 29 | this.dataList.add(data); 30 | } 31 | 32 | public List getDataList() { 33 | return dataList; 34 | } 35 | 36 | public int getType() { 37 | return type; 38 | } 39 | 40 | public int getIndex() { 41 | return index; 42 | } 43 | 44 | public int getSerializeSize() { 45 | return serializeSize; 46 | } 47 | 48 | public void setSerializeSize(int serializeSize) { 49 | this.serializeSize = serializeSize; 50 | } 51 | 52 | @Override 53 | public int compareTo(ColumnInfo c) { 54 | return this.index > c.index ? 1 : -1; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/common/ConsumerFactory.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.common; 2 | 3 | 4 | public interface ConsumerFactory { 5 | 6 | boolean acceptsType(String type); 7 | 8 | Consumer getConsumer(); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/common/DataLengthCfg.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.common; 2 | 3 | public class DataLengthCfg { 4 | private static final Integer[] dataLenArr = { 5 | 1,//TSDB_DATA_TYPE_NULL 6 | 1,//TSDB_DATA_TYPE_BOOL 7 | 1,//TSDB_DATA_TYPE_TINYINT 8 | 2,//TSDB_DATA_TYPE_SMALLINT 9 | 4,//TSDB_DATA_TYPE_INT 10 | 8,//TSDB_DATA_TYPE_BIGINT 11 | 4,//TSDB_DATA_TYPE_FLOAT 12 | 8,//TSDB_DATA_TYPE_DOUBLE 13 | null, 14 | 8, //TSDB_DATA_TYPE_TIMESTAMP 15 | null, 16 | 1, //TSDB_DATA_TYPE_UTINYINT 17 | 2, //TSDB_DATA_TYPE_USMALLINT 18 | 4, //TSDB_DATA_TYPE_UINT 19 | 8 //TSDB_DATA_TYPE_UBIGINT 20 | }; 21 | 22 | public static Integer getDataLength(int dataType){ 23 | if (dataType < dataLenArr.length){ 24 | return dataLenArr[dataType]; 25 | } 26 | return null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/common/TableInfo.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.common; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class TableInfo { 8 | private List dataList; 9 | private ByteBuffer tableName; 10 | private List tagInfo; 11 | 12 | public TableInfo(List dataList, ByteBuffer tableName, List tagInfo) { 13 | this.dataList = dataList; 14 | this.tableName = tableName; 15 | this.tagInfo = tagInfo; 16 | } 17 | 18 | public static TableInfo getEmptyTableInfo() { 19 | return new TableInfo(new ArrayList<>(), ByteBuffer.wrap(new byte[]{}), new ArrayList<>()); 20 | } 21 | public List getDataList() { 22 | return dataList; 23 | } 24 | 25 | public ByteBuffer getTableName() { 26 | return tableName; 27 | } 28 | 29 | public List getTagInfo() { 30 | return tagInfo; 31 | } 32 | 33 | public void setDataList(List dataList) { 34 | this.dataList = dataList; 35 | } 36 | 37 | public void setTableName(ByteBuffer tableName) { 38 | this.tableName = tableName; 39 | } 40 | 41 | public void setTagInfo(List tagInfo) { 42 | this.tagInfo = tagInfo; 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/enums/BindType.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.enums; 2 | 3 | public enum BindType { 4 | TAG(1), 5 | BIND(2), 6 | ; 7 | private final long length; 8 | 9 | BindType(int length) { 10 | this.length = length; 11 | } 12 | 13 | public long get() { 14 | return length; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/enums/ConnectionType.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.enums; 2 | 3 | public enum ConnectionType { 4 | // jni 5 | JNI("jni"), 6 | // http 7 | HTTP("http"), 8 | 9 | // websocket 10 | WS("ws"), 11 | WEBSOCKET("websocket"), 12 | ; 13 | 14 | final String type; 15 | 16 | ConnectionType(String type) { 17 | this.type = type; 18 | } 19 | 20 | public String getType() { 21 | return type; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/enums/FieldBindType.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.enums; 2 | 3 | public enum FieldBindType { 4 | TAOS_FIELD_COL(1), 5 | TAOS_FIELD_TAG(2), 6 | TAOS_FIELD_QUERY(3), 7 | TAOS_FIELD_TBNAME(4); 8 | 9 | private final int value; 10 | 11 | FieldBindType(int value) { 12 | this.value = value; 13 | } 14 | 15 | public int getValue() { 16 | return value; 17 | } 18 | 19 | public static FieldBindType fromValue(int value) { 20 | for (FieldBindType field : FieldBindType.values()) { 21 | if (field.value == value) { 22 | return field; 23 | } 24 | } 25 | throw new IllegalArgumentException("Unknown value: " + value); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/enums/SchemalessProtocolType.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.enums; 2 | 3 | import java.util.Arrays; 4 | 5 | public enum SchemalessProtocolType { 6 | UNKNOWN, 7 | LINE, 8 | TELNET, 9 | JSON, 10 | ; 11 | 12 | public static SchemalessProtocolType parse(String type) { 13 | return Arrays.stream(SchemalessProtocolType.values()) 14 | .filter(protocol -> type.equalsIgnoreCase(protocol.name())) 15 | .findFirst().orElse(UNKNOWN); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/enums/SchemalessTimestampType.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.enums; 2 | 3 | public enum SchemalessTimestampType { 4 | // Let the database decide 5 | NOT_CONFIGURED(""), 6 | HOURS("h"), 7 | MINUTES("m"), 8 | SECONDS("s"), 9 | MILLI_SECONDS("ms"), 10 | MICRO_SECONDS("u"), 11 | NANO_SECONDS("ns"), 12 | ; 13 | 14 | private String type; 15 | 16 | SchemalessTimestampType(String type) { 17 | this.type = type; 18 | } 19 | 20 | public String getType() { 21 | return type; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/enums/TimestampPrecision.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.enums; 2 | 3 | public class TimestampPrecision { 4 | public static final int MS = 0; 5 | public static final int US = 1; 6 | public static final int NS = 2; 7 | public static final int UNKNOWN = 9999; 8 | 9 | public static int getPrecision(String precision) { 10 | if (precision == null) 11 | return UNKNOWN; 12 | String trim = precision.trim(); 13 | switch (trim) { 14 | case "ms": 15 | return MS; 16 | case "us": 17 | return US; 18 | case "ns": 19 | return NS; 20 | default: 21 | return UNKNOWN; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/enums/TmqMessageType.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.enums; 2 | 3 | public enum TmqMessageType { 4 | TMQ_RES_INVALID(-1), 5 | 6 | TMQ_RES_DATA(1), 7 | 8 | TMQ_RES_TABLE_META(2), 9 | 10 | TMQ_RES_METADATA(3), 11 | ; 12 | 13 | final int code; 14 | 15 | TmqMessageType(int code) { 16 | this.code = code; 17 | } 18 | 19 | public int getCode() { 20 | return code; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/enums/WSFunction.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.enums; 2 | 3 | public enum WSFunction { 4 | // sql 5 | WS("ws"), 6 | // tmq 7 | TMQ("tmq"), 8 | //schemaless 9 | SCHEMALESS("schemaless");; 10 | 11 | final String function; 12 | 13 | WSFunction(String function) { 14 | this.function = function; 15 | } 16 | 17 | public String getFunction() { 18 | return function; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/rs/RestfulParameterMetaData.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.rs; 2 | 3 | import com.taosdata.jdbc.AbstractParameterMetaData; 4 | 5 | public class RestfulParameterMetaData extends AbstractParameterMetaData { 6 | 7 | RestfulParameterMetaData(Object[] parameters) { 8 | super(parameters); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/tmq/Assignment.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public class Assignment { 6 | @JsonProperty("vgroup_id") 7 | private int vgId; 8 | @JsonProperty("offset") 9 | private long currentOffset; 10 | private long begin; 11 | private long end; 12 | 13 | public Assignment() { 14 | } 15 | 16 | public Assignment(int vgId, long currentOffset, long begin, long end) { 17 | this.vgId = vgId; 18 | this.currentOffset = currentOffset; 19 | this.begin = begin; 20 | this.end = end; 21 | } 22 | 23 | public void setVgId(int vgId) { 24 | this.vgId = vgId; 25 | } 26 | 27 | public void setCurrentOffset(long currentOffset) { 28 | this.currentOffset = currentOffset; 29 | } 30 | 31 | public void setBegin(long begin) { 32 | this.begin = begin; 33 | } 34 | 35 | public void setEnd(long end) { 36 | this.end = end; 37 | } 38 | 39 | public int getVgId() { 40 | return vgId; 41 | } 42 | 43 | public long getCurrentOffset() { 44 | return currentOffset; 45 | } 46 | 47 | public long getBegin() { 48 | return begin; 49 | } 50 | 51 | public long getEnd() { 52 | return end; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/tmq/Deserializer.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | import java.io.Closeable; 4 | import java.sql.ResultSet; 5 | import java.sql.SQLException; 6 | import java.util.Map; 7 | 8 | public interface Deserializer extends Closeable { 9 | 10 | default void configure(Map configs) { 11 | // intentionally left blank 12 | } 13 | 14 | V deserialize(ResultSet data, String topic, String dbName) throws DeserializerException, SQLException; 15 | 16 | @Override 17 | default void close() { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/tmq/DeserializerException.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | public class DeserializerException extends RuntimeException { 4 | 5 | public DeserializerException(String message, Exception e) { 6 | super(message, e); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/tmq/JNIConsumerFactory.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | import com.taosdata.jdbc.common.Consumer; 4 | import com.taosdata.jdbc.common.ConsumerFactory; 5 | import com.taosdata.jdbc.common.ConsumerManager; 6 | import com.taosdata.jdbc.enums.ConnectionType; 7 | 8 | public class JNIConsumerFactory implements ConsumerFactory { 9 | 10 | static { 11 | ConsumerManager.register(new JNIConsumerFactory()); 12 | } 13 | 14 | @Override 15 | public boolean acceptsType(String type) { 16 | return null == type || ConnectionType.JNI.getType().equalsIgnoreCase(type); 17 | } 18 | 19 | @Override 20 | public Consumer getConsumer() { 21 | return new JNIConsumer<>(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/tmq/MapDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.ResultSetMetaData; 5 | import java.sql.SQLException; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class MapDeserializer implements Deserializer> { 10 | @Override 11 | public Map deserialize(ResultSet data, String topic, String dbName) throws SQLException { 12 | Map map = new HashMap<>(); 13 | 14 | ResultSetMetaData metaData = data.getMetaData(); 15 | for (int i = 1; i <= metaData.getColumnCount(); i++) { 16 | map.put(metaData.getColumnLabel(i), data.getObject(i)); 17 | } 18 | 19 | return map; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/tmq/MapEnhanceDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.ResultSetMetaData; 5 | import java.sql.SQLException; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public class MapEnhanceDeserializer implements Deserializer { 10 | 11 | // this method will not be called. 12 | @Override 13 | public TMQEnhMap deserialize(ResultSet data, String topic, String dbName) throws SQLException { 14 | return null; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/tmq/OffsetAndMetadata.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | public class OffsetAndMetadata { 4 | private final long offset; 5 | private final String metadata; 6 | 7 | 8 | public OffsetAndMetadata(long offset) { 9 | this(offset, ""); 10 | } 11 | 12 | public OffsetAndMetadata(long offset, String metadata) { 13 | if (offset < 0 && offset != TMQConstants.INVALID_OFFSET) 14 | throw new IllegalArgumentException("Invalid negative offset: " + offset); 15 | 16 | this.offset = offset; 17 | 18 | this.metadata = ""; 19 | } 20 | 21 | public long offset() { 22 | return offset; 23 | } 24 | 25 | public String metadata() { 26 | return metadata; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | final StringBuffer sb = new StringBuffer("OffsetAndMetadata{"); 32 | sb.append("offset=").append(offset); 33 | sb.append('}'); 34 | return sb.toString(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/tmq/OffsetCommitCallback.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | import java.util.Map; 4 | 5 | @FunctionalInterface 6 | public interface OffsetCommitCallback { 7 | 8 | void onComplete(Map offsets, Exception exception); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/tmq/OffsetWaitCallback.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | import com.taosdata.jdbc.TSDBError; 4 | 5 | import java.util.Map; 6 | 7 | import static com.taosdata.jdbc.TSDBConstants.TMQ_SUCCESS; 8 | 9 | public class OffsetWaitCallback { 10 | private final Map offsets; 11 | 12 | private final JNIConsumer consumer; 13 | private final OffsetCommitCallback callback; 14 | 15 | public OffsetWaitCallback(Map offsets, JNIConsumer consumer, OffsetCommitCallback callback) { 16 | this.offsets = offsets; 17 | this.consumer = consumer; 18 | this.callback = callback; 19 | } 20 | 21 | @SuppressWarnings("unused") 22 | public void commitCallbackHandler(int code) { 23 | if (TMQ_SUCCESS != code) { 24 | Exception exception = TSDBError.createSQLException(code, consumer.getErrMsg(code)); 25 | 26 | callback.onComplete(offsets, exception); 27 | } else { 28 | callback.onComplete(offsets, null); 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/tmq/TMQEnhMap.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | import java.util.Map; 4 | 5 | public class TMQEnhMap { 6 | private final String tableName; 7 | private final Map map; 8 | 9 | public TMQEnhMap(String tableName, Map map) { 10 | this.tableName = tableName; 11 | this.map = map; 12 | } 13 | 14 | public String getTableName() { 15 | return tableName; 16 | } 17 | 18 | public Map getMap() { 19 | return map; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/tmq/TopicPartition.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | import java.util.Objects; 6 | 7 | public class TopicPartition { 8 | private final String topic; 9 | @JsonProperty("vgroup_id") 10 | private final int vGroupId; 11 | 12 | public TopicPartition(String topic, int vGroupId) { 13 | this.topic = topic; 14 | this.vGroupId = vGroupId; 15 | } 16 | 17 | public String getTopic() { 18 | return topic; 19 | } 20 | 21 | public int getVGroupId() { 22 | return vGroupId; 23 | } 24 | 25 | @Override 26 | public boolean equals(Object o) { 27 | if (this == o) return true; 28 | if (o == null || getClass() != o.getClass()) return false; 29 | TopicPartition partition = (TopicPartition) o; 30 | return vGroupId == partition.vGroupId && Objects.equals(topic, partition.topic); 31 | } 32 | 33 | @Override 34 | public int hashCode() { 35 | return Objects.hash(topic, vGroupId); 36 | } 37 | 38 | 39 | @Override 40 | public String toString() { 41 | return "TopicPartition{" + "topic='" + topic + '\'' + 42 | ", vGroupId=" + vGroupId + 43 | '}'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/utils/DecimalUtil.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.BigInteger; 5 | 6 | public class DecimalUtil { 7 | 8 | public static BigDecimal getBigDecimal(byte[] original, int scale) { 9 | // reverse original array 10 | int left = 0; 11 | int right = original.length - 1; 12 | while (left < right) { 13 | byte temp = original[left]; 14 | original[left] = original[right]; 15 | original[right] = temp; 16 | left++; 17 | right--; 18 | } 19 | 20 | BigInteger value = new BigInteger(original); 21 | return new BigDecimal(value).movePointLeft(scale); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/utils/JsonUtil.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import com.fasterxml.jackson.databind.*; 5 | import com.fasterxml.jackson.databind.module.SimpleModule; 6 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; 7 | import com.taosdata.jdbc.ws.tmq.meta.*; 8 | 9 | import java.text.SimpleDateFormat; 10 | 11 | public class JsonUtil { 12 | private static final ObjectMapper objectMapper = new ObjectMapper(); 13 | 14 | static { 15 | configureObjectMapper(objectMapper); 16 | } 17 | 18 | private JsonUtil() { 19 | // private constructor to prevent instantiation 20 | } 21 | 22 | public static ObjectMapper getObjectMapper() { 23 | return objectMapper; 24 | } 25 | public static ObjectReader getObjectReader(Class clazz) { 26 | return objectMapper.readerFor(clazz); 27 | } 28 | 29 | public static ObjectReader getObjectReader() { 30 | return objectMapper.reader(); 31 | } 32 | public static ObjectWriter getObjectWriter(Class clazz) { 33 | return objectMapper.writerFor(clazz); 34 | } 35 | 36 | public static ObjectWriter getObjectWriter() { 37 | return objectMapper.writer(); 38 | } 39 | 40 | private static void configureObjectMapper(ObjectMapper objectMapper) { 41 | // ignore unknown properties 42 | objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); 43 | 44 | // ignore null values 45 | objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); 46 | 47 | // timestamp format 48 | objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); 49 | objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); 50 | 51 | // register JavaTimeModule 52 | objectMapper.registerModule(new JavaTimeModule()); 53 | 54 | // register meta deserializers 55 | SimpleModule module = new SimpleModule(); 56 | 57 | module.addDeserializer(AlterType.class, new AlterTypeDeserializer()); 58 | module.addDeserializer(TableType.class, new TableTypeDeserializer()); 59 | module.addDeserializer(MetaType.class, new MetaTypeDeserializer()); 60 | module.addDeserializer(Meta.class, new MetaDeserializer()); 61 | 62 | objectMapper.registerModule(module); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/utils/OSUtils.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | public class OSUtils { 4 | private static final String OS = System.getProperty("os.name").toLowerCase(); 5 | 6 | public static boolean isWindows() { 7 | return OS.contains("win"); 8 | } 9 | 10 | public static boolean isMac() { 11 | return OS.contains("mac"); 12 | } 13 | 14 | public static boolean isLinux() { 15 | return OS.contains("nux"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/utils/ReqId.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import java.lang.management.ManagementFactory; 4 | import java.lang.management.RuntimeMXBean; 5 | import java.nio.ByteBuffer; 6 | import java.nio.ByteOrder; 7 | import java.nio.charset.StandardCharsets; 8 | import java.util.UUID; 9 | import java.util.concurrent.atomic.AtomicLong; 10 | 11 | public class ReqId { 12 | 13 | private ReqId() { 14 | } 15 | 16 | private static final long tUUIDHashId; 17 | private static final long pid; 18 | private static AtomicLong serialNo = new AtomicLong(0); 19 | 20 | static { 21 | String uuid = UUID.randomUUID().toString(); 22 | long hash = murmurHash32(uuid.getBytes(StandardCharsets.UTF_8), uuid.length()); 23 | tUUIDHashId = (hash & 0x07ff) << 52; 24 | RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); 25 | pid = (long) (Long.valueOf(runtimeMXBean.getName().split("@")[0]).intValue() & 0x0f) << 48; 26 | } 27 | 28 | public static long getReqID() { 29 | long ts = (System.currentTimeMillis() >> 8) & 0x3ffffff; 30 | long val = serialNo.incrementAndGet(); 31 | return tUUIDHashId | pid | (ts << 20) | (val & 0xfffff); 32 | } 33 | 34 | public static long murmurHash32(byte[] data, int seed) { 35 | final int c1 = 0xcc9e2d51; 36 | final int c2 = 0x1b873593; 37 | final int r1 = 15; 38 | final int r2 = 13; 39 | final int m = 5; 40 | final int n = 0xe6546b64; 41 | 42 | int hash = seed; 43 | int length = data.length; 44 | 45 | for (int i = 0; i < length / 4; i++) { 46 | int k = ByteBuffer.wrap(data, i * 4, 4).order(ByteOrder.LITTLE_ENDIAN).getInt(); 47 | 48 | k *= c1; 49 | k = Integer.rotateLeft(k, r1); 50 | k *= c2; 51 | 52 | hash ^= k; 53 | hash = Integer.rotateLeft(hash, r2); 54 | hash = hash * m + n; 55 | } 56 | 57 | int k = 0; 58 | // TODO : check this 59 | switch (length & 3) { 60 | case 3: 61 | k ^= data[length - 3] << 16; 62 | case 2: 63 | k ^= data[length - 2] << 8; 64 | case 1: 65 | k ^= data[length - 1]; 66 | k *= c1; 67 | k = Integer.rotateLeft(k, r1); 68 | k *= c2; 69 | hash ^= k; 70 | } 71 | 72 | hash ^= length; 73 | 74 | hash ^= hash >>> 16; 75 | hash *= 0x85ebca6b; 76 | hash ^= hash >>> 13; 77 | hash *= 0xc2b2ae35; 78 | hash ^= hash >>> 16; 79 | 80 | return Integer.toUnsignedLong(hash); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | public class SqlSyntaxValidator { 6 | private static final Pattern USE_PATTERN = Pattern.compile("use\\s+(\\w+);?", Pattern.CASE_INSENSITIVE); 7 | 8 | private SqlSyntaxValidator() { 9 | } 10 | 11 | public static boolean isUseSql(String sql) { 12 | return sql.trim().toLowerCase().startsWith("use"); 13 | } 14 | 15 | public static String getDatabaseName(String sql) { 16 | if (isUseSql(sql)) { 17 | sql = sql.split(";")[0].trim(); 18 | return USE_PATTERN.matcher(sql).replaceAll("$1"); 19 | } 20 | return null; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/utils/SyncObj.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | import java.util.concurrent.locks.Condition; 5 | import java.util.concurrent.locks.Lock; 6 | import java.util.concurrent.locks.ReentrantLock; 7 | 8 | public class SyncObj { 9 | private final Lock lock = new ReentrantLock(); 10 | private final Condition condition = lock.newCondition(); 11 | public void signal() { 12 | lock.lock(); 13 | try { 14 | condition.signal(); 15 | } finally { 16 | lock.unlock(); 17 | } 18 | } 19 | 20 | public void await() throws InterruptedException { 21 | lock.lock(); 22 | try { 23 | condition.await(10, TimeUnit.MILLISECONDS); 24 | } finally { 25 | lock.unlock(); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/utils/TaosInfo.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import javax.management.*; 4 | import java.lang.management.ManagementFactory; 5 | import java.util.concurrent.atomic.AtomicLong; 6 | 7 | public class TaosInfo implements TaosInfoMBean { 8 | 9 | private static volatile TaosInfo instance; 10 | private final AtomicLong connect_open = new AtomicLong(); 11 | private final AtomicLong connect_close = new AtomicLong(); 12 | private final AtomicLong statement_count = new AtomicLong(); 13 | 14 | static { 15 | try { 16 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); 17 | ObjectName name = new ObjectName("TaosInfoMBean:name=TaosInfo"); 18 | server.registerMBean(TaosInfo.getInstance(), name); 19 | } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException ignored) { 20 | throw new RuntimeException("registerMBean failed"); 21 | } 22 | } 23 | 24 | @Override 25 | public long getConnect_open() { 26 | return connect_open.get(); 27 | } 28 | 29 | @Override 30 | public long getConnect_close() { 31 | return connect_close.get(); 32 | } 33 | 34 | @Override 35 | public long getConnect_active() { 36 | return connect_open.get() - connect_close.get(); 37 | } 38 | 39 | @Override 40 | public long getStatement_count() { 41 | return statement_count.get(); 42 | } 43 | 44 | /*******************************************************/ 45 | 46 | public void conn_open_increment() { 47 | connect_open.incrementAndGet(); 48 | } 49 | 50 | public void connect_close_increment() { 51 | connect_close.incrementAndGet(); 52 | } 53 | 54 | public void stmt_count_increment() { 55 | statement_count.incrementAndGet(); 56 | } 57 | 58 | /********************************************************************************/ 59 | private TaosInfo() { 60 | } 61 | 62 | public static TaosInfo getInstance() { 63 | if (instance == null) { 64 | synchronized (TaosInfo.class) { 65 | if (instance == null) { 66 | instance = new TaosInfo(); 67 | } 68 | } 69 | } 70 | return instance; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/utils/TaosInfoMBean.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | public interface TaosInfoMBean { 4 | 5 | long getConnect_open(); 6 | 7 | long getConnect_close(); 8 | 9 | long getConnect_active(); 10 | 11 | long getStatement_count(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/utils/UInt64Deserializer.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.core.JsonProcessingException; 5 | import com.fasterxml.jackson.databind.DeserializationContext; 6 | import com.fasterxml.jackson.databind.JsonDeserializer; 7 | 8 | import java.io.IOException; 9 | import java.math.BigInteger; 10 | 11 | public class UInt64Deserializer extends JsonDeserializer { 12 | @Override 13 | public Long deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { 14 | String text = p.getText(); 15 | try { 16 | return new BigInteger(text).longValue(); 17 | } catch (NumberFormatException e) { 18 | throw new IOException("Unable to deserialize UInt64 value: " + text, e); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/utils/UInt64Serializer.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator; 4 | import com.fasterxml.jackson.databind.JsonSerializer; 5 | import com.fasterxml.jackson.databind.SerializerProvider; 6 | 7 | import java.io.IOException; 8 | 9 | public class UInt64Serializer extends JsonSerializer { 10 | @Override 11 | public void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException { 12 | if (value < 0) { 13 | String encodedValue = Long.toUnsignedString(value); 14 | gen.writeString(encodedValue); 15 | } else { 16 | gen.writeNumber(value); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/utils/UnsignedDataUtils.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.BigInteger; 5 | 6 | public class UnsignedDataUtils { 7 | 8 | private UnsignedDataUtils() { 9 | } 10 | 11 | public static short parseUTinyInt(byte val) { 12 | return (short) (val & 0xff); 13 | } 14 | 15 | public static int parseUSmallInt(short val) { 16 | return val & 0xffff; 17 | } 18 | 19 | public static long parseUInteger(int val) { 20 | return val & 0xffffffffL; 21 | } 22 | 23 | public static BigInteger parseUBigInt(long val) { 24 | 25 | if (val > 0) { 26 | return BigInteger.valueOf(val); 27 | } 28 | 29 | return new BigInteger(Long.toUnsignedString(val)); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/CustomWebSocketClientHandshaker.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | import io.netty.handler.codec.http.HttpHeaders; 4 | import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker13; 5 | import io.netty.handler.codec.http.websocketx.WebSocketFrameEncoder; 6 | import io.netty.handler.codec.http.websocketx.WebSocketVersion; 7 | 8 | import java.net.URI; 9 | 10 | public class CustomWebSocketClientHandshaker extends WebSocketClientHandshaker13 { 11 | 12 | public CustomWebSocketClientHandshaker(URI webSocketURL, WebSocketVersion version, String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength) { 13 | super(webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength); 14 | } 15 | 16 | public CustomWebSocketClientHandshaker(URI webSocketURL, WebSocketVersion version, String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength, boolean performMasking, boolean allowMaskMismatch) { 17 | super(webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength, performMasking, allowMaskMismatch); 18 | } 19 | 20 | public CustomWebSocketClientHandshaker(URI webSocketURL, WebSocketVersion version, String subprotocol, boolean allowExtensions, HttpHeaders customHeaders, int maxFramePayloadLength, boolean performMasking, boolean allowMaskMismatch, long forceCloseTimeoutMillis) { 21 | super(webSocketURL, version, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength, performMasking, allowMaskMismatch, forceCloseTimeoutMillis); 22 | } 23 | 24 | @Override 25 | protected WebSocketFrameEncoder newWebSocketEncoder() { 26 | return new CustomWebSocketFrameEncoder(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/FutureResponse.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | import com.taosdata.jdbc.ws.entity.Response; 4 | 5 | import java.util.concurrent.CompletableFuture; 6 | 7 | public class FutureResponse implements Comparable { 8 | private final String action; 9 | private final Long id; 10 | private final CompletableFuture future; 11 | private final long timestamp; 12 | 13 | public FutureResponse(String action, Long id, CompletableFuture future) { 14 | this.action = action; 15 | this.id = id; 16 | this.future = future; 17 | timestamp = System.nanoTime(); 18 | } 19 | 20 | public String getAction() { 21 | return action; 22 | } 23 | 24 | public Long getId() { 25 | return id; 26 | } 27 | 28 | public CompletableFuture getFuture() { 29 | return future; 30 | } 31 | 32 | long getTimestamp() { 33 | return timestamp; 34 | } 35 | 36 | @Override 37 | public int compareTo(FutureResponse fr) { 38 | long r = this.timestamp - fr.timestamp; 39 | if (r > 0) return 1; 40 | if (r < 0) return -1; 41 | return 0; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/InFlightRequest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | import com.taosdata.jdbc.ws.entity.Action; 4 | import com.taosdata.jdbc.ws.schemaless.SchemalessAction; 5 | import com.taosdata.jdbc.ws.tmq.ConsumerAction; 6 | 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import java.util.concurrent.ConcurrentHashMap; 10 | import java.util.concurrent.Semaphore; 11 | import java.util.concurrent.TimeUnit; 12 | import java.util.concurrent.TimeoutException; 13 | 14 | /** 15 | * Unfinished execution 16 | */ 17 | public class InFlightRequest { 18 | private final int timeout; 19 | private final Semaphore semaphore; 20 | private final Map> futureMap = new HashMap<>(); 21 | 22 | public InFlightRequest(int timeout, int concurrentNum) { 23 | this.timeout = timeout; 24 | this.semaphore = new Semaphore(concurrentNum); 25 | for (Action value : Action.values()) { 26 | String action = value.getAction(); 27 | futureMap.put(action, new ConcurrentHashMap<>()); 28 | } 29 | for (ConsumerAction value : ConsumerAction.values()) { 30 | String action = value.getAction(); 31 | futureMap.put(action, new ConcurrentHashMap<>()); 32 | } 33 | for (SchemalessAction value : SchemalessAction.values()) { 34 | String action = value.getAction(); 35 | futureMap.put(action, new ConcurrentHashMap<>()); 36 | } 37 | } 38 | 39 | public void put(FutureResponse rf) throws InterruptedException, TimeoutException { 40 | if (semaphore.tryAcquire(timeout, TimeUnit.MILLISECONDS)) { 41 | futureMap.get(rf.getAction()).put(rf.getId(), rf); 42 | } else { 43 | throw new TimeoutException("websocket connection reached the max number of concurrent requests"); 44 | } 45 | } 46 | 47 | public FutureResponse remove(String action, Long id) { 48 | FutureResponse future = futureMap.get(action).remove(id); 49 | if (null != future) { 50 | semaphore.release(); 51 | } 52 | return future; 53 | } 54 | 55 | public void close() { 56 | futureMap.keySet().stream() 57 | .flatMap(k -> { 58 | ConcurrentHashMap futures = futureMap.get(k); 59 | futureMap.put(k, new ConcurrentHashMap<>()); 60 | return futures.values().stream(); 61 | }) 62 | .parallel().map(FutureResponse::getFuture) 63 | .forEach(e -> e.completeExceptionally(new Exception("close all inFlightRequest"))); 64 | } 65 | 66 | public boolean hasInFlightRequest() { 67 | return futureMap.keySet().stream() 68 | .filter(k -> !futureMap.get(k).isEmpty()).findAny().orElse(null) != null; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/TSWSPreparedStatement.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | 4 | import com.taosdata.jdbc.AbstractConnection; 5 | import com.taosdata.jdbc.rs.ConnectionParam; 6 | import com.taosdata.jdbc.ws.stmt2.entity.Stmt2PrepareResp; 7 | 8 | import java.sql.SQLException; 9 | public class TSWSPreparedStatement extends AbsWSPreparedStatement { 10 | public TSWSPreparedStatement(Transport transport, 11 | ConnectionParam param, 12 | String database, 13 | AbstractConnection connection, 14 | String sql, 15 | Long instanceId, 16 | Stmt2PrepareResp prepareResp) throws SQLException { 17 | super(transport, param, database, connection, sql, instanceId, prepareResp); 18 | } 19 | 20 | public TSWSPreparedStatement(Transport transport, 21 | ConnectionParam param, 22 | String database, 23 | AbstractConnection connection, 24 | String sql, 25 | Long instanceId) throws SQLException { 26 | super(transport, param, database, connection, sql, instanceId); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/WebSocketDriver.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | 4 | import com.taosdata.jdbc.AbstractDriver; 5 | import com.taosdata.jdbc.TSDBError; 6 | import com.taosdata.jdbc.TSDBErrorNumbers; 7 | import com.taosdata.jdbc.rs.ConnectionParam; 8 | 9 | import java.sql.*; 10 | import java.util.Properties; 11 | import java.util.logging.Logger; 12 | 13 | public class WebSocketDriver extends AbstractDriver { 14 | public static final String URL_PREFIX = "jdbc:TAOS-WS://"; 15 | 16 | static { 17 | try { 18 | DriverManager.registerDriver(new WebSocketDriver()); 19 | } catch (SQLException e) { 20 | throw TSDBError.createRuntimeException(TSDBErrorNumbers.ERROR_URL_NOT_SET, e); 21 | } 22 | } 23 | 24 | @Override 25 | public Connection connect(String url, Properties info) throws SQLException { 26 | // throw SQLException if url is null 27 | if (url == null || url.trim().isEmpty() || url.trim().replaceAll("\\s", "").isEmpty()) 28 | throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET); 29 | 30 | // return null if url is not be accepted 31 | if (!acceptsURL(url)) 32 | return null; 33 | 34 | Properties props = parseURL(url, info); 35 | ConnectionParam param = ConnectionParam.getParamWs(props); 36 | return getWSConnection(url, param, props); 37 | 38 | } 39 | 40 | @Override 41 | public boolean acceptsURL(String url) throws SQLException { 42 | if (url == null) 43 | throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_URL_NOT_SET); 44 | return url.trim().length() > 0 && url.startsWith(URL_PREFIX); 45 | } 46 | 47 | @Override 48 | public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { 49 | if (info == null) { 50 | info = new Properties(); 51 | } 52 | if (acceptsURL(url)) { 53 | info = parseURL(url, info); 54 | } 55 | return getPropertyInfo(info); 56 | } 57 | 58 | @Override 59 | public int getMajorVersion() { 60 | return 3; 61 | } 62 | 63 | @Override 64 | public int getMinorVersion() { 65 | return 0; 66 | } 67 | 68 | @Override 69 | public boolean jdbcCompliant() { 70 | return false; 71 | } 72 | 73 | @Override 74 | public Logger getParentLogger() throws SQLFeatureNotSupportedException { 75 | throw new SQLFeatureNotSupportedException(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/WebSocketHandshakeHandler.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | import io.netty.channel.ChannelFuture; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.channel.ChannelInboundHandlerAdapter; 6 | import io.netty.channel.ChannelPromise; 7 | import io.netty.handler.codec.http.FullHttpResponse; 8 | import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker; 9 | import io.netty.handler.codec.http.websocketx.WebSocketHandshakeException; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | public class WebSocketHandshakeHandler extends ChannelInboundHandlerAdapter { 14 | private static final Logger log = LoggerFactory.getLogger(WebSocketHandshakeHandler.class); 15 | 16 | private final WebSocketClientHandshaker handshaker; 17 | private ChannelPromise handshakeFuture; 18 | public WebSocketHandshakeHandler(WebSocketClientHandshaker handshaker) { 19 | this.handshaker = handshaker; 20 | this.handshakeFuture = null; 21 | } 22 | 23 | public ChannelFuture handshakeFuture() { 24 | return handshakeFuture; 25 | } 26 | 27 | @Override 28 | public void handlerAdded(ChannelHandlerContext ctx) { 29 | handshakeFuture = ctx.newPromise(); 30 | } 31 | @Override 32 | public void channelActive(ChannelHandlerContext ctx) { 33 | // 发起握手 34 | handshaker.handshake(ctx.channel()); 35 | ctx.fireChannelActive(); 36 | } 37 | 38 | @Override 39 | public void channelRead(ChannelHandlerContext ctx, Object msg) { 40 | if (!handshaker.isHandshakeComplete()) { 41 | try { 42 | handshaker.finishHandshake(ctx.channel(), (FullHttpResponse) msg); 43 | handshakeFuture.setSuccess(); 44 | 45 | ctx.pipeline().remove(this); 46 | } catch (WebSocketHandshakeException e) { 47 | log.error("handshake failed: ", e); 48 | handshakeFuture.setFailure(e); 49 | ctx.close(); 50 | } 51 | } 52 | ctx.fireChannelRead(msg); 53 | } 54 | 55 | @Override 56 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { 57 | if (!handshakeFuture.isDone()) { 58 | handshakeFuture.setFailure(cause); 59 | } 60 | ctx.close(); 61 | } 62 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/WebsocketNotConnectedException.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | /** 4 | * exception which indicates the websocket is not yet connected (ReadyState.OPEN) 5 | */ 6 | public class WebsocketNotConnectedException extends RuntimeException { 7 | 8 | /** 9 | * Serializable 10 | */ 11 | private static final long serialVersionUID = -785314021592982715L; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/Action.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | import com.taosdata.jdbc.ws.stmt2.entity.ResultResp; 4 | import com.taosdata.jdbc.ws.stmt2.entity.Stmt2ExecResp; 5 | import com.taosdata.jdbc.ws.stmt2.entity.Stmt2PrepareResp; 6 | import com.taosdata.jdbc.ws.stmt2.entity.Stmt2Resp; 7 | import com.taosdata.jdbc.ws.tmq.entity.FetchRawBlockResp; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * request type 14 | */ 15 | public enum Action { 16 | CONN("conn", ConnectResp.class), 17 | QUERY("query", QueryResp.class), 18 | //BINARY_QUERY("binary_query_with_result", QueryResp.class), 19 | BINARY_QUERY("binary_query", QueryResp.class), 20 | FETCH("fetch", FetchResp.class), 21 | FETCH_BLOCK("fetch_raw_block", FetchRawBlockResp.class), 22 | FETCH_BLOCK_NEW("fetch_block_new", FetchBlockNewResp.class), 23 | 24 | // free_result's class is meaningless 25 | FREE_RESULT("free_result", Response.class), 26 | 27 | // stmt2 28 | STMT2_INIT("stmt2_init", Stmt2Resp.class), 29 | STMT2_PREPARE("stmt2_prepare", Stmt2PrepareResp.class), 30 | STMT2_BIND("stmt2_bind", Stmt2Resp.class), 31 | STMT2_EXEC("stmt2_exec", Stmt2ExecResp.class), 32 | // response means nothing 33 | STMT2_CLOSE("stmt2_close", Stmt2Resp.class), 34 | STMT2_USE_RESULT("stmt2_result", ResultResp.class), 35 | 36 | //schemaless 37 | INSERT("insert", CommonResp.class), 38 | ; 39 | ; 40 | private final String action; 41 | private final Class clazz; 42 | 43 | Action(String action, Class clazz) { 44 | this.action = action; 45 | this.clazz = clazz; 46 | } 47 | 48 | public String getAction() { 49 | return action; 50 | } 51 | 52 | public Class getResponseClazz() { 53 | return clazz; 54 | } 55 | 56 | private static final Map actions = new HashMap<>(); 57 | 58 | static { 59 | for (Action value : Action.values()) { 60 | actions.put(value.action, value); 61 | } 62 | } 63 | 64 | public static Action of(String action) { 65 | if (null == action || action.equals("")) { 66 | return null; 67 | } 68 | return actions.get(action); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/Code.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | /** 4 | * response message info 5 | */ 6 | public enum Code { 7 | SUCCESS(0, "success"), 8 | ; 9 | 10 | private final int code; 11 | private final String message; 12 | 13 | Code(int code, String message) { 14 | this.code = code; 15 | this.message = message; 16 | } 17 | 18 | public int getCode() { 19 | return code; 20 | } 21 | 22 | public String getMessage() { 23 | return message; 24 | } 25 | 26 | public static Code of(int code) { 27 | for (Code value : Code.values()) { 28 | if (value.code == code) { 29 | return value; 30 | } 31 | } 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/CommonResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | public class CommonResp extends Response { 4 | 5 | private int code; 6 | private String message; 7 | 8 | public int getCode() { 9 | return code; 10 | } 11 | 12 | public void setCode(int code) { 13 | this.code = code; 14 | } 15 | 16 | public String getMessage() { 17 | return message; 18 | } 19 | 20 | public void setMessage(String message) { 21 | this.message = message; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/ConnectReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | import com.taosdata.jdbc.rs.ConnectionParam; 4 | import com.taosdata.jdbc.utils.ReqId; 5 | 6 | /** 7 | * connection request pojo 8 | */ 9 | 10 | public class ConnectReq extends Payload { 11 | 12 | private String user; 13 | private String password; 14 | private String db; 15 | private Integer mode; 16 | 17 | private String tz; 18 | private String app; 19 | private String ip; 20 | 21 | public String getUser() { 22 | return user; 23 | } 24 | 25 | public void setUser(String user) { 26 | this.user = user; 27 | } 28 | 29 | public String getPassword() { 30 | return password; 31 | } 32 | 33 | public void setPassword(String password) { 34 | this.password = password; 35 | } 36 | 37 | public String getDb() { 38 | return db; 39 | } 40 | 41 | public void setDb(String db) { 42 | this.db = db; 43 | } 44 | 45 | public Integer getMode() { 46 | return mode; 47 | } 48 | 49 | public void setMode(Integer mode) { 50 | this.mode = mode; 51 | } 52 | 53 | 54 | public String getTz() { 55 | return tz; 56 | } 57 | 58 | public void setTz(String tz) { 59 | this.tz = tz; 60 | } 61 | 62 | public String getApp() { 63 | return app; 64 | } 65 | 66 | public void setApp(String app) { 67 | this.app = app; 68 | } 69 | 70 | public String getIp() { 71 | return ip; 72 | } 73 | 74 | public void setIp(String ip) { 75 | this.ip = ip; 76 | } 77 | 78 | public ConnectReq(ConnectionParam param) { 79 | this.setReqId(ReqId.getReqID()); 80 | this.setUser(param.getUser()); 81 | this.setPassword(param.getPassword()); 82 | this.setDb(param.getDatabase()); 83 | this.setTz(param.getTz()); 84 | this.setApp(param.getAppName()); 85 | this.setIp(param.getAppIp()); 86 | 87 | // Currently, only BI mode is supported. The downstream interface value is 0, so a conversion is performed here. 88 | if(param.getConnectMode() == ConnectionParam.CONNECT_MODE_BI){ 89 | this.setMode(0); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/ConnectResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | /** 4 | * connection result pojo 5 | */ 6 | public class ConnectResp extends CommonResp { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/FetchBlockNewResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.util.ReferenceCountUtil; 5 | 6 | import java.nio.charset.StandardCharsets; 7 | 8 | public class FetchBlockNewResp extends Response { 9 | private ByteBuf buffer; 10 | 11 | public void setCompleted(boolean completed) { 12 | isCompleted = completed; 13 | } 14 | 15 | private boolean isCompleted; 16 | private long time; 17 | private int code; 18 | private String message; 19 | private short version; 20 | 21 | public FetchBlockNewResp(ByteBuf buffer) { 22 | this.setAction(Action.FETCH_BLOCK_NEW.getAction()); 23 | this.buffer = buffer; 24 | } 25 | 26 | public void init() { 27 | buffer.readLongLE(); // action id 28 | version = buffer.readShortLE(); 29 | time = buffer.readLongLE(); 30 | this.setReqId(buffer.readLongLE()); 31 | code = buffer.readIntLE(); 32 | int messageLen = buffer.readIntLE(); 33 | byte[] msgBytes = new byte[messageLen]; 34 | buffer.readBytes(msgBytes); 35 | 36 | message = new String(msgBytes, StandardCharsets.UTF_8); 37 | buffer.readLongLE(); // resultId 38 | isCompleted = buffer.readByte() != 0; 39 | 40 | if (isCompleted){ 41 | ReferenceCountUtil.safeRelease(buffer); 42 | } 43 | } 44 | 45 | public ByteBuf getBuffer() { 46 | return buffer; 47 | } 48 | 49 | public void setBuffer(ByteBuf buffer) { 50 | this.buffer = buffer; 51 | } 52 | 53 | public boolean isCompleted() { 54 | return isCompleted; 55 | } 56 | 57 | 58 | public long getTime() { 59 | return time; 60 | } 61 | 62 | public int getCode() { 63 | return code; 64 | } 65 | 66 | public String getMessage() { 67 | return message; 68 | } 69 | 70 | public short getVersion() { 71 | return version; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/FetchReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import com.taosdata.jdbc.utils.UInt64Deserializer; 6 | import com.taosdata.jdbc.utils.UInt64Serializer; 7 | 8 | public class FetchReq extends Payload { 9 | @JsonSerialize(using = UInt64Serializer.class) 10 | @JsonDeserialize(using = UInt64Deserializer.class) 11 | private long id; 12 | 13 | public long getId() { 14 | return id; 15 | } 16 | 17 | public void setId(long id) { 18 | this.id = id; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/FetchResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | /** 4 | * fetch result pojo 5 | */ 6 | public class FetchResp extends CommonResp{ 7 | private long id; 8 | private boolean completed; 9 | private Integer[] lengths; 10 | private int rows; 11 | 12 | public long getId() { 13 | return id; 14 | } 15 | 16 | public void setId(long id) { 17 | this.id = id; 18 | } 19 | 20 | public boolean isCompleted() { 21 | return completed; 22 | } 23 | 24 | public void setCompleted(boolean completed) { 25 | this.completed = completed; 26 | } 27 | 28 | public Integer[] getLengths() { 29 | return lengths; 30 | } 31 | 32 | public void setLengths(Integer[] lengths) { 33 | this.lengths = lengths; 34 | } 35 | 36 | public int getRows() { 37 | return rows; 38 | } 39 | 40 | public void setRows(int rows) { 41 | this.rows = rows; 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/Payload.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public class Payload { 6 | @JsonProperty("req_id") 7 | private long reqId; 8 | 9 | public void setReqId(long reqId) { 10 | this.reqId = reqId; 11 | } 12 | 13 | public long getReqId() { 14 | return reqId; 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/QueryReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | public class QueryReq extends Payload { 4 | private String sql; 5 | 6 | public String getSql() { 7 | return sql; 8 | } 9 | 10 | public void setSql(String sql) { 11 | this.sql = sql; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/Request.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.taosdata.jdbc.utils.JsonUtil; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | 9 | /** 10 | * send to taosadapter 11 | */ 12 | public class Request { 13 | private static final Logger log = LoggerFactory.getLogger(Request.class); 14 | 15 | private String action; 16 | private Payload args; 17 | 18 | public Request(String action, Payload args) { 19 | this.action = action; 20 | this.args = args; 21 | } 22 | 23 | public String getAction() { 24 | return action; 25 | } 26 | 27 | public Long id(){ 28 | return args.getReqId(); 29 | } 30 | 31 | public void setAction(String action) { 32 | this.action = action; 33 | } 34 | 35 | public Payload getArgs() { 36 | return args; 37 | } 38 | 39 | public void setArgs(Payload args) { 40 | this.args = args; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | ObjectMapper objectMapper = JsonUtil.getObjectMapper(); 46 | try { 47 | return objectMapper.writeValueAsString(this); 48 | } catch (JsonProcessingException e) { 49 | log.error("Request to string error", e); 50 | return null; 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/RequestFactory.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | /** 4 | * generate id for request 5 | */ 6 | public class RequestFactory { 7 | 8 | private RequestFactory() { 9 | } 10 | 11 | public static Request generateQuery(String sql, long reqId) { 12 | QueryReq queryReq = new QueryReq(); 13 | queryReq.setReqId(reqId); 14 | queryReq.setSql(sql); 15 | return new Request(Action.QUERY.getAction(), queryReq); 16 | } 17 | 18 | public static Request generateFetch(long id, long reqId) { 19 | FetchReq fetchReq = new FetchReq(); 20 | fetchReq.setReqId(reqId); 21 | fetchReq.setId(id); 22 | return new Request(Action.FETCH.getAction(), fetchReq); 23 | } 24 | 25 | public static Request generateFetchBlock(long id) { 26 | FetchReq fetchReq = new FetchReq(); 27 | fetchReq.setReqId(id); 28 | fetchReq.setId(id); 29 | return new Request(Action.FETCH_BLOCK.getAction(), fetchReq); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/entity/Response.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | /** 6 | * return from taosadapter 7 | */ 8 | public class Response { 9 | private String action; 10 | 11 | @JsonProperty("req_id") 12 | private long reqId; 13 | 14 | public String getAction() { 15 | return action; 16 | } 17 | 18 | public void setAction(String action) { 19 | this.action = action; 20 | } 21 | 22 | public long getReqId() { 23 | return reqId; 24 | } 25 | 26 | public void setReqId(long reqId) { 27 | this.reqId = reqId; 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/schemaless/ConnReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.schemaless; 2 | 3 | import com.taosdata.jdbc.ws.entity.Payload; 4 | 5 | public class ConnReq extends Payload { 6 | private String user; 7 | private String password; 8 | private String db; 9 | 10 | public String getUser() { 11 | return user; 12 | } 13 | 14 | public void setUser(String user) { 15 | this.user = user; 16 | } 17 | 18 | public String getPassword() { 19 | return password; 20 | } 21 | 22 | public void setPassword(String password) { 23 | this.password = password; 24 | } 25 | 26 | public String getDb() { 27 | return db; 28 | } 29 | 30 | public void setDb(String db) { 31 | this.db = db; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/schemaless/InsertReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.schemaless; 2 | 3 | import com.taosdata.jdbc.ws.entity.Payload; 4 | 5 | public class InsertReq extends Payload { 6 | 7 | private int protocol; 8 | private String precision; 9 | private String data; 10 | private int ttl; 11 | 12 | public int getProtocol() { 13 | return protocol; 14 | } 15 | 16 | public void setProtocol(int protocol) { 17 | this.protocol = protocol; 18 | } 19 | 20 | public String getPrecision() { 21 | return precision; 22 | } 23 | 24 | public void setPrecision(String precision) { 25 | this.precision = precision; 26 | } 27 | 28 | public String getData() { 29 | return data; 30 | } 31 | 32 | public void setData(String data) { 33 | this.data = data; 34 | } 35 | 36 | public int getTtl() { 37 | return ttl; 38 | } 39 | 40 | public void setTtl(int ttl) { 41 | this.ttl = ttl; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/schemaless/SchemalessAction.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.schemaless; 2 | 3 | import com.taosdata.jdbc.ws.entity.CommonResp; 4 | import com.taosdata.jdbc.ws.entity.Response; 5 | 6 | public enum SchemalessAction { 7 | CONN("conn", CommonResp.class), 8 | INSERT("insert", CommonResp.class), 9 | ; 10 | 11 | private final String action; 12 | private final Class clazz; 13 | 14 | SchemalessAction(String action, Class clazz) { 15 | this.action = action; 16 | this.clazz = clazz; 17 | } 18 | 19 | public String getAction() { 20 | return action; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/stmt2/entity/CloseReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.stmt2.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import com.taosdata.jdbc.utils.UInt64Serializer; 6 | import com.taosdata.jdbc.ws.entity.Payload; 7 | 8 | public class CloseReq extends Payload { 9 | @JsonProperty("stmt_id") 10 | @JsonSerialize(using = UInt64Serializer.class) 11 | private long stmtId; 12 | 13 | public long getStmtId() { 14 | return stmtId; 15 | } 16 | 17 | public void setStmtId(long stmtId) { 18 | this.stmtId = stmtId; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/stmt2/entity/ExecReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.stmt2.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import com.taosdata.jdbc.utils.UInt64Serializer; 6 | import com.taosdata.jdbc.ws.entity.Payload; 7 | 8 | public class ExecReq extends Payload { 9 | @JsonProperty("stmt_id") 10 | @JsonSerialize(using = UInt64Serializer.class) 11 | private long stmtId; 12 | 13 | public long getStmtId() { 14 | return stmtId; 15 | } 16 | 17 | public void setStmtId(long stmtId) { 18 | this.stmtId = stmtId; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/stmt2/entity/Field.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.stmt2.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | public class Field { 6 | private String name; 7 | @JsonProperty("field_type") 8 | private byte fieldType; 9 | private byte precision; 10 | private byte scale; 11 | private int bytes; 12 | 13 | @JsonProperty("bind_type") 14 | private byte bindType; 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | 23 | public byte getFieldType() { 24 | return fieldType; 25 | } 26 | 27 | public void setFieldType(byte fieldType) { 28 | this.fieldType = fieldType; 29 | } 30 | 31 | public byte getPrecision() { 32 | return precision; 33 | } 34 | 35 | public void setPrecision(byte precision) { 36 | this.precision = precision; 37 | } 38 | 39 | public byte getScale() { 40 | return scale; 41 | } 42 | 43 | public void setScale(byte scale) { 44 | this.scale = scale; 45 | } 46 | 47 | public int getBytes() { 48 | return bytes; 49 | } 50 | 51 | public void setBytes(int bytes) { 52 | this.bytes = bytes; 53 | } 54 | 55 | public byte getBindType() { 56 | return bindType; 57 | } 58 | 59 | public void setBindType(byte bindType) { 60 | this.bindType = bindType; 61 | } 62 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/stmt2/entity/InitReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.stmt2.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.taosdata.jdbc.ws.entity.Payload; 5 | 6 | public class InitReq extends Payload { 7 | @JsonProperty("single_stb_insert") 8 | private boolean singleStbInsert; 9 | @JsonProperty("single_table_bind_once") 10 | private boolean singleTableBindOnce; 11 | 12 | public boolean isSingleStbInsert() { 13 | return singleStbInsert; 14 | } 15 | 16 | public void setSingleStbInsert(boolean singleStbInsert) { 17 | this.singleStbInsert = singleStbInsert; 18 | } 19 | 20 | public boolean isSingleTableBindOnce() { 21 | return singleTableBindOnce; 22 | } 23 | 24 | public void setSingleTableBindOnce(boolean singleTableBindOnce) { 25 | this.singleTableBindOnce = singleTableBindOnce; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/stmt2/entity/PrepareReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.stmt2.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import com.taosdata.jdbc.utils.UInt64Serializer; 6 | import com.taosdata.jdbc.ws.entity.Payload; 7 | 8 | public class PrepareReq extends Payload { 9 | @JsonProperty("stmt_id") 10 | @JsonSerialize(using = UInt64Serializer.class) 11 | private long stmtId; 12 | private String sql; 13 | @JsonProperty("get_fields") 14 | private boolean getFields = true; 15 | public long getStmtId() { 16 | return stmtId; 17 | } 18 | 19 | public void setStmtId(long stmtId) { 20 | this.stmtId = stmtId; 21 | } 22 | 23 | public String getSql() { 24 | return sql; 25 | } 26 | 27 | public void setSql(String sql) { 28 | this.sql = sql; 29 | } 30 | 31 | 32 | public boolean isGetFields() { 33 | return getFields; 34 | } 35 | 36 | public void setGetFields(boolean getFields) { 37 | this.getFields = getFields; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/stmt2/entity/RequestFactory.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.stmt2.entity; 2 | 3 | 4 | import com.taosdata.jdbc.ws.entity.Action; 5 | import com.taosdata.jdbc.ws.entity.Request; 6 | 7 | /** 8 | * generate id for request 9 | */ 10 | public class RequestFactory { 11 | 12 | private RequestFactory() { 13 | } 14 | 15 | public static Request generateInit(long reqId, boolean singleStbInsert, boolean singleTableBindOnce) { 16 | InitReq initReq = new InitReq(); 17 | initReq.setReqId(reqId); 18 | initReq.setSingleStbInsert(singleStbInsert); 19 | initReq.setSingleTableBindOnce(singleTableBindOnce); 20 | return new Request(Action.STMT2_INIT.getAction(), initReq); 21 | } 22 | 23 | public static Request generatePrepare(long stmtId, long reqId, String sql) { 24 | PrepareReq prepareReq = new PrepareReq(); 25 | prepareReq.setReqId(reqId); 26 | prepareReq.setStmtId(stmtId); 27 | prepareReq.setSql(sql); 28 | return new Request(Action.STMT2_PREPARE.getAction(), prepareReq); 29 | } 30 | 31 | public static Request generateExec(long stmtId, long reqId) { 32 | ExecReq req = new ExecReq(); 33 | req.setReqId(reqId); 34 | req.setStmtId(stmtId); 35 | return new Request(Action.STMT2_EXEC.getAction(), req); 36 | } 37 | public static Request generateClose(long stmtId, long reqId) { 38 | CloseReq req = new CloseReq(); 39 | req.setReqId(reqId); 40 | req.setStmtId(stmtId); 41 | return new Request(Action.STMT2_CLOSE.getAction(), req); 42 | } 43 | public static Request generateUseResult(long stmtId, long reqId) { 44 | ResultReq req = new ResultReq(); 45 | req.setReqId(reqId); 46 | req.setStmtId(stmtId); 47 | return new Request(Action.STMT2_USE_RESULT.getAction(), req); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/stmt2/entity/ResultReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.stmt2.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import com.taosdata.jdbc.utils.UInt64Serializer; 6 | import com.taosdata.jdbc.ws.entity.Payload; 7 | 8 | public class ResultReq extends Payload { 9 | @JsonProperty("stmt_id") 10 | @JsonSerialize(using = UInt64Serializer.class) 11 | private long stmtId; 12 | 13 | public long getStmtId() { 14 | return stmtId; 15 | } 16 | 17 | public void setStmtId(long stmtId) { 18 | this.stmtId = stmtId; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/stmt2/entity/ResultResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.stmt2.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 5 | import com.taosdata.jdbc.utils.UInt64Deserializer; 6 | import com.taosdata.jdbc.ws.entity.CommonResp; 7 | import com.taosdata.jdbc.ws.entity.QueryResp; 8 | 9 | /** 10 | * query result pojo 11 | */ 12 | public class ResultResp extends QueryResp { 13 | @JsonProperty("stmt_id") 14 | @JsonDeserialize(using = UInt64Deserializer.class) 15 | private long stmtId; 16 | 17 | public long getStmtId() { 18 | return stmtId; 19 | } 20 | 21 | public void setStmtId(long stmtId) { 22 | this.stmtId = stmtId; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/stmt2/entity/Stmt2ExecResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.stmt2.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 5 | import com.taosdata.jdbc.utils.UInt64Deserializer; 6 | import com.taosdata.jdbc.ws.entity.CommonResp; 7 | 8 | public class Stmt2ExecResp extends CommonResp { 9 | @JsonProperty("stmt_id") 10 | @JsonDeserialize(using = UInt64Deserializer.class) 11 | private long stmtId; 12 | private int affected; 13 | public long getStmtId() { 14 | return stmtId; 15 | } 16 | 17 | public void setStmtId(long stmtId) { 18 | this.stmtId = stmtId; 19 | } 20 | 21 | public int getAffected() { 22 | return affected; 23 | } 24 | 25 | public void setAffected(int affected) { 26 | this.affected = affected; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/stmt2/entity/Stmt2PrepareResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.stmt2.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 5 | import com.taosdata.jdbc.utils.UInt64Deserializer; 6 | import com.taosdata.jdbc.ws.entity.CommonResp; 7 | 8 | import java.util.List; 9 | 10 | public class Stmt2PrepareResp extends CommonResp { 11 | @JsonProperty("stmt_id") 12 | @JsonDeserialize(using = UInt64Deserializer.class) 13 | private long stmtId; 14 | private List fields; 15 | @JsonProperty("fields_count") 16 | private int fieldsCount; 17 | @JsonProperty("is_insert") 18 | private boolean isInsert; 19 | public long getStmtId() { 20 | return stmtId; 21 | } 22 | 23 | public void setStmtId(long stmtId) { 24 | this.stmtId = stmtId; 25 | } 26 | 27 | public List getFields() { 28 | return fields; 29 | } 30 | 31 | public void setFields(List fields) { 32 | this.fields = fields; 33 | } 34 | 35 | public int getFieldsCount() { 36 | return fieldsCount; 37 | } 38 | 39 | public void setFieldsCount(int fieldsCount) { 40 | this.fieldsCount = fieldsCount; 41 | } 42 | public boolean isInsert() { 43 | return isInsert; 44 | } 45 | 46 | public void setInsert(boolean insert) { 47 | isInsert = insert; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/stmt2/entity/Stmt2Resp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.stmt2.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 5 | import com.taosdata.jdbc.utils.UInt64Deserializer; 6 | import com.taosdata.jdbc.ws.entity.CommonResp; 7 | 8 | import java.util.List; 9 | 10 | // init | prepare | set_table_name | set_tags | bind | add_batch 11 | public class Stmt2Resp extends CommonResp { 12 | @JsonProperty("stmt_id") 13 | @JsonDeserialize(using = UInt64Deserializer.class) 14 | private long stmtId; 15 | public long getStmtId() { 16 | return stmtId; 17 | } 18 | 19 | public void setStmtId(long stmtId) { 20 | this.stmtId = stmtId; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/ConsumerAction.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq; 2 | 3 | import com.taosdata.jdbc.ws.entity.Response; 4 | import com.taosdata.jdbc.ws.tmq.entity.*; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | public enum ConsumerAction { 10 | // subscribe 11 | SUBSCRIBE("subscribe", SubscribeResp.class), 12 | POLL("poll", PollResp.class), 13 | FETCH_RAW_DATA("fetch_raw_data", FetchRawBlockResp.class), 14 | COMMIT("commit", CommitResp.class), 15 | ASSIGNMENT("assignment", AssignmentResp.class), 16 | SEEK("seek", SeekResp.class), 17 | UNSUBSCRIBE("unsubscribe", UnsubscribeResp.class), 18 | COMMIT_OFFSET("commit_offset", CommitOffsetResp.class), 19 | COMMITTED("committed", CommittedResp.class), 20 | POSITION("position", PositionResp.class), 21 | LIST_TOPICS("list_topics", ListTopicsResp.class), 22 | FETCH_JSON_META("fetch_json_meta", FetchJsonMetaResp.class), 23 | 24 | ; 25 | 26 | private final String action; 27 | private final Class clazz; 28 | 29 | ConsumerAction(String action, Class clazz) { 30 | this.action = action; 31 | this.clazz = clazz; 32 | } 33 | 34 | public String getAction() { 35 | return action; 36 | } 37 | 38 | public Class getResponseClazz() { 39 | return clazz; 40 | } 41 | 42 | private static final Map actions = new HashMap<>(); 43 | 44 | static { 45 | for (ConsumerAction value : ConsumerAction.values()) { 46 | actions.put(value.action, value); 47 | } 48 | } 49 | 50 | public static ConsumerAction of(String action) { 51 | if (null == action || action.equals("")) { 52 | return null; 53 | } 54 | return actions.get(action); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/WSConsumerFactory.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq; 2 | 3 | import com.taosdata.jdbc.common.Consumer; 4 | import com.taosdata.jdbc.common.ConsumerFactory; 5 | import com.taosdata.jdbc.common.ConsumerManager; 6 | import com.taosdata.jdbc.enums.ConnectionType; 7 | 8 | public class WSConsumerFactory implements ConsumerFactory { 9 | 10 | static { 11 | ConsumerManager.register(new WSConsumerFactory()); 12 | } 13 | 14 | @Override 15 | public boolean acceptsType(String type) { 16 | return ConnectionType.WS.getType().equalsIgnoreCase(type) || ConnectionType.WEBSOCKET.getType().equalsIgnoreCase(type); 17 | } 18 | 19 | @Override 20 | public Consumer getConsumer() { 21 | return new WSConsumer<>(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/AssignmentReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.taosdata.jdbc.ws.entity.Payload; 4 | 5 | public class AssignmentReq extends Payload { 6 | private String topic; 7 | 8 | public String getTopic() { 9 | return topic; 10 | } 11 | 12 | public void setTopic(String topic) { 13 | this.topic = topic; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/AssignmentResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.taosdata.jdbc.tmq.Assignment; 4 | import com.taosdata.jdbc.ws.entity.CommonResp; 5 | 6 | public class AssignmentResp extends CommonResp { 7 | private long timing; 8 | private Assignment[] assignment; 9 | public long getTiming() { 10 | return timing; 11 | } 12 | 13 | public void setTiming(long timing) { 14 | this.timing = timing; 15 | } 16 | 17 | public Assignment[] getAssignment() { 18 | return assignment; 19 | } 20 | 21 | public void setAssignment(Assignment[] assignment) { 22 | this.assignment = assignment; 23 | } 24 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/CommitOffsetReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.taosdata.jdbc.ws.entity.Payload; 5 | 6 | public class CommitOffsetReq extends Payload { 7 | private String topic; 8 | 9 | @JsonProperty("vgroup_id") 10 | private int vgroupId; 11 | 12 | private long offset; 13 | 14 | public String getTopic() { 15 | return topic; 16 | } 17 | 18 | public void setTopic(String topic) { 19 | this.topic = topic; 20 | } 21 | 22 | public int getVgroupId() { 23 | return vgroupId; 24 | } 25 | 26 | public void setVgroupId(int vgroupId) { 27 | this.vgroupId = vgroupId; 28 | } 29 | 30 | public long getOffset() { 31 | return offset; 32 | } 33 | 34 | public void setOffset(long offset) { 35 | this.offset = offset; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/CommitOffsetResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.taosdata.jdbc.ws.entity.CommonResp; 5 | 6 | public class CommitOffsetResp extends CommonResp { 7 | private long timing; 8 | private String topic; 9 | @JsonProperty("vg_id") 10 | private int vgId; 11 | private long offset; 12 | public long getTiming() { 13 | return timing; 14 | } 15 | 16 | public void setTiming(long timing) { 17 | this.timing = timing; 18 | } 19 | 20 | public String getTopic() { 21 | return topic; 22 | } 23 | 24 | public void setTopic(String topic) { 25 | this.topic = topic; 26 | } 27 | 28 | public int getVgId() { 29 | return vgId; 30 | } 31 | 32 | public void setVgId(int vgId) { 33 | this.vgId = vgId; 34 | } 35 | 36 | public long getOffset() { 37 | return offset; 38 | } 39 | 40 | public void setOffset(long offset) { 41 | this.offset = offset; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/CommitReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import com.taosdata.jdbc.utils.UInt64Serializer; 6 | import com.taosdata.jdbc.ws.entity.Payload; 7 | 8 | public class CommitReq extends Payload { 9 | 10 | @JsonProperty("message_id") 11 | @JsonSerialize(using = UInt64Serializer.class) 12 | private long messageId; 13 | 14 | public long getMessageId() { 15 | return messageId; 16 | } 17 | 18 | public void setMessageId(long messageId) { 19 | this.messageId = messageId; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/CommitResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 5 | import com.taosdata.jdbc.utils.UInt64Deserializer; 6 | import com.taosdata.jdbc.ws.entity.CommonResp; 7 | 8 | public class CommitResp extends CommonResp { 9 | @JsonProperty("stmt_id") 10 | @JsonDeserialize(using = UInt64Deserializer.class) 11 | private long messageId; 12 | 13 | public long getMessageId() { 14 | return messageId; 15 | } 16 | 17 | public void setMessageId(long messageId) { 18 | this.messageId = messageId; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/CommittedReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.taosdata.jdbc.tmq.TopicPartition; 5 | import com.taosdata.jdbc.ws.entity.Payload; 6 | 7 | public class CommittedReq extends Payload { 8 | 9 | @JsonProperty("topic_vgroup_ids") 10 | TopicPartition[] topicPartitions; 11 | 12 | public TopicPartition[] getTopicPartitions() { 13 | return topicPartitions; 14 | } 15 | 16 | public void setTopicPartitions(TopicPartition[] topicPartitions) { 17 | this.topicPartitions = topicPartitions; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/CommittedResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.taosdata.jdbc.ws.entity.CommonResp; 4 | 5 | public class CommittedResp extends CommonResp { 6 | private long timing; 7 | private long[] committed; 8 | public long getTiming() { 9 | return timing; 10 | } 11 | 12 | public void setTiming(long timing) { 13 | this.timing = timing; 14 | } 15 | 16 | public long[] getCommitted() { 17 | return committed; 18 | } 19 | 20 | public void setCommitted(long[] committed) { 21 | this.committed = committed; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/FetchJsonMetaData.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 5 | import com.taosdata.jdbc.utils.UInt64Deserializer; 6 | import com.taosdata.jdbc.ws.entity.CommonResp; 7 | import com.taosdata.jdbc.ws.tmq.meta.Meta; 8 | 9 | import java.util.List; 10 | 11 | public class FetchJsonMetaData { 12 | @JsonProperty("tmq_meta_version") 13 | private String tmqMetaVersion; 14 | private List metas; 15 | 16 | public String getTmqMetaVersion() { 17 | return tmqMetaVersion; 18 | } 19 | 20 | public void setTmqMetaVersion(String tmqMetaVersion) { 21 | this.tmqMetaVersion = tmqMetaVersion; 22 | } 23 | 24 | public List getMetas() { 25 | return metas; 26 | } 27 | 28 | public void setMetas(List metas) { 29 | this.metas = metas; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/FetchJsonMetaReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import com.taosdata.jdbc.utils.UInt64Serializer; 6 | import com.taosdata.jdbc.ws.entity.Payload; 7 | 8 | public class FetchJsonMetaReq extends Payload { 9 | 10 | @JsonProperty("message_id") 11 | @JsonSerialize(using = UInt64Serializer.class) 12 | private long messageId; 13 | 14 | public long getMessageId() { 15 | return messageId; 16 | } 17 | 18 | public void setMessageId(long messageId) { 19 | this.messageId = messageId; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/FetchJsonMetaResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 5 | import com.taosdata.jdbc.utils.UInt64Deserializer; 6 | import com.taosdata.jdbc.ws.entity.CommonResp; 7 | 8 | public class FetchJsonMetaResp extends CommonResp { 9 | private long timing; 10 | @JsonProperty("message_id") 11 | @JsonDeserialize(using = UInt64Deserializer.class) 12 | private long messageId; 13 | 14 | private FetchJsonMetaData data; 15 | 16 | public long getTiming() { 17 | return timing; 18 | } 19 | 20 | public void setTiming(long timing) { 21 | this.timing = timing; 22 | } 23 | 24 | public long getMessageId() { 25 | return messageId; 26 | } 27 | 28 | public void setMessageId(long messageId) { 29 | this.messageId = messageId; 30 | } 31 | 32 | public FetchJsonMetaData getData() { 33 | return data; 34 | } 35 | 36 | public void setData(FetchJsonMetaData data) { 37 | this.data = data; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/FetchRawReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import com.taosdata.jdbc.utils.UInt64Serializer; 6 | import com.taosdata.jdbc.ws.entity.Payload; 7 | 8 | public class FetchRawReq extends Payload { 9 | @JsonProperty("message_id") 10 | @JsonSerialize(using = UInt64Serializer.class) 11 | private long messageId; 12 | 13 | public long getMessageId() { 14 | return messageId; 15 | } 16 | 17 | public void setMessageId(long messageId) { 18 | this.messageId = messageId; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/FetchResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 5 | import com.taosdata.jdbc.utils.UInt64Deserializer; 6 | import com.taosdata.jdbc.ws.entity.CommonResp; 7 | 8 | public class FetchResp extends CommonResp { 9 | 10 | @JsonProperty("message_id") 11 | @JsonDeserialize(using = UInt64Deserializer.class) 12 | private long messageId; 13 | private boolean completed; 14 | 15 | @JsonProperty("table_name") 16 | private String tableName; 17 | 18 | private int rows; 19 | 20 | @JsonProperty("fields_count") 21 | private int fieldsCount; 22 | 23 | @JsonProperty("fields_names") 24 | private String[] fieldsNames; 25 | 26 | @JsonProperty("fields_types") 27 | private int[] fieldsTypes; 28 | 29 | @JsonProperty("fields_lengths") 30 | private long[] fieldsLengths; 31 | 32 | private int precision; 33 | 34 | 35 | public long getMessageId() { 36 | return messageId; 37 | } 38 | 39 | public void setMessageId(long messageId) { 40 | this.messageId = messageId; 41 | } 42 | 43 | public boolean isCompleted() { 44 | return completed; 45 | } 46 | 47 | public void setCompleted(boolean completed) { 48 | this.completed = completed; 49 | } 50 | 51 | public String getTableName() { 52 | return tableName; 53 | } 54 | 55 | public void setTableName(String tableName) { 56 | this.tableName = tableName; 57 | } 58 | 59 | public int getRows() { 60 | return rows; 61 | } 62 | 63 | public void setRows(int rows) { 64 | this.rows = rows; 65 | } 66 | 67 | public int getFieldsCount() { 68 | return fieldsCount; 69 | } 70 | 71 | public void setFieldsCount(int fieldsCount) { 72 | this.fieldsCount = fieldsCount; 73 | } 74 | 75 | public String[] getFieldsNames() { 76 | return fieldsNames; 77 | } 78 | 79 | public void setFieldsNames(String[] fieldsNames) { 80 | this.fieldsNames = fieldsNames; 81 | } 82 | 83 | public int[] getFieldsTypes() { 84 | return fieldsTypes; 85 | } 86 | 87 | public void setFieldsTypes(int[] fieldsTypes) { 88 | this.fieldsTypes = fieldsTypes; 89 | } 90 | 91 | public long[] getFieldsLengths() { 92 | return fieldsLengths; 93 | } 94 | 95 | public void setFieldsLengths(long[] fieldsLengths) { 96 | this.fieldsLengths = fieldsLengths; 97 | } 98 | 99 | public int getPrecision() { 100 | return precision; 101 | } 102 | 103 | public void setPrecision(int precision) { 104 | this.precision = precision; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/ListTopicsReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.taosdata.jdbc.ws.entity.Payload; 4 | 5 | public class ListTopicsReq extends Payload { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/ListTopicsResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.taosdata.jdbc.ws.entity.CommonResp; 4 | 5 | public class ListTopicsResp extends CommonResp { 6 | private long timing; 7 | private String[] topics; 8 | public long getTiming() { 9 | return timing; 10 | } 11 | 12 | public void setTiming(long timing) { 13 | this.timing = timing; 14 | } 15 | 16 | public String[] getTopics() { 17 | return topics; 18 | } 19 | 20 | public void setTopics(String[] topics) { 21 | this.topics = topics; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/PollReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 5 | import com.taosdata.jdbc.utils.UInt64Deserializer; 6 | import com.taosdata.jdbc.ws.entity.Payload; 7 | 8 | public class PollReq extends Payload { 9 | @JsonProperty("blocking_time") 10 | private long blockingTime; 11 | 12 | @JsonProperty("message_id") 13 | @JsonDeserialize(using = UInt64Deserializer.class) 14 | private long messageId; 15 | 16 | public long getBlockingTime() { 17 | return blockingTime; 18 | } 19 | 20 | public void setBlockingTime(long blockingTime) { 21 | this.blockingTime = blockingTime; 22 | } 23 | 24 | public long getMessageId() { 25 | return messageId; 26 | } 27 | 28 | public void setMessageId(long messageId) { 29 | this.messageId = messageId; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/PollResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 5 | import com.taosdata.jdbc.utils.UInt64Deserializer; 6 | import com.taosdata.jdbc.ws.entity.CommonResp; 7 | 8 | public class PollResp extends CommonResp { 9 | @JsonProperty("have_message") 10 | private boolean haveMessage; 11 | 12 | private String topic; 13 | private String database; 14 | 15 | @JsonProperty("vgroup_id") 16 | private int vgroupId; 17 | 18 | @JsonProperty("message_type") 19 | private int messageType; 20 | 21 | @JsonProperty("message_id") 22 | @JsonDeserialize(using = UInt64Deserializer.class) 23 | private long messageId; 24 | 25 | private long offset; 26 | 27 | private long timing; 28 | 29 | public boolean isHaveMessage() { 30 | return haveMessage; 31 | } 32 | 33 | public void setHaveMessage(boolean haveMessage) { 34 | this.haveMessage = haveMessage; 35 | } 36 | 37 | public String getTopic() { 38 | return topic; 39 | } 40 | 41 | public void setTopic(String topic) { 42 | this.topic = topic; 43 | } 44 | 45 | public String getDatabase() { 46 | return database; 47 | } 48 | 49 | public void setDatabase(String database) { 50 | this.database = database; 51 | } 52 | 53 | public int getVgroupId() { 54 | return vgroupId; 55 | } 56 | 57 | public void setVgroupId(int vgroupId) { 58 | this.vgroupId = vgroupId; 59 | } 60 | 61 | public int getMessageType() { 62 | return messageType; 63 | } 64 | 65 | public void setMessageType(int messageType) { 66 | this.messageType = messageType; 67 | } 68 | 69 | public long getMessageId() { 70 | return messageId; 71 | } 72 | 73 | public void setMessageId(long messageId) { 74 | this.messageId = messageId; 75 | } 76 | 77 | public long getTiming() { 78 | return timing; 79 | } 80 | 81 | public void setTiming(long timing) { 82 | this.timing = timing; 83 | } 84 | 85 | public long getOffset() { 86 | return offset; 87 | } 88 | 89 | public void setOffset(long offset) { 90 | this.offset = offset; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/PositionReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.taosdata.jdbc.tmq.TopicPartition; 5 | import com.taosdata.jdbc.ws.entity.Payload; 6 | 7 | public class PositionReq extends Payload { 8 | 9 | @JsonProperty("topic_vgroup_ids") 10 | 11 | private TopicPartition[] topicPartitions; 12 | 13 | public TopicPartition[] getTopicPartitions() { 14 | return topicPartitions; 15 | } 16 | 17 | public void setTopicPartitions(TopicPartition[] topicPartitions) { 18 | this.topicPartitions = topicPartitions; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/PositionResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.taosdata.jdbc.ws.entity.CommonResp; 4 | 5 | public class PositionResp extends CommonResp { 6 | private long timing; 7 | private long[] position; 8 | 9 | public long getTiming() { 10 | return timing; 11 | } 12 | 13 | public void setTiming(long timing) { 14 | this.timing = timing; 15 | } 16 | 17 | public long[] getPosition() { 18 | return position; 19 | } 20 | 21 | public void setPosition(long[] position) { 22 | this.position = position; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/SeekReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.taosdata.jdbc.ws.entity.Payload; 5 | 6 | public class SeekReq extends Payload { 7 | private String topic; 8 | @JsonProperty("vgroup_id") 9 | private int vgId; 10 | private long offset; 11 | 12 | public String getTopic() { 13 | return topic; 14 | } 15 | 16 | public void setTopic(String topic) { 17 | this.topic = topic; 18 | } 19 | 20 | public int getVgId() { 21 | return vgId; 22 | } 23 | 24 | public void setVgId(int vgId) { 25 | this.vgId = vgId; 26 | } 27 | 28 | public long getOffset() { 29 | return offset; 30 | } 31 | 32 | public void setOffset(long offset) { 33 | this.offset = offset; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/SeekResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.taosdata.jdbc.ws.entity.CommonResp; 4 | 5 | public class SeekResp extends CommonResp { 6 | private long timing; 7 | public long getTiming() { 8 | return timing; 9 | } 10 | 11 | public void setTiming(long timing) { 12 | this.timing = timing; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/SubscribeResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.taosdata.jdbc.ws.entity.CommonResp; 4 | 5 | public class SubscribeResp extends CommonResp { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/UnsubscribeReq.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import com.taosdata.jdbc.ws.entity.Payload; 5 | 6 | public class UnsubscribeReq extends Payload { 7 | @JsonProperty("req_id") 8 | private long reqId; 9 | 10 | @Override 11 | public long getReqId() { 12 | return reqId; 13 | } 14 | 15 | @Override 16 | public void setReqId(long reqId) { 17 | this.reqId = reqId; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/entity/UnsubscribeResp.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.entity; 2 | 3 | import com.taosdata.jdbc.ws.entity.CommonResp; 4 | 5 | public class UnsubscribeResp extends CommonResp { 6 | private long timing; 7 | public long getTiming() { 8 | return timing; 9 | } 10 | 11 | public void setTiming(long timing) { 12 | this.timing = timing; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/AlterType.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | public enum AlterType { 4 | ADD_TAG(1), 5 | DROP_TAG(2), 6 | RENAME_TAG_NAME(3), 7 | SET_TAG(4), 8 | ADD_COLUMN(5), 9 | DROP_COLUMN(6), 10 | MODIFY_COLUMN_LENGTH(7), 11 | MODIFY_TAG_LENGTH(8), 12 | MODIFY_TABLE_OPTION(9), 13 | RENAME_COLUMN_NAME(10); 14 | private final int value; 15 | 16 | AlterType(int value) { 17 | this.value = value; 18 | } 19 | 20 | public int getValue() { 21 | return value; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/AlterTypeDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.databind.DeserializationContext; 5 | import com.fasterxml.jackson.databind.JsonDeserializer; 6 | 7 | import java.io.IOException; 8 | 9 | public class AlterTypeDeserializer extends JsonDeserializer { 10 | @Override 11 | public AlterType deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { 12 | int value = p.getIntValue(); 13 | for (AlterType type : AlterType.values()) { 14 | if (type.getValue() == value) { 15 | return type; 16 | } 17 | } 18 | throw new IOException("Invalid alter type: " + value); 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/ChildTableInfo.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import java.util.List; 4 | 5 | public class ChildTableInfo extends Meta { 6 | private String using; 7 | private int tagNum; 8 | private List tags; 9 | 10 | public String getUsing() { 11 | return using; 12 | } 13 | 14 | public void setUsing(String using) { 15 | this.using = using; 16 | } 17 | 18 | public int getTagNum() { 19 | return tagNum; 20 | } 21 | 22 | public void setTagNum(int tagNum) { 23 | this.tagNum = tagNum; 24 | } 25 | 26 | public List getTags() { 27 | return tags; 28 | } 29 | 30 | public void setTags(List tags) { 31 | this.tags = tags; 32 | } 33 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/Column.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | import java.util.Objects; 6 | 7 | public class Column { 8 | private String name; 9 | private int type; 10 | private Integer length; 11 | @JsonProperty("isPrimarykey") 12 | private Boolean primarykey; 13 | 14 | private String encode; 15 | private String compress; 16 | private String level; 17 | 18 | public Column() { 19 | } 20 | 21 | public Column(String name, int type, Integer length, Boolean primarykey, String encode, String compress, String level) { 22 | this.name = name; 23 | this.type = type; 24 | this.length = length; 25 | this.primarykey = primarykey; 26 | this.encode = encode; 27 | this.compress = compress; 28 | this.level = level; 29 | } 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public int getType() { 39 | return type; 40 | } 41 | 42 | public void setType(int type) { 43 | this.type = type; 44 | } 45 | 46 | public Integer getLength() { 47 | return length; 48 | } 49 | 50 | public void setLength(Integer length) { 51 | this.length = length; 52 | } 53 | 54 | public Boolean isPrimarykey() { 55 | return primarykey; 56 | } 57 | 58 | public void setPrimarykey(Boolean primarykey) { 59 | this.primarykey = primarykey; 60 | } 61 | 62 | public String getEncode() { 63 | return encode; 64 | } 65 | 66 | public void setEncode(String encode) { 67 | this.encode = encode; 68 | } 69 | 70 | public String getCompress() { 71 | return compress; 72 | } 73 | 74 | public void setCompress(String compress) { 75 | this.compress = compress; 76 | } 77 | 78 | public String getLevel() { 79 | return level; 80 | } 81 | 82 | public void setLevel(String level) { 83 | this.level = level; 84 | } 85 | 86 | @Override 87 | public boolean equals(Object o) { 88 | if (this == o) return true; 89 | if (o == null || getClass() != o.getClass()) return false; 90 | Column column = (Column) o; 91 | return type == column.type && Objects.equals(name, column.name) && Objects.equals(length, column.length) && Objects.equals(primarykey, column.primarykey) && Objects.equals(encode, column.encode) && Objects.equals(compress, column.compress) && Objects.equals(level, column.level); 92 | } 93 | 94 | @Override 95 | public int hashCode() { 96 | return Objects.hash(name, type, length, primarykey, encode, compress, level); 97 | } 98 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/Meta.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import java.util.Objects; 4 | 5 | public abstract class Meta { 6 | private MetaType type; 7 | private String tableName; 8 | private TableType tableType; 9 | 10 | public MetaType getType() { 11 | return type; 12 | } 13 | 14 | public void setType(MetaType type) { 15 | this.type = type; 16 | } 17 | public String getTableName() { 18 | return tableName; 19 | } 20 | 21 | public void setTableName(String tableName) { 22 | this.tableName = tableName; 23 | } 24 | 25 | public TableType getTableType() { 26 | return tableType; 27 | } 28 | 29 | public void setTableType(TableType tableType) { 30 | this.tableType = tableType; 31 | } 32 | 33 | @Override 34 | public boolean equals(Object o) { 35 | if (this == o) return true; 36 | if (o == null || getClass() != o.getClass()) return false; 37 | Meta meta = (Meta) o; 38 | return type == meta.type && Objects.equals(tableName, meta.tableName) && tableType == meta.tableType; 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | return Objects.hash(type, tableName, tableType); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/MetaCreateChildTable.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import java.util.List; 4 | import java.util.Objects; 5 | 6 | public class MetaCreateChildTable extends Meta { 7 | private String using; 8 | private int tagNum; 9 | private List tags; 10 | 11 | private List createList; 12 | 13 | public String getUsing() { 14 | return using; 15 | } 16 | 17 | public void setUsing(String using) { 18 | this.using = using; 19 | } 20 | 21 | public int getTagNum() { 22 | return tagNum; 23 | } 24 | 25 | public void setTagNum(int tagNum) { 26 | this.tagNum = tagNum; 27 | } 28 | 29 | public List getTags() { 30 | return tags; 31 | } 32 | 33 | public void setTags(List tags) { 34 | this.tags = tags; 35 | } 36 | public List getCreateList() { 37 | return createList; 38 | } 39 | 40 | public void setCreateList(List createList) { 41 | this.createList = createList; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object o) { 46 | if (this == o) return true; 47 | if (o == null || getClass() != o.getClass()) return false; 48 | if (!super.equals(o)) return false; 49 | MetaCreateChildTable that = (MetaCreateChildTable) o; 50 | return tagNum == that.tagNum && Objects.equals(using, that.using) && Objects.equals(tags, that.tags) && Objects.equals(createList, that.createList); 51 | } 52 | 53 | @Override 54 | public int hashCode() { 55 | return Objects.hash(super.hashCode(), using, tagNum, tags, createList); 56 | } 57 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/MetaCreateNormalTable.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import java.util.List; 4 | import java.util.Objects; 5 | 6 | public class MetaCreateNormalTable extends Meta { 7 | 8 | private List columns; 9 | private List tags; 10 | 11 | public List getColumns() { 12 | return columns; 13 | } 14 | 15 | public void setColumns(List columns) { 16 | this.columns = columns; 17 | } 18 | 19 | public List getTags() { 20 | return tags; 21 | } 22 | 23 | public void setTags(List tags) { 24 | this.tags = tags; 25 | } 26 | 27 | @Override 28 | public boolean equals(Object o) { 29 | if (this == o) return true; 30 | if (o == null || getClass() != o.getClass()) return false; 31 | if (!super.equals(o)) return false; 32 | MetaCreateNormalTable that = (MetaCreateNormalTable) o; 33 | return Objects.equals(columns, that.columns) && Objects.equals(tags, that.tags); 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | return Objects.hash(super.hashCode(), columns, tags); 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/MetaCreateSuperTable.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import java.util.List; 4 | import java.util.Objects; 5 | 6 | public class MetaCreateSuperTable extends Meta { 7 | private List columns; 8 | private List tags; 9 | 10 | public List getColumns() { 11 | return columns; 12 | } 13 | 14 | public void setColumns(List columns) { 15 | this.columns = columns; 16 | } 17 | 18 | public List getTags() { 19 | return tags; 20 | } 21 | 22 | public void setTags(List tags) { 23 | this.tags = tags; 24 | } 25 | 26 | @Override 27 | public boolean equals(Object o) { 28 | if (this == o) return true; 29 | if (o == null || getClass() != o.getClass()) return false; 30 | if (!super.equals(o)) return false; 31 | MetaCreateSuperTable that = (MetaCreateSuperTable) o; 32 | return Objects.equals(columns, that.columns) && Objects.equals(tags, that.tags); 33 | } 34 | 35 | @Override 36 | public int hashCode() { 37 | return Objects.hash(super.hashCode(), columns, tags); 38 | } 39 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/MetaDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.core.JsonProcessingException; 5 | import com.fasterxml.jackson.core.ObjectCodec; 6 | import com.fasterxml.jackson.databind.DeserializationContext; 7 | import com.fasterxml.jackson.databind.JsonNode; 8 | import com.fasterxml.jackson.databind.deser.std.StdDeserializer; 9 | 10 | import java.io.IOException; 11 | 12 | public class MetaDeserializer extends StdDeserializer { 13 | 14 | public MetaDeserializer() { 15 | this(null); 16 | } 17 | 18 | protected MetaDeserializer(Class vc) { 19 | super(vc); 20 | } 21 | 22 | @Override 23 | public Meta deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, IllegalArgumentException { 24 | ObjectCodec mapper = p.getCodec(); 25 | JsonNode node = mapper.readTree(p); 26 | 27 | String type = node.get("type").asText(); 28 | 29 | String tableType = null; 30 | if (null != node.get("tableType")){ 31 | tableType = node.get("tableType").asText(); 32 | } 33 | 34 | return getMetaBasedOnTableType(mapper, node, type, tableType); 35 | } 36 | 37 | private Meta getMetaBasedOnTableType(ObjectCodec mapper, JsonNode node, String type, String tableType) throws JsonProcessingException { 38 | if (MetaType.CREATE.toString().equalsIgnoreCase(type)) { 39 | if (TableType.SUPER.toString().equalsIgnoreCase(tableType)) { 40 | return mapper.treeToValue(node, MetaCreateSuperTable.class); 41 | } else if (TableType.NORMAL.toString().equalsIgnoreCase(tableType)) { 42 | return mapper.treeToValue(node, MetaCreateNormalTable.class); 43 | } else if (TableType.CHILD.toString().equalsIgnoreCase(tableType)) { 44 | return mapper.treeToValue(node, MetaCreateChildTable.class); 45 | } 46 | } 47 | 48 | if (MetaType.DROP.toString().equalsIgnoreCase(type)) { 49 | if (TableType.SUPER.toString().equalsIgnoreCase(tableType)) { 50 | return mapper.treeToValue(node, MetaDropSuperTable.class); 51 | } else { 52 | return mapper.treeToValue(node, MetaDropTable.class); 53 | } 54 | } 55 | 56 | if (MetaType.ALTER.toString().equalsIgnoreCase(type)) { 57 | return mapper.treeToValue(node, MetaAlterTable.class); 58 | } 59 | throw new IllegalArgumentException("Unsupported combination of 'type' and 'tableType' values: type=" + type + ", tableType=" + tableType); 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/MetaDropSuperTable.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | public class MetaDropSuperTable extends Meta { 3 | } 4 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/MetaDropTable.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import java.util.List; 4 | import java.util.Objects; 5 | 6 | public class MetaDropTable extends Meta { 7 | private List tableNameList; 8 | 9 | public List getTableNameList() { 10 | return tableNameList; 11 | } 12 | 13 | public void setTableNameList(List tableNameList) { 14 | this.tableNameList = tableNameList; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object o) { 19 | if (this == o) return true; 20 | if (o == null || getClass() != o.getClass()) return false; 21 | if (!super.equals(o)) return false; 22 | MetaDropTable that = (MetaDropTable) o; 23 | return Objects.equals(tableNameList, that.tableNameList); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hash(super.hashCode(), tableNameList); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/MetaType.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | public enum MetaType { 4 | // Type: "CREATE" - Create tables, "DROP" - Drop tables, "ALTER" - Alter a table, "DELETE" - Delete data 5 | CREATE, 6 | DROP, 7 | ALTER, 8 | DELETE; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/MetaTypeDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.databind.DeserializationContext; 5 | import com.fasterxml.jackson.databind.JsonDeserializer; 6 | 7 | import java.io.IOException; 8 | 9 | public class MetaTypeDeserializer extends JsonDeserializer { 10 | @Override 11 | public MetaType deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { 12 | String value = p.getText(); 13 | return MetaType.valueOf(value.toUpperCase()); 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/TableType.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | public enum TableType { 4 | SUPER, 5 | CHILD, 6 | NORMAL; 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/TableTypeDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.databind.DeserializationContext; 5 | import com.fasterxml.jackson.databind.JsonDeserializer; 6 | 7 | import java.io.IOException; 8 | 9 | public class TableTypeDeserializer extends JsonDeserializer { 10 | @Override 11 | public TableType deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { 12 | String value = p.getText(); 13 | return TableType.valueOf(value.toUpperCase()); 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/Tag.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | 5 | import java.util.Objects; 6 | 7 | public class Tag { 8 | private String name; 9 | private int type; 10 | private JsonNode value; 11 | 12 | public Tag() { 13 | } 14 | public Tag(String name, int type, JsonNode value) { 15 | this.name = name; 16 | this.type = type; 17 | this.value = value; 18 | } 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public int getType() { 28 | return type; 29 | } 30 | 31 | public void setType(int type) { 32 | this.type = type; 33 | } 34 | 35 | public JsonNode getValue() { 36 | return value; 37 | } 38 | 39 | public void setValue(JsonNode value) { 40 | this.value = value; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object o) { 45 | if (this == o) return true; 46 | if (o == null || getClass() != o.getClass()) return false; 47 | Tag tag = (Tag) o; 48 | return type == tag.type && Objects.equals(name, tag.name) && Objects.equals(value, tag.value); 49 | } 50 | 51 | @Override 52 | public int hashCode() { 53 | return Objects.hash(name, type, value); 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/com/taosdata/jdbc/ws/tmq/meta/TagAlter.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws.tmq.meta; 2 | 3 | import java.util.Objects; 4 | 5 | public class TagAlter { 6 | private String colName; 7 | private String colValue; 8 | private boolean colValueNull; 9 | 10 | public TagAlter() { 11 | } 12 | public TagAlter(String colName, String colValue, boolean colValueNull) { 13 | this.colName = colName; 14 | this.colValue = colValue; 15 | this.colValueNull = colValueNull; 16 | } 17 | 18 | public String getColName() { 19 | return colName; 20 | } 21 | 22 | public void setColName(String colName) { 23 | this.colName = colName; 24 | } 25 | 26 | public String getColValue() { 27 | return colValue; 28 | } 29 | 30 | public void setColValue(String colValue) { 31 | this.colValue = colValue; 32 | } 33 | 34 | public boolean isColValueNull() { 35 | return colValueNull; 36 | } 37 | 38 | public void setColValueNull(boolean colValueNull) { 39 | this.colValueNull = colValueNull; 40 | } 41 | 42 | @Override 43 | public boolean equals(Object o) { 44 | if (this == o) return true; 45 | if (o == null || getClass() != o.getClass()) return false; 46 | TagAlter tagAlter = (TagAlter) o; 47 | return colValueNull == tagAlter.colValueNull && Objects.equals(colName, tagAlter.colName) && Objects.equals(colValue, tagAlter.colValue); 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | return Objects.hash(colName, colValue, colValueNull); 53 | } 54 | } -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/com.taosdata.jdbc.common.ConsumerFactory: -------------------------------------------------------------------------------- 1 | com.taosdata.jdbc.tmq.JNIConsumerFactory 2 | com.taosdata.jdbc.ws.tmq.WSConsumerFactory -------------------------------------------------------------------------------- /src/main/resources/META-INF/services/java.sql.Driver: -------------------------------------------------------------------------------- 1 | com.taosdata.jdbc.ws.WebSocketDriver 2 | com.taosdata.jdbc.TSDBDriver 3 | com.taosdata.jdbc.rs.RestfulDriver 4 | -------------------------------------------------------------------------------- /src/main/resources/taos-jdbc-version.properties: -------------------------------------------------------------------------------- 1 | PRODUCT_NAME = ${product.name} 2 | PRODUCT_VERSION = ${product.version} 3 | DRIVER_VERSION = ${project.version} -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/annotation/CatalogClass.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.annotation; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Test class 8 | */ 9 | public class CatalogClass { 10 | 11 | private String name; 12 | private String alias; 13 | private String author; 14 | private String version; 15 | private List methods = new ArrayList<>(); 16 | private int total; 17 | private int failure; 18 | 19 | public void setTotal(int total) { 20 | this.total = total; 21 | } 22 | 23 | public void setFailure(int failure) { 24 | this.failure = failure; 25 | } 26 | 27 | public void setAuthor(String author) { 28 | this.author = author; 29 | } 30 | 31 | public void setVersion(String version) { 32 | this.version = version; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public void setAlias(String alias) { 40 | this.alias = alias; 41 | } 42 | 43 | public void setMethods(List methods) { 44 | this.methods = methods; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | if (methods.size() < 1) 50 | return ""; 51 | StringBuilder sb = new StringBuilder(); 52 | sb.append("ClassName: ").append(name); 53 | String msg = trim(alias); 54 | if (null != msg) { 55 | sb.append("\tAlias:").append(alias); 56 | sb.append("\tTotal:").append(total) 57 | .append("\tFailure:").append(failure).append("\n"); 58 | } 59 | for (CatalogMethod method : methods) { 60 | sb.append("\t").append(method.getName()); 61 | sb.append("\t").append(method.isSuccess()); 62 | sb.append("\t").append(method.getMessage()); 63 | String mAuthor = trim(method.getAuthor()); 64 | if (null == mAuthor) { 65 | sb.append("\t").append(author); 66 | } else { 67 | sb.append("\t").append(method.getAuthor()); 68 | } 69 | String mVersion = trim(method.getVersion()); 70 | if (null == mVersion) { 71 | sb.append("\t").append(version); 72 | } else { 73 | sb.append("\t").append(mVersion); 74 | } 75 | sb.append("\n"); 76 | } 77 | return sb.toString(); 78 | } 79 | 80 | private String trim(String s) { 81 | if (null == s || s.trim().equals("")) { 82 | return null; 83 | } else { 84 | return s.trim(); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/annotation/CatalogMethod.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.annotation; 2 | 3 | /** 4 | * Test method 5 | */ 6 | public class CatalogMethod { 7 | private String name; 8 | private boolean success; 9 | private String message; 10 | private String author; 11 | private String version; 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | 21 | public boolean isSuccess() { 22 | return success; 23 | } 24 | 25 | public void setSuccess(boolean success) { 26 | this.success = success; 27 | } 28 | 29 | public String getMessage() { 30 | return message; 31 | } 32 | 33 | public void setMessage(String message) { 34 | this.message = message; 35 | } 36 | 37 | public String getAuthor() { 38 | return author; 39 | } 40 | 41 | public void setAuthor(String author) { 42 | this.author = author; 43 | } 44 | 45 | public String getVersion() { 46 | return version; 47 | } 48 | 49 | public void setVersion(String version) { 50 | this.version = version; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/annotation/CatalogRunner.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.annotation; 2 | 3 | import org.junit.internal.AssumptionViolatedException; 4 | import org.junit.internal.runners.model.EachTestNotifier; 5 | import org.junit.runner.notification.RunNotifier; 6 | import org.junit.runner.notification.StoppedByUserException; 7 | import org.junit.runners.BlockJUnit4ClassRunner; 8 | import org.junit.runners.model.InitializationError; 9 | import org.junit.runners.model.Statement; 10 | 11 | public class CatalogRunner extends BlockJUnit4ClassRunner { 12 | 13 | public CatalogRunner(Class testClass) throws InitializationError { 14 | super(testClass); 15 | } 16 | 17 | @Override 18 | public void run(RunNotifier notifier) { 19 | //add user-defined listener 20 | notifier.addListener(new CatalogListener()); 21 | EachTestNotifier testNotifier = new EachTestNotifier(notifier, getDescription()); 22 | 23 | notifier.fireTestRunStarted(getDescription()); 24 | 25 | try { 26 | Statement statement = classBlock(notifier); 27 | statement.evaluate(); 28 | } catch (AssumptionViolatedException av) { 29 | testNotifier.addFailedAssumption(av); 30 | } catch (StoppedByUserException exception) { 31 | throw exception; 32 | } catch (Throwable e) { 33 | testNotifier.addFailure(e); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/annotation/Description.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ElementType.METHOD}) 10 | public @interface Description { 11 | 12 | String value(); 13 | 14 | // git blame author 15 | String author() default ""; 16 | 17 | // since which version; 18 | String version() default ""; 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/annotation/TestTarget.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ElementType.TYPE}) 10 | public @interface TestTarget { 11 | 12 | String alias() default ""; 13 | 14 | String author(); 15 | 16 | String version() default ""; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/AppMemoryLeakTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.utils.SpecifyAddress; 4 | import org.junit.Assert; 5 | import org.junit.BeforeClass; 6 | import org.junit.Ignore; 7 | import org.junit.Test; 8 | 9 | import java.sql.Connection; 10 | import java.sql.DriverManager; 11 | import java.sql.SQLException; 12 | import java.sql.Statement; 13 | 14 | @Ignore 15 | public class AppMemoryLeakTest { 16 | 17 | private static String url; 18 | 19 | @Test(expected = SQLException.class) 20 | public void testCreateTooManyConnection() throws ClassNotFoundException, SQLException { 21 | Class.forName("com.taosdata.jdbc.TSDBDriver"); 22 | while (true) { 23 | Connection conn = DriverManager.getConnection(url); 24 | Assert.assertNotNull(conn); 25 | } 26 | } 27 | 28 | @Test(expected = Exception.class) 29 | public void testCreateTooManyStatement() throws ClassNotFoundException, SQLException { 30 | Class.forName("com.taosdata.jdbc.TSDBDriver"); 31 | Connection conn = DriverManager.getConnection(url); 32 | while (true) { 33 | Statement stmt = conn.createStatement(); 34 | Assert.assertNotNull(stmt); 35 | } 36 | } 37 | 38 | @BeforeClass 39 | public static void before() { 40 | url = SpecifyAddress.getInstance().getJniUrl(); 41 | if (url == null) { 42 | url = "jdbc:TAOS://localhost:6030/?user=root&password=taosdata"; 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.TSDBDriver; 4 | import org.junit.Assert; 5 | import org.junit.Before; 6 | import org.junit.Ignore; 7 | import org.junit.Test; 8 | 9 | import java.sql.*; 10 | import java.util.Properties; 11 | 12 | @Ignore 13 | public class ConnectMultiTaosdByRestfulWithDifferentTokenTest { 14 | 15 | private static final String host1 = "192.168.17.156"; 16 | private static final String user1 = "root"; 17 | private static final String password1 = "tqueue"; 18 | private Connection conn1; 19 | private static final String host2 = "192.168.17.82"; 20 | private static final String user2 = "root"; 21 | private static final String password2 = "taosdata"; 22 | private Connection conn2; 23 | 24 | @Test 25 | public void test() throws SQLException { 26 | //when 27 | executeSelectStatus(conn1); 28 | executeSelectStatus(conn2); 29 | executeSelectStatus(conn1); 30 | } 31 | 32 | private void executeSelectStatus(Connection connection) throws SQLException { 33 | try (Statement stmt = connection.createStatement()) { 34 | ResultSet rs = stmt.executeQuery("select 1"); 35 | ResultSetMetaData meta = rs.getMetaData(); 36 | Assert.assertNotNull(meta); 37 | while (rs.next()) { 38 | } 39 | } 40 | } 41 | 42 | @Before 43 | public void before() { 44 | Properties properties = new Properties(); 45 | properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); 46 | properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); 47 | properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); 48 | 49 | String url1 = "jdbc:TAOS-RS://" + host1 + ":6041/?user=" + user1 + "&password=" + password1; 50 | String url2 = "jdbc:TAOS-RS://" + host2 + ":6041/?user=" + user2 + "&password=" + password2; 51 | try { 52 | conn1 = DriverManager.getConnection(url1, properties); 53 | conn2 = DriverManager.getConnection(url2, properties); 54 | } catch (SQLException e) { 55 | e.printStackTrace(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/ConnectWrongDatabaseTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.utils.SpecifyAddress; 4 | import org.junit.Test; 5 | 6 | import java.sql.Connection; 7 | import java.sql.DriverManager; 8 | import java.sql.SQLException; 9 | import java.sql.Statement; 10 | 11 | public class ConnectWrongDatabaseTest { 12 | 13 | @Test(expected = SQLException.class) 14 | public void connectByJni() throws SQLException { 15 | String url = SpecifyAddress.getInstance().getJniWithoutUrl(); 16 | if (url == null) { 17 | url = "jdbc:TAOS://localhost:6030/wrong_db?user=root&password=taosdata"; 18 | } else { 19 | url += "wrong_db?user=root&password=taosdata"; 20 | } 21 | DriverManager.getConnection(url); 22 | } 23 | 24 | @Test(expected = SQLException.class) 25 | public void connectByRestful() throws SQLException { 26 | String url = SpecifyAddress.getInstance().getRestWithoutUrl(); 27 | if (url == null) { 28 | url = "jdbc:TAOS-RS://localhost:6041/wrong_db?user=root&password=taosdata"; 29 | } else { 30 | url += "wrong_db?user=root&password=taosdata"; 31 | } 32 | Connection connection = DriverManager.getConnection(url); 33 | try (Statement statement = connection.createStatement()) { 34 | statement.executeUpdate("show databases"); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/DriverAutoloadTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.TSDBDriver; 4 | import com.taosdata.jdbc.utils.SpecifyAddress; 5 | import org.junit.Assert; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | 9 | import java.sql.Connection; 10 | import java.sql.DriverManager; 11 | import java.sql.SQLException; 12 | import java.util.Properties; 13 | 14 | public class DriverAutoloadTest { 15 | 16 | private Properties properties; 17 | private final String host = "127.0.0.1"; 18 | 19 | @Test 20 | public void testRestful() throws SQLException { 21 | String url = SpecifyAddress.getInstance().getRestUrl(); 22 | if (url == null) { 23 | url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; 24 | } 25 | Connection conn = DriverManager.getConnection(url, properties); 26 | Assert.assertNotNull(conn); 27 | conn.close(); 28 | } 29 | 30 | @Test 31 | public void testJni() throws SQLException { 32 | String url = SpecifyAddress.getInstance().getRestUrl(); 33 | if (url == null) { 34 | url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; 35 | } 36 | Connection conn = DriverManager.getConnection(url, properties); 37 | Assert.assertNotNull(conn); 38 | conn.close(); 39 | } 40 | 41 | 42 | @Before 43 | public void before() { 44 | properties = new Properties(); 45 | properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); 46 | properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); 47 | properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/FailOverTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import org.junit.Ignore; 4 | import org.junit.Test; 5 | 6 | import java.sql.*; 7 | import java.text.SimpleDateFormat; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | @Ignore 11 | public class FailOverTest { 12 | 13 | private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 14 | 15 | @Test 16 | public void testFailOver() throws ClassNotFoundException { 17 | Class.forName("com.taosdata.jdbc.TSDBDriver"); 18 | final String url = "jdbc:TAOS://:/?user=root&password=taosdata"; 19 | 20 | long end = System.currentTimeMillis() + 1000 * 60 * 5; 21 | while (System.currentTimeMillis() < end) { 22 | try (Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement()) { 23 | ResultSet rs = stmt.executeQuery("show dnodes"); 24 | ResultSetMetaData meta = rs.getMetaData(); 25 | while (rs.next()) { 26 | for (int i = 1; i <= meta.getColumnCount(); i++) { 27 | System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t"); 28 | } 29 | System.out.println(); 30 | } 31 | System.out.println("======================="); 32 | rs.close(); 33 | TimeUnit.SECONDS.sleep(5); 34 | } catch (SQLException | InterruptedException e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/GetLongWithDifferentTimestampPrecision.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.annotation.Description; 4 | import com.taosdata.jdbc.utils.SpecifyAddress; 5 | import org.junit.Assert; 6 | import org.junit.Ignore; 7 | import org.junit.Test; 8 | 9 | import java.sql.*; 10 | import java.text.SimpleDateFormat; 11 | 12 | public class GetLongWithDifferentTimestampPrecision { 13 | 14 | private final String host = "127.0.0.1"; 15 | 16 | @Description("rest return value only for time, have no precision info") 17 | @Test 18 | @Ignore 19 | public void testRestful() throws SQLException { 20 | // given 21 | String url = SpecifyAddress.getInstance().getRestWithoutUrl(); 22 | if (url == null) { 23 | url = "jdbc:TAOS-RS://" + host + ":6041/"; 24 | } 25 | Connection conn = DriverManager.getConnection(url, "root", "taosdata"); 26 | long ts = System.currentTimeMillis(); 27 | 28 | // when and then 29 | assertResultSet(conn, "ms", ts, ts); 30 | assertResultSet(conn, "us", ts, ts * 1000); 31 | assertResultSet(conn, "ns", ts, ts * 1000_000); 32 | } 33 | 34 | @Test 35 | public void testJni() throws SQLException { 36 | // given 37 | String url = SpecifyAddress.getInstance().getJniWithoutUrl(); 38 | if (url == null) { 39 | url = "jdbc:TAOS://" + host + ":6030/"; 40 | } 41 | Connection conn = DriverManager.getConnection(url, "root", "taosdata"); 42 | long ts = System.currentTimeMillis(); 43 | 44 | // when and then 45 | assertResultSet(conn, "ms", ts, ts); 46 | assertResultSet(conn, "us", ts, ts * 1000); 47 | assertResultSet(conn, "ns", ts, ts * 1000_000); 48 | } 49 | 50 | private void assertResultSet(Connection conn, String precision, long timestamp, long expect) throws SQLException { 51 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); 52 | 53 | try (Statement stmt = conn.createStatement()) { 54 | stmt.execute("drop database if exists test"); 55 | stmt.execute("create database if not exists test precision '" + precision + "'"); 56 | stmt.execute("create table test.weather(ts timestamp, f1 int)"); 57 | 58 | String dateTimeStr = sdf.format(new Date(timestamp)); 59 | stmt.execute("insert into test.weather values('" + dateTimeStr + "', 1)"); 60 | 61 | ResultSet rs = stmt.executeQuery("select * from test.weather"); 62 | rs.next(); 63 | long actual = rs.getLong("ts"); 64 | Assert.assertEquals(expect, actual); 65 | stmt.execute("drop database if exists test"); 66 | } 67 | } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/GroupByFetchBlockJNITest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.utils.SpecifyAddress; 4 | import com.taosdata.jdbc.utils.TestUtils; 5 | import org.junit.After; 6 | import org.junit.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import java.sql.*; 11 | 12 | public class GroupByFetchBlockJNITest { 13 | private static Connection connection; 14 | private static Statement statement; 15 | 16 | private String host = "127.0.0.1"; 17 | private String dbName = TestUtils.camelToSnake(GroupByFetchBlockJNITest.class); 18 | private String tName = "st"; 19 | 20 | @Test 21 | public void groupbyTest() throws SQLException { 22 | String sql = "select symbol,max(high) from " + dbName + "." + tName + " where kline_type = '1m' group by symbol;"; 23 | 24 | ResultSet resultSet = statement.executeQuery(sql); 25 | resultSet.next(); 26 | Assert.assertEquals("1m", resultSet.getString(1)); 27 | Assert.assertEquals(2.2, resultSet.getDouble(2), 0); 28 | } 29 | 30 | @Before 31 | public void before() throws SQLException { 32 | String url = SpecifyAddress.getInstance().getRestUrl(); 33 | if (url == null) { 34 | url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; 35 | } 36 | connection = DriverManager.getConnection(url); 37 | statement = connection.createStatement(); 38 | statement.execute("drop database if exists " + dbName); 39 | statement.execute("create database " + dbName); 40 | statement.execute("use " + dbName); 41 | statement.execute("create table " + tName + " (ts timestamp,open_time bigint, low double, open double, high double, close double,close_time bigint, volume double, trades bigint,\n" + 42 | "quote_volume double, changed double,amplitude double,ticket_id bigint) tags(symbol nchar(50), kline_type nchar(20))"); 43 | statement.execute("insert into t1 using " + tName + " tags ('1m','1m') values (now, 1, 1.1, 1.1, 1.1, 1.1, 1, 1.1, 1, 1.1,1.1,1.1,1);"); 44 | statement.execute("insert into t1 using " + tName + " tags ('1m','1m') values (now, 2, 2.2, 2.2, 2.2, 2.2, 2, 2.2, 2, 2.2,2.2,2.2,2)"); 45 | } 46 | 47 | @After 48 | public void after() throws SQLException { 49 | statement.execute("drop database if exists " + dbName); 50 | statement.close(); 51 | connection.close(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/GroupByFetchBlockTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.TSDBDriver; 4 | import com.taosdata.jdbc.utils.SpecifyAddress; 5 | import com.taosdata.jdbc.utils.TestUtils; 6 | import org.junit.After; 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Test; 10 | 11 | import java.sql.*; 12 | import java.util.Properties; 13 | 14 | public class GroupByFetchBlockTest { 15 | private static Connection connection; 16 | private static Statement statement; 17 | 18 | private String host = "127.0.0.1"; 19 | private String dbName = TestUtils.camelToSnake(GroupByFetchBlockTest.class); 20 | private String tName = "st"; 21 | 22 | @Test 23 | public void groupbyTest() throws SQLException { 24 | String sql = "select symbol,max(high) from " + dbName + "." + tName + " where kline_type = '1m' group by symbol;"; 25 | 26 | ResultSet resultSet = statement.executeQuery(sql); 27 | resultSet.next(); 28 | Assert.assertEquals("1m", resultSet.getString(1)); 29 | Assert.assertEquals(2.2, resultSet.getDouble(2), 0); 30 | } 31 | 32 | @Before 33 | public void before() throws SQLException { 34 | String url = SpecifyAddress.getInstance().getRestUrl(); 35 | if (url == null) { 36 | url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; 37 | } 38 | Properties config = new Properties(); 39 | config.setProperty(TSDBDriver.PROPERTY_KEY_BATCH_LOAD, "true"); 40 | connection = DriverManager.getConnection(url, config); 41 | statement = connection.createStatement(); 42 | statement.execute("drop database if exists " + dbName); 43 | statement.execute("create database " + dbName); 44 | statement.execute("use " + dbName); 45 | statement.execute("create table " + tName + " (ts timestamp,open_time bigint, low double, open double, high double, close double,close_time bigint, volume double, trades bigint,\n" + 46 | "quote_volume double, changed double,amplitude double,ticket_id bigint) tags(symbol nchar(50), kline_type nchar(20))"); 47 | statement.execute("insert into t1 using " + tName + " tags ('1m','1m') values (now, 1, 1.1, 1.1, 1.1, 1.1, 1, 1.1, 1, 1.1,1.1,1.1,1);"); 48 | statement.execute("insert into t1 using " + tName + " tags ('1m','1m') values (now, 2, 2.2, 2.2, 2.2, 2.2, 2, 2.2, 2, 2.2,2.2,2.2,2)"); 49 | } 50 | 51 | @After 52 | public void after() throws SQLException { 53 | statement.execute("drop database if exists " + dbName); 54 | statement.close(); 55 | connection.close(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/JDBCTypeAndTypeCompareTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.utils.SpecifyAddress; 4 | import com.taosdata.jdbc.utils.TestUtils; 5 | import org.junit.AfterClass; 6 | import org.junit.Ignore; 7 | import org.junit.Test; 8 | 9 | import java.sql.*; 10 | 11 | @Ignore 12 | public class JDBCTypeAndTypeCompareTest { 13 | private static Connection conn; 14 | private static final String dbname = TestUtils.camelToSnake(JDBCTypeAndTypeCompareTest.class); 15 | 16 | @Test 17 | public void test() throws SQLException { 18 | String url = SpecifyAddress.getInstance().getJniWithoutUrl(); 19 | if (url == null) { 20 | url = "jdbc:TAOS://127.0.0.1:6030/"; 21 | } 22 | conn = DriverManager.getConnection(url, "root", "taosdata"); 23 | Statement stmt = conn.createStatement(); 24 | 25 | stmt.execute("drop database if exists " + dbname); 26 | stmt.execute("create database if not exists " + dbname); 27 | stmt.execute("use " + dbname); 28 | stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(10), f9 nchar(10) )"); 29 | stmt.execute("insert into weather values(now, 1, 2, 3.0, 4.0, 5, 6, true, 'test','test')"); 30 | 31 | ResultSet rs = stmt.executeQuery("select * from weather"); 32 | ResultSetMetaData meta = rs.getMetaData(); 33 | while (rs.next()) { 34 | for (int i = 1; i <= meta.getColumnCount(); i++) { 35 | String columnName = meta.getColumnName(i); 36 | String columnTypeName = meta.getColumnTypeName(i); 37 | Object value = rs.getObject(i); 38 | System.out.printf("columnName : %s, columnTypeName: %s, JDBCType: %s\n", columnName, columnTypeName, value.getClass().getName()); 39 | } 40 | } 41 | 42 | stmt.close(); 43 | } 44 | 45 | @AfterClass 46 | public static void afterClass() { 47 | try { 48 | if (null != conn) { 49 | Statement statement = conn.createStatement(); 50 | statement.execute("drop database if exists " + dbname); 51 | statement.close(); 52 | conn.close(); 53 | } 54 | } catch (SQLException e) { 55 | e.printStackTrace(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/QueryDataTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.TSDBDriver; 4 | import com.taosdata.jdbc.utils.SpecifyAddress; 5 | import com.taosdata.jdbc.utils.TestUtils; 6 | import org.junit.After; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import java.sql.*; 11 | import java.util.Properties; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | 15 | public class QueryDataTest { 16 | 17 | static Connection connection; 18 | static Statement statement; 19 | static String dbName = TestUtils.camelToSnake(QueryDataTest.class); 20 | static String stbName = "meters"; 21 | static String host = "127.0.0.1"; 22 | 23 | @Before 24 | public void createDatabase() throws SQLException { 25 | Properties properties = new Properties(); 26 | properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); 27 | properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); 28 | properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); 29 | properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); 30 | properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); 31 | String url = SpecifyAddress.getInstance().getJniWithoutUrl(); 32 | if (url == null) { 33 | url = "jdbc:TAOS://" + host + ":0/"; 34 | } 35 | connection = DriverManager.getConnection(url, properties); 36 | 37 | statement = connection.createStatement(); 38 | statement.executeUpdate("drop database if exists " + dbName); 39 | statement.executeUpdate("create database if not exists " + dbName); 40 | statement.executeUpdate("use " + dbName); 41 | 42 | String createTableSql = "create table " + stbName + "(ts timestamp, name binary(64))"; 43 | statement.executeUpdate(createTableSql); 44 | } 45 | 46 | @Test 47 | public void testQueryBinaryData() throws SQLException { 48 | String insertSql = "insert into " + stbName + " values(now, 'taosdata')"; 49 | statement.executeUpdate(insertSql); 50 | 51 | String querySql = "select * from " + stbName; 52 | ResultSet rs = statement.executeQuery(querySql); 53 | 54 | while (rs.next()) { 55 | String name = rs.getString(2); 56 | assertEquals("taosdata", name); 57 | } 58 | rs.close(); 59 | } 60 | 61 | @After 62 | public void close() throws SQLException { 63 | if (statement != null) { 64 | statement.execute("drop database if exists " + dbName); 65 | statement.close(); 66 | } 67 | if (connection != null) 68 | connection.close(); 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/QueryTimeoutTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.TSDBStatement; 4 | import com.taosdata.jdbc.utils.SpecifyAddress; 5 | import org.junit.Assert; 6 | import org.junit.Before; 7 | import org.junit.Ignore; 8 | import org.junit.Test; 9 | 10 | import java.sql.*; 11 | 12 | 13 | public class QueryTimeoutTest { 14 | private String host = "127.0.0.1"; 15 | private Connection conn; 16 | 17 | 18 | @Ignore 19 | @Test(expected = SQLTimeoutException.class) 20 | public void execute() throws SQLException { 21 | // given 22 | final int timeout = 1; 23 | final String sql = "show cluster alive"; 24 | TSDBStatement stmt = (TSDBStatement) conn.createStatement(); 25 | 26 | // when and Then 27 | stmt.setQueryTimeout(timeout); 28 | boolean hasResult = stmt.execute(sql); 29 | if (hasResult) { 30 | ResultSet rs = stmt.getResultSet(); 31 | ResultSetMetaData meta = rs.getMetaData(); 32 | while (rs.next()) { 33 | for (int i = 1; i <= meta.getColumnCount(); i++) { 34 | String value = rs.getString(i); 35 | Assert.assertEquals("status", meta.getColumnLabel(i)); 36 | Assert.assertTrue(value.equals("1") || value.equals("2")); 37 | } 38 | } 39 | } 40 | } 41 | 42 | @Before 43 | public void before() throws SQLException { 44 | String url = SpecifyAddress.getInstance().getJniWithoutUrl(); 45 | if (url == null) { 46 | url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; 47 | } 48 | conn = DriverManager.getConnection(url); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/ResetQueryCacheTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.utils.SpecifyAddress; 4 | import org.junit.Test; 5 | 6 | import java.sql.Connection; 7 | import java.sql.DriverManager; 8 | import java.sql.SQLException; 9 | import java.sql.Statement; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | import static org.junit.Assert.assertFalse; 13 | 14 | public class ResetQueryCacheTest { 15 | 16 | @Test 17 | public void jni() throws SQLException { 18 | // given 19 | String url = SpecifyAddress.getInstance().getJniUrl(); 20 | if (url == null) { 21 | url = "jdbc:TAOS://127.0.0.1:0/?user=root&password=taosdata&timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8"; 22 | } else { 23 | url += "&timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8"; 24 | } 25 | Connection connection = DriverManager.getConnection(url); 26 | Statement statement = connection.createStatement(); 27 | 28 | // when 29 | boolean execute = statement.execute("reset query cache"); 30 | 31 | // then 32 | assertFalse(execute); 33 | assertEquals(0, statement.getUpdateCount()); 34 | 35 | statement.close(); 36 | connection.close(); 37 | } 38 | 39 | @Test 40 | public void restful() throws SQLException { 41 | // given 42 | String url = SpecifyAddress.getInstance().getRestUrl(); 43 | if (url == null) { 44 | url = "jdbc:TAOS-RS://127.0.0.1:6041/?user=root&password=taosdata&timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8"; 45 | } else { 46 | url += "&timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8"; 47 | } 48 | Connection connection = DriverManager.getConnection(url); 49 | Statement statement = connection.createStatement(); 50 | 51 | // when 52 | boolean execute = statement.execute("reset query cache"); 53 | 54 | // then 55 | assertFalse(execute); 56 | assertEquals(0, statement.getUpdateCount()); 57 | 58 | statement.close(); 59 | connection.close(); 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/ResultSetMetaShouldNotBeNullRestfulTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.utils.SpecifyAddress; 4 | import com.taosdata.jdbc.utils.TestUtils; 5 | import org.junit.After; 6 | import org.junit.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import java.sql.*; 11 | 12 | public class ResultSetMetaShouldNotBeNullRestfulTest { 13 | 14 | private static final String host = "127.0.0.1"; 15 | private static final String dbname = TestUtils.camelToSnake(ResultSetMetaShouldNotBeNullRestfulTest.class); 16 | 17 | private Connection connection; 18 | 19 | @Test 20 | public void testExecuteQuery() throws SQLException { 21 | // given 22 | ResultSetMetaData metaData; 23 | int columnCount; 24 | 25 | // when 26 | Statement statement = connection.createStatement(); 27 | metaData = statement.executeQuery("select * from weather").getMetaData(); 28 | columnCount = metaData.getColumnCount(); 29 | 30 | // then 31 | Assert.assertNotNull(metaData); 32 | Assert.assertEquals(2, columnCount); 33 | } 34 | 35 | @Test 36 | public void testExecute() throws SQLException { 37 | // given 38 | ResultSetMetaData metaData; 39 | int columnCount; 40 | boolean execute; 41 | 42 | // when 43 | Statement statement = connection.createStatement(); 44 | execute = statement.execute("select * from weather"); 45 | metaData = statement.getResultSet().getMetaData(); 46 | columnCount = metaData.getColumnCount(); 47 | 48 | // then 49 | Assert.assertEquals(true, execute); 50 | Assert.assertNotNull(metaData); 51 | Assert.assertEquals(2, columnCount); 52 | } 53 | 54 | @Before 55 | public void before() throws SQLException { 56 | String url = SpecifyAddress.getInstance().getRestUrl(); 57 | if (url == null) { 58 | url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; 59 | } 60 | connection = DriverManager.getConnection(url); 61 | Statement stmt = connection.createStatement(); 62 | stmt.execute("drop database if exists " + dbname); 63 | stmt.execute("create database if not exists " + dbname); 64 | stmt.execute("use " + dbname); 65 | stmt.execute("create table weather (ts timestamp, temperature float)"); 66 | stmt.close(); 67 | } 68 | 69 | @After 70 | public void after() throws SQLException { 71 | Statement stmt = connection.createStatement(); 72 | stmt.execute("drop database if exists " + dbname); 73 | stmt.close(); 74 | connection.close(); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cases/SelectTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cases; 2 | 3 | import com.taosdata.jdbc.TSDBDriver; 4 | import com.taosdata.jdbc.utils.SpecifyAddress; 5 | import com.taosdata.jdbc.utils.TestUtils; 6 | import org.junit.After; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import java.sql.*; 11 | import java.util.Properties; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | 15 | public class SelectTest { 16 | Connection connection; 17 | String dbName = TestUtils.camelToSnake(SelectTest.class); 18 | String tName = "t0"; 19 | String host = "127.0.0.1"; 20 | 21 | @Before 22 | public void createDatabaseAndTable() throws SQLException { 23 | Properties properties = new Properties(); 24 | properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); 25 | properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); 26 | properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); 27 | properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); 28 | properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); 29 | String url = SpecifyAddress.getInstance().getJniWithoutUrl(); 30 | if (url == null) { 31 | url = "jdbc:TAOS://" + host + ":0/"; 32 | } 33 | connection = DriverManager.getConnection(url, properties); 34 | 35 | Statement stmt = connection.createStatement(); 36 | stmt.execute("drop database if exists " + dbName); 37 | stmt.execute("create database if not exists " + dbName); 38 | stmt.execute("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); 39 | stmt.close(); 40 | } 41 | 42 | @Test 43 | public void selectData() throws SQLException { 44 | long ts = 1496732686000l; 45 | 46 | try (Statement stmt = connection.createStatement()) { 47 | for (int i = 0; i < 50; i++) { 48 | ts++; 49 | int row = stmt.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")"); 50 | assertEquals(1, row); 51 | } 52 | 53 | String sql = "select * from " + dbName + "." + tName; 54 | ResultSet resSet = stmt.executeQuery(sql); 55 | 56 | int num = 0; 57 | while (resSet.next()) { 58 | num++; 59 | } 60 | resSet.close(); 61 | assertEquals(num, 50); 62 | } 63 | 64 | } 65 | 66 | @After 67 | public void close() throws SQLException { 68 | if (connection != null) { 69 | Statement stmt = connection.createStatement(); 70 | stmt.executeUpdate("drop database " + dbName); 71 | stmt.close(); 72 | connection.close(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cloud/CloudSchemalessNewTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cloud; 2 | 3 | import com.taosdata.jdbc.AbstractConnection; 4 | import com.taosdata.jdbc.confprops.HttpKeepAliveTest; 5 | import com.taosdata.jdbc.enums.SchemalessProtocolType; 6 | import com.taosdata.jdbc.enums.SchemalessTimestampType; 7 | import com.taosdata.jdbc.utils.TestUtils; 8 | import org.junit.Assert; 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | import java.sql.*; 13 | 14 | 15 | public class CloudSchemalessNewTest { 16 | String url = null; 17 | public static Connection connection; 18 | String dbName = "javatest"; 19 | 20 | @Before 21 | public void before() throws SQLException { 22 | url = System.getenv("TDENGINE_CLOUD_URL"); 23 | if (url == null || "".equals(url.trim())) { 24 | System.out.println("Environment variable for CloudTest not set properly"); 25 | return; 26 | } 27 | connection = DriverManager.getConnection(url); 28 | Statement statement = connection.createStatement(); 29 | statement.executeUpdate("use " + dbName); 30 | } 31 | 32 | @Test 33 | public void testLine() throws SQLException { 34 | if (url == null || "".equals(url.trim())) { 35 | return; 36 | } 37 | 38 | // given 39 | long cur_time = System.currentTimeMillis(); 40 | String[] lines = new String[]{ 41 | "st,t1=3i64,t2=4f64,t3=\"t3\",ts=" + cur_time + " c1=3i64,c3=L\"passit\",c2=false,c4=4f64 " + cur_time}; 42 | 43 | // when 44 | ((AbstractConnection)connection).write(lines, SchemalessProtocolType.LINE, SchemalessTimestampType.MILLI_SECONDS); 45 | // then 46 | Statement statement = connection.createStatement(); 47 | ResultSet rs = statement.executeQuery("select * from javatest.st order by _ts DESC limit 1"); 48 | Assert.assertNotNull(rs); 49 | ResultSetMetaData metaData = rs.getMetaData(); 50 | Assert.assertTrue(metaData.getColumnCount() > 0); 51 | while (rs.next()) { 52 | Assert.assertEquals(cur_time, rs.getLong("_ts")); 53 | } 54 | rs.close(); 55 | statement.close(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cloud/CloudSchemalessTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cloud; 2 | 3 | import com.taosdata.jdbc.SchemalessWriter; 4 | import com.taosdata.jdbc.enums.SchemalessProtocolType; 5 | import com.taosdata.jdbc.enums.SchemalessTimestampType; 6 | import com.taosdata.jdbc.utils.TestUtils; 7 | import org.junit.Assert; 8 | import org.junit.Before; 9 | import org.junit.Ignore; 10 | import org.junit.Test; 11 | 12 | import java.sql.*; 13 | 14 | @Ignore 15 | public class CloudSchemalessTest { 16 | String url = null; 17 | public static SchemalessWriter writer; 18 | public static Connection connection; 19 | String dbName = "javatest"; 20 | 21 | @Before 22 | public void before() throws SQLException { 23 | String url = System.getenv("TDENGINE_CLOUD_URL"); 24 | if (url == null || "".equals(url.trim())) { 25 | System.out.println("Environment variable for CloudTest not set properly"); 26 | return; 27 | } 28 | connection = DriverManager.getConnection(url); 29 | writer = new SchemalessWriter(url, null, null, dbName); 30 | } 31 | 32 | @Test 33 | public void testLine() throws SQLException { 34 | if (url == null || "".equals(url.trim())) { 35 | return; 36 | } 37 | 38 | // given 39 | long cur_time = System.currentTimeMillis(); 40 | String[] lines = new String[]{ 41 | "st,t1=3i64,t2=4f64,t3=\"t3\",ts=" + cur_time + " c1=3i64,c3=L\"passit\",c2=false,c4=4f64 " + cur_time}; 42 | 43 | // when 44 | writer.write(lines, SchemalessProtocolType.LINE, SchemalessTimestampType.MILLI_SECONDS); 45 | // then 46 | Statement statement = connection.createStatement(); 47 | statement.executeUpdate("use " + dbName); 48 | ResultSet rs = statement.executeQuery("select * from javatest.st order by _ts DESC limit 1"); 49 | Assert.assertNotNull(rs); 50 | ResultSetMetaData metaData = rs.getMetaData(); 51 | Assert.assertTrue(metaData.getColumnCount() > 0); 52 | while (rs.next()) { 53 | Assert.assertEquals(cur_time, rs.getLong("_ts")); 54 | } 55 | rs.close(); 56 | statement.close(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/cloud/CloudTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.cloud; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | import java.sql.*; 7 | import java.util.Arrays; 8 | import java.util.stream.Collectors; 9 | 10 | import static org.junit.Assert.assertNotEquals; 11 | 12 | public class CloudTest { 13 | String[] strings = {"abc", "涛思数据"}; 14 | String[] types = {"BINARY", "TIMESTAMP"}; 15 | 16 | @Test 17 | public void connectCloudService() throws Exception { 18 | 19 | String url = System.getenv("TDENGINE_CLOUD_URL"); 20 | if (url == null || "".equals(url.trim())) { 21 | System.out.println("Environment variable for CloudTest not set properly"); 22 | return; 23 | } 24 | 25 | Connection conn = DriverManager.getConnection(url); 26 | Statement stmt = conn.createStatement(); 27 | ResultSet rs = stmt.executeQuery("select server_version()"); 28 | rs.next(); 29 | String version = rs.getString(1); 30 | assertNotEquals(version, null); 31 | // stmt.execute("create database if not exists cloudtest"); 32 | // stmt.execute("create table if not exists cloudtest.t0(ts timestamp, c0 binary(20))"); 33 | stmt.execute("insert into javatest.t0 values(now, 'abc')(now+1s, '涛思数据')"); 34 | rs = stmt.executeQuery("select * from javatest.t0"); 35 | ResultSetMetaData meta = rs.getMetaData(); 36 | Assert.assertTrue(Arrays.stream(types).collect(Collectors.toSet()).contains(meta.getColumnTypeName(2))); 37 | while (rs.next()) { 38 | Assert.assertTrue(Arrays.stream(strings).collect(Collectors.toSet()).contains(rs.getString(2))); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.confprops; 2 | 3 | 4 | import com.taosdata.jdbc.TSDBDriver; 5 | import com.taosdata.jdbc.rs.RestfulResultSetMetaDataTest; 6 | import com.taosdata.jdbc.utils.SpecifyAddress; 7 | import com.taosdata.jdbc.utils.TestUtils; 8 | import org.junit.After; 9 | import org.junit.Before; 10 | import org.junit.Ignore; 11 | import org.junit.Test; 12 | 13 | import java.sql.Connection; 14 | import java.sql.DriverManager; 15 | import java.sql.SQLException; 16 | import java.sql.Statement; 17 | import java.util.Properties; 18 | 19 | @Ignore 20 | public class BadLocaleSettingTest { 21 | 22 | private static final String host = "127.0.0.1"; 23 | private static final String dbName = TestUtils.camelToSnake(BadLocaleSettingTest.class); 24 | private static Connection conn; 25 | 26 | @Test 27 | public void canSetLocale() throws SQLException { 28 | Properties properties = new Properties(); 29 | properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); 30 | properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); 31 | properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); 32 | 33 | String url = SpecifyAddress.getInstance().getJniUrl(); 34 | if (url == null) { 35 | url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; 36 | } 37 | conn = DriverManager.getConnection(url, properties); 38 | Statement stmt = conn.createStatement(); 39 | stmt.execute("drop database if exists " + dbName); 40 | stmt.execute("create database if not exists " + dbName); 41 | stmt.execute("use " + dbName); 42 | stmt.execute("drop table if exists weather"); 43 | stmt.execute("create table weather(ts timestamp, temperature float, humidity int)"); 44 | stmt.executeUpdate("insert into weather values(1624071506435, 12.3, 4)"); 45 | stmt.close(); 46 | } 47 | 48 | @Before 49 | public void beforeClass() { 50 | System.setProperty("sun.jnu.encoding", "ANSI_X3.4-1968"); 51 | System.setProperty("file.encoding", "ANSI_X3.4-1968"); 52 | } 53 | 54 | @After 55 | public void afterClass() throws SQLException { 56 | if (conn != null) { 57 | Statement statement = conn.createStatement(); 58 | statement.execute("drop database " + dbName); 59 | statement.close(); 60 | conn.close(); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.confprops; 2 | 3 | import com.taosdata.jdbc.TSDBDriver; 4 | import com.taosdata.jdbc.utils.SpecifyAddress; 5 | import com.taosdata.jdbc.utils.TestUtils; 6 | import org.junit.After; 7 | import org.junit.AfterClass; 8 | import org.junit.Assert; 9 | import org.junit.Test; 10 | 11 | import java.sql.*; 12 | import java.util.Properties; 13 | 14 | public class CharsetTest { 15 | private static final String host = "127.0.0.1"; 16 | private String dbName = TestUtils.camelToSnake(CharsetTest.class); 17 | 18 | @Test 19 | public void test() throws SQLException { 20 | // given 21 | String url = SpecifyAddress.getInstance().getJniUrl(); 22 | if (url == null) { 23 | url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; 24 | } 25 | Properties props = new Properties(); 26 | props.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); 27 | 28 | try (Connection conn = DriverManager.getConnection(url, props); 29 | Statement stmt = conn.createStatement()) { 30 | 31 | // when 32 | stmt.execute("drop database if exists " + dbName); 33 | stmt.execute("create database if not exists " + dbName); 34 | stmt.execute("use " + dbName); 35 | stmt.execute("create table weather(ts timestamp, temperature nchar(10))"); 36 | stmt.execute("insert into weather values(now, '北京')"); 37 | 38 | // then 39 | ResultSet rs = stmt.executeQuery("select * from weather"); 40 | while (rs.next()) { 41 | Object value = rs.getObject("temperature"); 42 | Assert.assertTrue(value instanceof String); 43 | Assert.assertEquals("北京", value.toString()); 44 | } 45 | } 46 | } 47 | 48 | @After 49 | public void afterClass(){ 50 | String url = SpecifyAddress.getInstance().getJniUrl(); 51 | if (url == null) { 52 | url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; 53 | } 54 | Properties props = new Properties(); 55 | props.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); 56 | 57 | try (Connection conn = DriverManager.getConnection(url, props); 58 | Statement stmt = conn.createStatement()) { 59 | stmt.execute("drop database if exists " + dbName); 60 | } catch (SQLException e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/confprops/TaosInfoMonitorTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.confprops; 2 | 3 | import com.taosdata.jdbc.utils.SpecifyAddress; 4 | import org.junit.Assert; 5 | import org.junit.Ignore; 6 | import org.junit.Test; 7 | 8 | import java.sql.*; 9 | import java.util.List; 10 | import java.util.Random; 11 | import java.util.concurrent.TimeUnit; 12 | import java.util.stream.Collectors; 13 | import java.util.stream.IntStream; 14 | 15 | @Ignore 16 | public class TaosInfoMonitorTest { 17 | 18 | private static final String host = "127.0.0.1"; 19 | private Random random = new Random(System.currentTimeMillis()); 20 | 21 | @Test 22 | public void testCreateTooManyConnection() throws InterruptedException { 23 | 24 | List threads = IntStream.range(1, 11).mapToObj(i -> new Thread(() -> { 25 | String url = SpecifyAddress.getInstance().getJniUrl(); 26 | if (url == null) { 27 | url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; 28 | } 29 | int connSize = random.nextInt(10); 30 | for (int j = 0; j < connSize; j++) { 31 | 32 | try { 33 | Connection conn = DriverManager.getConnection(url); 34 | TimeUnit.MILLISECONDS.sleep(random.nextInt(3000)); 35 | 36 | int stmtSize = random.nextInt(100); 37 | for (int k = 0; k < stmtSize; k++) { 38 | Statement stmt = conn.createStatement(); 39 | TimeUnit.MILLISECONDS.sleep(random.nextInt(3000)); 40 | 41 | ResultSet rs = stmt.executeQuery("show databases"); 42 | while (rs.next()) { 43 | } 44 | rs.close(); 45 | stmt.close(); 46 | } 47 | } catch (SQLException | InterruptedException throwables) { 48 | Assert.fail(); 49 | } 50 | } 51 | }, "thread-" + i)).collect(Collectors.toList()); 52 | 53 | threads.forEach(Thread::start); 54 | 55 | for (Thread thread : threads) { 56 | thread.join(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/rs/RestfulDriverTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.rs; 2 | 3 | import com.taosdata.jdbc.utils.SpecifyAddress; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | import java.sql.Driver; 8 | import java.sql.DriverPropertyInfo; 9 | import java.sql.SQLException; 10 | import java.sql.SQLFeatureNotSupportedException; 11 | 12 | public class RestfulDriverTest { 13 | private static final String host = "127.0.0.1"; 14 | 15 | @Test 16 | public void acceptsURL() throws SQLException { 17 | Driver driver = new RestfulDriver(); 18 | String url = SpecifyAddress.getInstance().getRestWithoutUrl(); 19 | if (url == null) { 20 | url = "jdbc:TAOS-RS://" + host + ":6041"; 21 | } 22 | boolean isAccept = driver.acceptsURL(url); 23 | Assert.assertTrue(isAccept); 24 | String specifyHost = SpecifyAddress.getInstance().getHost(); 25 | if (specifyHost == null) { 26 | url = "jdbc:TAOS://" + host + ":6041"; 27 | } else { 28 | url = "jdbc:TAOS://" + specifyHost + ":6041"; 29 | } 30 | isAccept = driver.acceptsURL(url); 31 | Assert.assertFalse(isAccept); 32 | } 33 | 34 | @Test 35 | public void getPropertyInfo() throws SQLException { 36 | Driver driver = new RestfulDriver(); 37 | final String url = ""; 38 | DriverPropertyInfo[] propertyInfo = driver.getPropertyInfo(url, null); 39 | Assert.assertNotNull(propertyInfo); 40 | } 41 | 42 | @Test 43 | public void getMajorVersion() { 44 | Assert.assertEquals(3, new RestfulDriver().getMajorVersion()); 45 | } 46 | 47 | @Test 48 | public void getMinorVersion() { 49 | Assert.assertEquals(0, new RestfulDriver().getMinorVersion()); 50 | } 51 | 52 | @Test 53 | public void jdbcCompliant() { 54 | Assert.assertFalse(new RestfulDriver().jdbcCompliant()); 55 | } 56 | 57 | @Test(expected = SQLFeatureNotSupportedException.class) 58 | public void getParentLogger() throws SQLFeatureNotSupportedException { 59 | new RestfulDriver().getParentLogger(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/rs/RestfulResponseCodeTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.rs; 2 | 3 | import com.taosdata.jdbc.TSDBErrorNumbers; 4 | import com.taosdata.jdbc.utils.SpecifyAddress; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | import java.sql.*; 9 | 10 | public class RestfulResponseCodeTest { 11 | private static final String host = "127.0.0.1"; 12 | 13 | @Test 14 | public void cloudTest() { 15 | String url = System.getenv("TDENGINE_CLOUD_URL"); 16 | if (url == null || "".equals(url.trim())) { 17 | System.out.println("Environment variable for CloudTest not set properly"); 18 | return; 19 | } 20 | 21 | url = url.substring(0, url.length() - 1); 22 | try (Connection connection = DriverManager.getConnection(url); 23 | Statement statement = connection.createStatement()) { 24 | statement.executeQuery("select 1"); 25 | } catch (SQLException e) { 26 | Assert.assertEquals(TSDBErrorNumbers.ERROR_CONNECTION_TIMEOUT, e.getErrorCode()); 27 | } 28 | } 29 | 30 | @Test 31 | public void taosAdapterTest() throws SQLException { 32 | String url = SpecifyAddress.getInstance().getRestUrl(); 33 | if (url == null) { 34 | url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; 35 | } 36 | try (Connection connection = DriverManager.getConnection(url); 37 | Statement statement = connection.createStatement()) { 38 | ResultSet rs = statement.executeQuery("select 1"); 39 | rs.next(); 40 | Assert.assertEquals(1, rs.getInt(1)); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/tmq/ResultBean.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | import java.nio.charset.StandardCharsets; 4 | import java.sql.Timestamp; 5 | 6 | public class ResultBean { 7 | private Timestamp ts; 8 | private int c1; 9 | private Float c2; 10 | private String c3; 11 | private byte[] c4; 12 | private Integer t1; 13 | private boolean c5; 14 | 15 | public Timestamp getTs() { 16 | return ts; 17 | } 18 | 19 | public void setTs(Timestamp ts) { 20 | this.ts = ts; 21 | } 22 | 23 | public int getC1() { 24 | return c1; 25 | } 26 | 27 | public void setC1(int c1) { 28 | this.c1 = c1; 29 | } 30 | 31 | public Float getC2() { 32 | return c2; 33 | } 34 | 35 | public void setC2(Float c2) { 36 | this.c2 = c2; 37 | } 38 | 39 | public String getC3() { 40 | return c3; 41 | } 42 | 43 | public void setC3(String c3) { 44 | this.c3 = c3; 45 | } 46 | 47 | public byte[] getC4() { 48 | return c4; 49 | } 50 | 51 | public void setC4(byte[] c4) { 52 | this.c4 = c4; 53 | } 54 | 55 | public Integer getT1() { 56 | return t1; 57 | } 58 | 59 | public void setT1(Integer t1) { 60 | this.t1 = t1; 61 | } 62 | 63 | public boolean isC5() { 64 | return c5; 65 | } 66 | 67 | public void setC5(boolean c5) { 68 | this.c5 = c5; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | final StringBuffer sb = new StringBuffer("ResultBean{"); 74 | sb.append("ts=").append(ts); 75 | sb.append(", c1=").append(c1); 76 | sb.append(", c2=").append(c2); 77 | sb.append(", c3='").append(c3).append('\''); 78 | sb.append(", c4="); 79 | if (c4 == null) sb.append("null"); 80 | else { 81 | sb.append("'").append(new String(c4, StandardCharsets.UTF_8)).append("'"); 82 | } 83 | sb.append(", t1=").append(t1); 84 | sb.append(", c5=").append(c5); 85 | sb.append('}'); 86 | return sb.toString(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/tmq/ResultDeserializer.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.tmq; 2 | 3 | public class ResultDeserializer extends ReferenceDeserializer { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/utils/InsertSqlPatternTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import com.taosdata.jdbc.ws.TSWSPreparedStatement; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | import java.util.regex.Matcher; 8 | 9 | public class InsertSqlPatternTest { 10 | String[] sqls = { 11 | "insert into st.pre values (?, ?)", 12 | "insert into st.pre (c1, c2) values (?, ?)", 13 | "insert into ? using st.pre tags(?) values (?, ?)", 14 | "insert into ? using st.pre tags(?)values(?, ?)", 15 | "insert into ? using st.pre (t1, t2) tags(?,?) values (?, ?)", 16 | "insert into ? using st.pre (t1, t2)tags(?,?)values (?, ?)", 17 | "insert into ? using st.pre (t1, t2) tags(?,?) (c1, c2) values(?, ?)", 18 | "insert into st.sub_t using db.sup_t (t1, t2) tags(?,?) (c1, c2) values(?, ?)", 19 | }; 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/utils/JsonUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | import java.text.SimpleDateFormat; 8 | 9 | public class JsonUtilTest { 10 | private static final ObjectMapper objectMapper = JsonUtil.getObjectMapper(); 11 | 12 | 13 | @Test 14 | public void testIgnoreUnknownProperties() throws Exception { 15 | String json = "{\"knownProperty\":\"value\", \"unknownProperty\":\"value\"}"; 16 | TestKnownPropertyClass result = objectMapper.readValue(json, TestKnownPropertyClass.class); 17 | Assert.assertEquals("value", result.knownProperty); 18 | } 19 | 20 | @Test 21 | public void testSerializationWithoutNull() throws Exception { 22 | TestNullPropertyClass testClass = new TestNullPropertyClass(); 23 | testClass.name = "John"; 24 | testClass.age = null; 25 | String json = objectMapper.writeValueAsString(testClass); 26 | Assert.assertFalse(json.contains("age")); 27 | } 28 | 29 | @Test 30 | public void testDateFormat() throws Exception { 31 | TestClassWithDate testClass = new TestClassWithDate(); 32 | testClass.date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2023-10-01 12:00:00"); 33 | String json = objectMapper.writeValueAsString(testClass); 34 | Assert.assertTrue(json.contains("\"date\":\"2023-10-01 12:00:00\"")); 35 | } 36 | 37 | @Test 38 | public void testJavaTimeModule() throws Exception { 39 | String json = "{\"localDateTime\":\"2023-10-01T12:00:00\"}"; 40 | TestClassWithJavaTime result = objectMapper.readValue(json, TestClassWithJavaTime.class); 41 | Assert.assertEquals("2023-10-01T12:00", result.localDateTime.toString()); 42 | } 43 | 44 | // 测试类 45 | static class TestKnownPropertyClass { 46 | public String knownProperty; 47 | } 48 | 49 | static class TestClassWithDate { 50 | public java.util.Date date; 51 | } 52 | 53 | static class TestClassWithArray { 54 | public String[] values; 55 | } 56 | 57 | static class TestClassWithJavaTime { 58 | public java.time.LocalDateTime localDateTime; 59 | } 60 | static class TestNullPropertyClass { 61 | public String name; 62 | public Integer age; 63 | } 64 | } -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/utils/OSUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Before; 5 | import org.junit.Test; 6 | 7 | public class OSUtilsTest { 8 | 9 | private String OS; 10 | 11 | @Test 12 | public void inWindows() { 13 | Assert.assertEquals(OS.contains("win"), OSUtils.isWindows()); 14 | } 15 | 16 | @Test 17 | public void isMac() { 18 | Assert.assertEquals(OS.contains("mac"), OSUtils.isMac()); 19 | } 20 | 21 | @Test 22 | public void isLinux() { 23 | Assert.assertEquals(OS.contains("nux"), OSUtils.isLinux()); 24 | } 25 | 26 | @Before 27 | public void before() { 28 | OS = System.getProperty("os.name").toLowerCase(); 29 | } 30 | } -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/utils/RuntimeUtils.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.InputStreamReader; 7 | 8 | /** 9 | * 10 | */ 11 | public class RuntimeUtils { 12 | 13 | /** 14 | * another method to get TDengine version,Local method run 'taos -V' 15 | * to help run getDatabaseProductVersion test case 16 | * @return 17 | */ 18 | public static String getLocalTDengineVersion() { 19 | Process proc = null; 20 | try { 21 | proc = Runtime.getRuntime().exec("taos -V"); 22 | } catch (IOException e) { 23 | throw new RuntimeException(e.getMessage()); 24 | } 25 | 26 | try (InputStream is = proc.getInputStream(); 27 | InputStreamReader isr = new InputStreamReader(is,"UTF-8"); 28 | BufferedReader br = new BufferedReader(isr)) { 29 | 30 | // just first line 31 | String output = br.readLine(); 32 | 33 | if (StringUtils.isEmpty(output)) { 34 | return ""; 35 | } 36 | 37 | String[] array = output.split("\\s+"); 38 | if (array == null || array.length != 2) { 39 | return ""; 40 | } 41 | 42 | return array[1]; 43 | } catch (IOException e) { 44 | e.printStackTrace(); 45 | } 46 | 47 | return null; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/utils/StringUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class StringUtilsTest { 7 | 8 | @Test 9 | public void isEmptyNull() { 10 | Assert.assertTrue(StringUtils.isEmpty(null)); 11 | } 12 | 13 | @Test 14 | public void isEmptyEmpty() { 15 | Assert.assertTrue(StringUtils.isEmpty("")); 16 | } 17 | 18 | @Test 19 | public void isNumericNull() { 20 | Assert.assertFalse(StringUtils.isNumeric(null)); 21 | } 22 | 23 | @Test 24 | public void isNumericEmpty() { 25 | Assert.assertFalse(StringUtils.isNumeric("")); 26 | } 27 | 28 | @Test 29 | public void isNumericStr() { 30 | Assert.assertFalse(StringUtils.isNumeric("abc")); 31 | } 32 | 33 | @Test 34 | public void isNumericNeg() { 35 | Assert.assertFalse(StringUtils.isNumeric("-21")); 36 | } 37 | 38 | @Test 39 | public void isNumericPoint() { 40 | Assert.assertFalse(StringUtils.isNumeric("2.15")); 41 | } 42 | 43 | @Test 44 | public void isNumeric() { 45 | Assert.assertTrue(StringUtils.isNumeric("61")); 46 | } 47 | 48 | @Test 49 | public void getBasicUrlTest() { 50 | Assert.assertEquals("jdbc:TAOS://localhost:6030/", StringUtils.getBasicUrl("jdbc:TAOS://localhost:6030/?user=root&password=taosdata")); 51 | Assert.assertEquals("jdbc:TAOS://localhost:6030/", StringUtils.getBasicUrl("jdbc:TAOS://localhost:6030/")); 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/utils/TestUtils.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import java.sql.Connection; 4 | import java.sql.ResultSet; 5 | import java.sql.SQLException; 6 | import java.sql.Statement; 7 | import java.util.Random; 8 | import java.util.UUID; 9 | import java.util.concurrent.atomic.AtomicInteger; 10 | 11 | public class TestUtils { 12 | private static AtomicInteger counter = new AtomicInteger(0); 13 | public static String camelToSnake(Class clazz) { 14 | String className = clazz.getSimpleName(); 15 | String temp = className.replaceAll("(?<=[a-z])([A-Z])", "_$1").toLowerCase(); 16 | return temp + counter.incrementAndGet(); 17 | } 18 | 19 | public static void waitTransactionDone(Connection connection) throws SQLException, InterruptedException{ 20 | while (true) { 21 | try (Statement statement = connection.createStatement()){ 22 | ResultSet resultSet = statement.executeQuery("show transactions"); 23 | if (resultSet.next()) { 24 | continue; 25 | } 26 | break; 27 | } catch (SQLException e) { 28 | Thread.sleep(1000); 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/utils/TimestampUtil.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | 7 | public class TimestampUtil { 8 | 9 | private static final String datetimeFormat = "yyyy-MM-dd HH:mm:ss.SSS"; 10 | 11 | public static long datetimeToLong(String dateTime) { 12 | SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat); 13 | try { 14 | return sdf.parse(dateTime).getTime(); 15 | } catch (ParseException e) { 16 | throw new IllegalArgumentException("invalid datetime string >>> " + dateTime); 17 | } 18 | } 19 | 20 | public static String longToDatetime(long time) { 21 | SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat); 22 | return sdf.format(new Date(time)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/utils/UInt64SerializerTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.utils; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.taosdata.jdbc.TSDBConstants; 5 | import com.taosdata.jdbc.ws.entity.FetchReq; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | public class UInt64SerializerTest { 10 | 11 | @Test 12 | public void write() throws JsonProcessingException { 13 | FetchReq fetchReq = new FetchReq(); 14 | fetchReq.setId(-1); 15 | fetchReq.setReqId(-1); 16 | 17 | // 使用 Jackson 将对象转换为 JSON 字符串 18 | String s = JsonUtil.getObjectWriter().writeValueAsString(fetchReq); 19 | Assert.assertTrue(s.contains(TSDBConstants.MAX_UNSIGNED_LONG)); 20 | 21 | // 使用 Jackson 将 JSON 字符串解析为对象 22 | FetchReq fetchReq1 = JsonUtil.getObjectReader(FetchReq.class).readValue(s); 23 | Assert.assertEquals(-1, fetchReq1.getId()); 24 | } 25 | } -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/ws/SchemaConnectTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | import com.taosdata.jdbc.SchemalessWriter; 4 | import com.taosdata.jdbc.utils.SpecifyAddress; 5 | import org.junit.AfterClass; 6 | import org.junit.BeforeClass; 7 | import org.junit.Test; 8 | 9 | import java.sql.Connection; 10 | import java.sql.DriverManager; 11 | import java.sql.SQLException; 12 | import java.sql.Statement; 13 | 14 | public class SchemaConnectTest { 15 | private static final String host = "127.0.0.1"; 16 | 17 | @Test 18 | public void testUrl() throws SQLException { 19 | String url = SpecifyAddress.getInstance().getRestUrl(); 20 | if (url == null) { 21 | url = "jdbc:TAOS-RS://" + host + ":6041/sml_test?user=root&password=taosdata"; 22 | } 23 | SchemalessWriter writer = new SchemalessWriter(url, null, null, null); 24 | } 25 | 26 | @Test 27 | public void testAllParam() throws SQLException { 28 | SchemalessWriter writer = new SchemalessWriter("127.0.0.1", "6041", "root", "taosdata", "sml_test", "ws"); 29 | } 30 | 31 | @BeforeClass 32 | public static void before() throws SQLException { 33 | String url = SpecifyAddress.getInstance().getRestUrl(); 34 | if (url == null) { 35 | url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; 36 | } 37 | 38 | try (Connection conn = DriverManager.getConnection(url); 39 | Statement statement = conn.createStatement()) { 40 | statement.executeUpdate("drop database if exists sml_test"); 41 | statement.executeUpdate("create database sml_test"); 42 | } 43 | } 44 | 45 | @AfterClass 46 | public static void after() throws SQLException { 47 | String url = SpecifyAddress.getInstance().getRestUrl(); 48 | if (url == null) { 49 | url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; 50 | } 51 | 52 | try (Connection conn = DriverManager.getConnection(url); 53 | Statement statement = conn.createStatement()) { 54 | statement.executeUpdate("drop database if exists sml_test"); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/ws/WSAppInfoTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | import com.taosdata.jdbc.TSDBDriver; 4 | import com.taosdata.jdbc.annotation.CatalogRunner; 5 | import com.taosdata.jdbc.annotation.TestTarget; 6 | import com.taosdata.jdbc.utils.SpecifyAddress; 7 | import org.junit.*; 8 | import org.junit.runner.RunWith; 9 | 10 | import java.sql.*; 11 | import java.util.Properties; 12 | 13 | @RunWith(CatalogRunner.class) 14 | @TestTarget(alias = "websocket query test", author = "huolibo", version = "2.0.38") 15 | @FixMethodOrder 16 | public class WSAppInfoTest { 17 | private static final String host = "127.0.0.1"; 18 | private static final int port = 6041; 19 | private Connection connection; 20 | private static final String appName = "jdbc_appName"; 21 | private static final String appIp = "192.168.1.1"; 22 | 23 | @Test 24 | public void AppInfoTest() throws SQLException, InterruptedException { 25 | 26 | for (int i = 0; i < 10; i++) { 27 | Thread.sleep(1000); 28 | try (Statement statement = connection.createStatement(); 29 | ResultSet resultSet = statement.executeQuery("show connections")) { 30 | while (resultSet.next()) { 31 | 32 | String name = resultSet.getString("user_app"); 33 | String ip = resultSet.getString("user_ip"); 34 | 35 | System.out.println("name: " + name + " ip: " + ip); 36 | if (appName.equals(name) 37 | && appIp.equals(ip)) { 38 | return; 39 | } 40 | } 41 | } catch (SQLException e) { 42 | e.printStackTrace(); 43 | throw e; 44 | } 45 | } 46 | Assert.fail("App info not found in show connections"); 47 | } 48 | 49 | @Before 50 | public void before() throws SQLException { 51 | String url = SpecifyAddress.getInstance().getRestWithoutUrl(); 52 | if (url == null) { 53 | url = "jdbc:TAOS-WS://" + host + ":" + port + "/?user=root&password=taosdata"; 54 | } else { 55 | url += "?user=root&password=taosdata"; 56 | } 57 | Properties properties = new Properties(); 58 | properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "Asia/Shanghai"); 59 | properties.setProperty(TSDBDriver.PROPERTY_KEY_APP_NAME, appName); 60 | properties.setProperty(TSDBDriver.PROPERTY_KEY_APP_IP, appIp); 61 | connection = DriverManager.getConnection(url, properties); 62 | } 63 | 64 | @After 65 | public void after() throws SQLException { 66 | if (null != connection) { 67 | connection.close(); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/ws/WSBigQueryTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | import com.taosdata.jdbc.utils.SpecifyAddress; 4 | import com.taosdata.jdbc.utils.TestUtils; 5 | import org.junit.*; 6 | 7 | import java.sql.*; 8 | import java.util.AbstractCollection; 9 | import java.util.Arrays; 10 | import java.util.HashSet; 11 | import java.util.Properties; 12 | 13 | @FixMethodOrder 14 | public class WSBigQueryTest { 15 | String host = "127.0.0.1"; 16 | String db_name = "ws_prepare"; 17 | String tableName = TestUtils.camelToSnake(WSBigQueryTest.class); 18 | String superTable = "wpt_st"; 19 | Connection connection; 20 | 21 | 22 | @Test 23 | public void testExecuteBatchInsert() throws SQLException { 24 | String sql = "insert into " + db_name + "." + tableName + " (ts, c1) values(?, ?)"; 25 | PreparedStatement statement = connection.prepareStatement(sql); 26 | HashSet collect = new HashSet<>(); 27 | 28 | for (int i = 0; i < 20000; i++) { 29 | collect.add(i); 30 | statement.setTimestamp(1, new Timestamp(System.currentTimeMillis() + i)); 31 | statement.setInt(2, i); 32 | statement.addBatch(); 33 | } 34 | statement.executeBatch(); 35 | 36 | String sql1 = "select * from " + db_name + "." + tableName; 37 | statement = connection.prepareStatement(sql1); 38 | boolean b = statement.execute(); 39 | Assert.assertTrue(b); 40 | ResultSet resultSet = statement.getResultSet(); 41 | while (resultSet.next()) { 42 | Assert.assertTrue(collect.contains(resultSet.getInt(2))); 43 | } 44 | statement.close(); 45 | } 46 | 47 | @Before 48 | public void before() throws SQLException { 49 | String url = SpecifyAddress.getInstance().getRestWithoutUrl(); 50 | if (url == null) { 51 | url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata&batchfetch=true"; 52 | } else { 53 | url += "?user=root&password=taosdata&batchfetch=true"; 54 | } 55 | Properties properties = new Properties(); 56 | connection = DriverManager.getConnection(url, properties); 57 | Statement statement = connection.createStatement(); 58 | statement.execute("drop database if exists " + db_name); 59 | statement.execute("create database " + db_name); 60 | statement.execute("use " + db_name); 61 | statement.execute("create table if not exists " + db_name + "." + tableName + " (ts timestamp, c1 int)"); 62 | statement.close(); 63 | } 64 | 65 | @After 66 | public void after() throws SQLException { 67 | try (Statement statement = connection.createStatement()) { 68 | statement.execute("drop database if exists " + db_name); 69 | } 70 | connection.close(); 71 | } 72 | } -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/ws/WSConsumerResultSetTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | import com.taosdata.jdbc.EmptyResultSet; 4 | import com.taosdata.jdbc.TSDBError; 5 | import com.taosdata.jdbc.TSDBErrorNumbers; 6 | import com.taosdata.jdbc.ws.tmq.WSConsumerResultSet; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | import java.sql.*; 11 | 12 | import static org.junit.Assert.*; 13 | public class WSConsumerResultSetTest { 14 | 15 | private WSConsumerResultSet wsConsumerResultSet; 16 | 17 | @Before 18 | public void setUp() { 19 | wsConsumerResultSet = new WSConsumerResultSet(null, null, 0, null, null); 20 | } 21 | 22 | @Test 23 | public void testIsBeforeFirst() throws SQLException { 24 | assertFalse(wsConsumerResultSet.isBeforeFirst()); 25 | } 26 | 27 | @Test 28 | public void testIsAfterLast() throws SQLException { 29 | assertFalse(wsConsumerResultSet.isAfterLast()); 30 | } 31 | 32 | @Test 33 | public void testIsFirst() throws SQLException { 34 | assertTrue(wsConsumerResultSet.isFirst()); 35 | } 36 | 37 | @Test 38 | public void testIsLast() throws SQLException { 39 | assertFalse(wsConsumerResultSet.isLast()); 40 | } 41 | 42 | @Test 43 | public void testBeforeFirst() throws SQLException { 44 | wsConsumerResultSet.beforeFirst(); 45 | } 46 | 47 | @Test 48 | public void testafterFirst() throws SQLException { 49 | wsConsumerResultSet.afterLast(); 50 | } 51 | 52 | @Test 53 | public void testFirst() throws SQLException { 54 | assertFalse(wsConsumerResultSet.first()); 55 | } 56 | 57 | 58 | @Test 59 | public void testLast() throws SQLException { 60 | assertFalse(wsConsumerResultSet.last()); 61 | } 62 | 63 | @Test 64 | public void testGetRow() throws SQLException { 65 | assertEquals(0, wsConsumerResultSet.getRow()); 66 | } 67 | 68 | @Test(expected = SQLException.class) 69 | public void testAbsolute() throws SQLException { 70 | wsConsumerResultSet.absolute(0); 71 | } 72 | 73 | @Test(expected = SQLException.class) 74 | public void testRelative() throws SQLException { 75 | wsConsumerResultSet.relative(0); 76 | } 77 | 78 | @Test(expected = SQLException.class) 79 | public void testPrevious() throws SQLException { 80 | wsConsumerResultSet.previous(); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/ws/WSMasterSlaveTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | import com.taosdata.jdbc.TSDBDriver; 4 | import com.taosdata.jdbc.TSDBErrorNumbers; 5 | import com.taosdata.jdbc.annotation.CatalogRunner; 6 | import com.taosdata.jdbc.annotation.Description; 7 | import com.taosdata.jdbc.annotation.TestTarget; 8 | import com.taosdata.jdbc.tmq.ResultBean; 9 | import com.taosdata.jdbc.tmq.TMQConstants; 10 | import com.taosdata.jdbc.tmq.TaosConsumer; 11 | import com.taosdata.jdbc.utils.SpecifyAddress; 12 | import org.junit.*; 13 | import org.junit.runner.RunWith; 14 | 15 | import java.sql.*; 16 | import java.util.Properties; 17 | 18 | @RunWith(CatalogRunner.class) 19 | @TestTarget(alias = "websocket query test", author = "yjshe", version = "2.0.38") 20 | @FixMethodOrder 21 | public class WSMasterSlaveTest { 22 | private static final String hostB = "vm95"; 23 | private static final int portB = 6041; 24 | 25 | @Description("consumer") 26 | @Test 27 | public void consumerException() { 28 | Properties properties = new Properties(); 29 | properties.setProperty(TMQConstants.CONNECT_USER, "root"); 30 | properties.setProperty(TMQConstants.CONNECT_PASS, "taosdata"); 31 | properties.setProperty(TMQConstants.BOOTSTRAP_SERVERS, "127.0.0.1:6041"); 32 | properties.setProperty(TSDBDriver.PROPERTY_KEY_SLAVE_CLUSTER_HOST, hostB); 33 | properties.setProperty(TSDBDriver.PROPERTY_KEY_SLAVE_CLUSTER_PORT, String.valueOf(portB)); 34 | 35 | properties.setProperty(TMQConstants.MSG_WITH_TABLE_NAME, "true"); 36 | properties.setProperty(TMQConstants.ENABLE_AUTO_COMMIT, "true"); 37 | properties.setProperty(TMQConstants.GROUP_ID, "ws_bean"); 38 | properties.setProperty(TMQConstants.VALUE_DESERIALIZER, "com.taosdata.jdbc.tmq.ResultDeserializer"); 39 | properties.setProperty(TMQConstants.CONNECT_TYPE, "ws"); 40 | 41 | try { 42 | TaosConsumer consumer = new TaosConsumer<>(properties); 43 | } 44 | catch (Exception e){ 45 | System.out.println(e.getMessage()); 46 | return; 47 | } 48 | Assert.fail(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/taosdata/jdbc/ws/WebSocketDriverTest.java: -------------------------------------------------------------------------------- 1 | package com.taosdata.jdbc.ws; 2 | 3 | import com.taosdata.jdbc.rs.RestfulDriver; 4 | import com.taosdata.jdbc.utils.SpecifyAddress; 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | import java.sql.Driver; 9 | import java.sql.DriverPropertyInfo; 10 | import java.sql.SQLException; 11 | import java.sql.SQLFeatureNotSupportedException; 12 | 13 | public class WebSocketDriverTest { 14 | private static final String host = "127.0.0.1"; 15 | 16 | @Test 17 | public void acceptsURL() throws SQLException { 18 | Driver driver = new WebSocketDriver(); 19 | String url = SpecifyAddress.getInstance().getWebSocketWithoutUrl(); 20 | if (url == null) { 21 | url = "jdbc:TAOS-WS://" + host + ":6041"; 22 | } 23 | boolean isAccept = driver.acceptsURL(url); 24 | Assert.assertTrue(isAccept); 25 | String specifyHost = SpecifyAddress.getInstance().getHost(); 26 | if (specifyHost == null) { 27 | url = "jdbc:TAOS://" + host + ":6041"; 28 | } else { 29 | url = "jdbc:TAOS://" + specifyHost + ":6041"; 30 | } 31 | isAccept = driver.acceptsURL(url); 32 | Assert.assertFalse(isAccept); 33 | } 34 | 35 | @Test 36 | public void getPropertyInfo() throws SQLException { 37 | Driver driver = new WebSocketDriver(); 38 | final String url = ""; 39 | DriverPropertyInfo[] propertyInfo = driver.getPropertyInfo(url, null); 40 | Assert.assertNotNull(propertyInfo); 41 | } 42 | 43 | @Test 44 | public void getMajorVersion() { 45 | Assert.assertEquals(3, new RestfulDriver().getMajorVersion()); 46 | } 47 | 48 | @Test 49 | public void getMinorVersion() { 50 | Assert.assertEquals(0, new RestfulDriver().getMinorVersion()); 51 | } 52 | 53 | @Test 54 | public void jdbcCompliant() { 55 | Assert.assertFalse(new RestfulDriver().jdbcCompliant()); 56 | } 57 | 58 | @Test(expected = SQLFeatureNotSupportedException.class) 59 | public void getParentLogger() throws SQLFeatureNotSupportedException { 60 | new WebSocketDriver().getParentLogger(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/resources/commons-logging.properties: -------------------------------------------------------------------------------- 1 | #org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog 2 | 3 | -------------------------------------------------------------------------------- /src/test/resources/simplelog.properties: -------------------------------------------------------------------------------- 1 | org.apache.commons.logging.simplelog.defaultlog=INFO 2 | org.apache.commons.logging.simplelog.showlogname=true 3 | org.apache.commons.logging.simplelog.showShortLogname=restful 4 | org.apache.commons.logging.simplelog.showdatetime=true 5 | org.apache.commons.logging.simplelog.dateTimeFormat=yyyy-mm-dd hh:MM:ss.SSS --------------------------------------------------------------------------------