diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 76cb0e0f31..9a84c79596 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -75,4 +75,4 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see -https://www.contributor-covenant.org/faq +https://www.contributor-covenant.org/faq diff --git a/cmake/taostools_CMakeLists.txt.in b/cmake/taostools_CMakeLists.txt.in deleted file mode 100644 index 9a6a5329ae..0000000000 --- a/cmake/taostools_CMakeLists.txt.in +++ /dev/null @@ -1,13 +0,0 @@ - -# taos-tools -ExternalProject_Add(taos-tools - GIT_REPOSITORY https://github.com/taosdata/taos-tools.git - GIT_TAG 3.0 - SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools" - BINARY_DIR "" - #BUILD_IN_SOURCE TRUE - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" -) diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index b2729ed7a7..745dc01cf6 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -205,9 +205,18 @@ ENDIF() # download dependencies configure_file(${CONTRIB_TMP_FILE} "${TD_CONTRIB_DIR}/deps-download/CMakeLists.txt") execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" . - WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download") + WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download" + RESULT_VARIABLE result) +IF(NOT result EQUAL "0") + message(FATAL_ERROR "CMake step for dowloading dependencies failed: ${result}") +ENDIF() + execute_process(COMMAND "${CMAKE_COMMAND}" --build . - WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download") + WORKING_DIRECTORY "${TD_CONTRIB_DIR}/deps-download" + RESULT_VARIABLE result) +IF(NOT result EQUAL "0") + message(FATAL_ERROR "CMake step for building dependencies failed: ${result}") +ENDIF() # ================================================================================================ # Build diff --git a/docs/en/07-develop/07-tmq.md b/docs/en/07-develop/07-tmq.md index e556dc5f37..6b92ace6a2 100644 --- a/docs/en/07-develop/07-tmq.md +++ b/docs/en/07-develop/07-tmq.md @@ -31,12 +31,12 @@ There are many parameters for creating consumers, which flexibly support various | Parameter Name | Type | Description | Remarks | | :-----------------------: | :-----: | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `td.connect.ip` | string | Server IP address | | +| `td.connect.ip` | string | FQDN of Server | ip or host name | | `td.connect.user` | string | Username | | | `td.connect.pass` | string | Password | | | `td.connect.port` | integer | Server port number | | -| `group.id` | string | Consumer group ID, the same consumer group shares consumption progress |
**Required**. Maximum length: 192.
Each topic can have up to 100 consumer groups | -| `client.id` | string | Client ID | Maximum length: 192 | +| `group.id` | string | Consumer group ID, the same consumer group shares consumption progress |
**Required**. Maximum length: 192,excess length will be cut off.
Each topic can have up to 100 consumer groups | +| `client.id` | string | Client ID | Maximum length: 255, excess length will be cut off. | | `auto.offset.reset` | enum | Initial position of the consumer group subscription |
`earliest`: default(version < 3.2.0.0); subscribe from the beginning;
`latest`: default(version >= 3.2.0.0); only subscribe from the latest data;
`none`: cannot subscribe without a committed offset | | `enable.auto.commit` | boolean | Whether to enable automatic consumption point submission, true: automatic submission, client application does not need to commit; false: client application needs to commit manually | Default is true | | `auto.commit.interval.ms` | integer | Time interval for automatically submitting consumption records, in milliseconds | Default is 5000 | diff --git a/docs/en/08-operation/09-backup.md b/docs/en/08-operation/09-backup.md index 6457719d88..ee0a56c497 100644 --- a/docs/en/08-operation/09-backup.md +++ b/docs/en/08-operation/09-backup.md @@ -1,14 +1,19 @@ --- title: Data Backup and Restoration -slug: /operations-and-maintenance/back-up-and-restore-data +slug: /operations-and-maintenance/data-backup-and-restoration --- -To prevent data loss and accidental deletions, TDengine provides comprehensive features such as data backup, restoration, fault tolerance, and real-time synchronization of remote data to ensure the security of data storage. This section briefly explains the backup and restoration functions. +import Image from '@theme/IdealImage'; +import imgBackup from '../assets/data-backup-01.png'; + +You can back up the data in your TDengine cluster and restore it in the event that data is lost or damaged. ## Data Backup and Restoration Using taosdump taosdump is an open-source tool that supports backing up data from a running TDengine cluster and restoring the backed-up data to the same or another running TDengine cluster. taosdump can back up the database as a logical data unit or back up data records within a specified time period in the database. When using taosdump, you can specify the directory path for data backup. If no directory path is specified, taosdump will default to backing up the data in the current directory. +### Back Up Data with taosdump + Below is an example of using taosdump to perform data backup. ```shell @@ -19,6 +24,8 @@ After executing the above command, taosdump will connect to the TDengine cluster When using taosdump, if the specified storage path already contains data files, taosdump will prompt the user and exit immediately to avoid data overwriting. This means the same storage path can only be used for one backup. If you see related prompts, please operate carefully to avoid accidental data loss. +### Restore Data with taosdump + To restore data files from a specified local file path to a running TDengine cluster, you can execute the taosdump command by specifying command-line parameters and the data file path. Below is an example code for taosdump performing data restoration. ```shell @@ -27,25 +34,62 @@ taosdump -i /file/path -h localhost -P 6030 After executing the above command, taosdump will connect to the TDengine cluster at localhost:6030 and restore the data files from /file/path to the TDengine cluster. -## Data Backup and Restoration Based on TDengine Enterprise +## Data Backup and Restoration in TDengine Enterprise -TDengine Enterprise provides an efficient incremental backup feature, with the following process. +TDengine Enterprise implements incremental backup and recovery of data by using data subscription. The backup and recovery functions of TDengine Enterprise include the following concepts: -Step 1, access the taosExplorer service through a browser, usually at the port 6060 of the IP address where the TDengine cluster is located, such as `http://localhost:6060`. +1. Incremental data backup: Based on TDengine's data subscription function, all data changes of **the backup object** (including: addition, modification, deletion, metadata change, etc.) are recorded to generate a backup file. +2. Data recovery: Use the backup file generated by incremental data backup to restore **the backup object** to a specified point in time. +3. Backup object: The object that the user backs up can be a **database** or a **supertable**. +4. Backup plan: The user creates a periodic backup task for the backup object. The backup plan starts at a specified time point and periodically executes the backup task at intervals of **the backup cycle. Each backup task generates a** **backup point** . +5. Backup point: Each time a backup task is executed, a set of backup files is generated. They correspond to a time point, called **a backup point** . The first backup point is called **the initial backup point** . +6. Restore task: The user selects a backup point in the backup plan and creates a restore task. The restore task starts from **the initial backup point** and plays back the data changes in **the backup file** one by one until the specified backup point ends. -Step 2, in the "System Management - Backup" page of the taosExplorer service, add a new data backup task, fill in the database name and backup storage file path in the task configuration information, and start the data backup after completing the task creation. Three parameters can be configured on the data backup configuration page: +### Incremental Backup Example -- Backup cycle: Required, configure the time interval for each data backup execution, which can be selected from a dropdown menu to execute once every day, every 7 days, or every 30 days. After configuration, a data backup task will be initiated at 0:00 of the corresponding backup cycle; -- Database: Required, configure the name of the database to be backed up (the database's wal_retention_period parameter must be greater than 0); -- Directory: Required, configure the path in the running environment of taosX where the data will be backed up, such as `/root/data_backup`; +
+Incremental backup process +
Figure 1. Incremental backup process
+
-Step 3, after the data backup task is completed, find the created data backup task in the list of created tasks on the same page, and directly perform one-click restoration to restore the data to TDengine. +1. The user creates a backup plan to execute the backup task every 1 day starting from 2024-08-27 00:00:00 . +2. The first backup task was executed at 2024-08-27 00:00:00, generating an initial backup point . +3. After that, the backup task is executed every 1 day, and multiple backup points are generated . +4. Users can select a backup point and create a restore task . +5. The restore task starts from the initial backup point, applies the backup points one by one, and restores to the specified backup point. -Compared to taosdump, if the same data is backed up multiple times in the specified storage path, since TDengine Enterprise not only has high backup efficiency but also implements incremental processing, each backup task will be completed quickly. As taosdump always performs full backups, TDengine Enterprise can significantly reduce system overhead in scenarios with large data volumes and is more convenient. +### Back Up Data in TDengine Enterprise -**Common Error Troubleshooting** +1. In a web browser, open the taosExplorer interface for TDengine. This interface is located on port 6060 on the hostname or IP address running TDengine. +2. In the main menu on the left, click **Management** and open the **Backup** tab. +3. Under **Backup Plan**, click **Create New Backup** to define your backup plan. + 1. **Database:** Select the database that you want to backup. + 2. **Super Table:** (Optional) Select the supertable that you want to backup. If you do not select a supertable, all data in the database is backed up. + 3. **Next execution time:** Enter the date and time when you want to perform the initial backup for this backup plan. If you specify a date and time in the past, the initial backup is performed immediately. + 4. **Backup Cycle:** Specify how often you want to perform incremental backups. The value of this field must be less than the value of `WAL_RETENTION_PERIOD` for the specified database. + 5. **Retry times:** Enter how many times you want to retry a backup task that has failed, provided that the specific failure might be resolved by retrying. + 6. **Retry interval:** Enter the delay in seconds between retry attempts. + 7. **Directory:** Enter the full path of the directory in which you want to store backup files. + 8. **Backup file max size:** Enter the maximum size of a single backup file. If the total size of your backup exceeds this number, the backup is split into multiple files. + 9. **Compression level:** Select **fastest** for the fastest performance but lowest compression ratio, **best** for the highest compression ratio but slowest performance, or **balanced** for a combination of performance and compression. -1. If the task fails to start and reports the following error: +4. Click **Confirm** to create the backup plan. + +You can view your backup plans and modify, clone, or delete them using the buttons in the **Operation** columns. Click **Refresh** to update the status of your plans. Note that you must stop a backup plan before you can delete it. You can also click **View** in the **Backup File** column to view the backup record points and files created by each plan. + +### Restore Data in TDengine Enterprise + +1. Locate the backup plan containing data that you want to restore and click **View** in the **Backup File** column. +2. Determine the backup record point to which you want to restore and click the Restore icon in the **Operation** column. +3. Select the backup file timestamp and target database and click **Confirm**. + + + +## Troubleshooting + +### Port Access Exception + +A port access exception is indicated by the following error: ```text Error: tmq to td task exec error @@ -54,9 +98,11 @@ Caused by: [0x000B] Unable to establish connection ``` -The cause is an abnormal connection to the data source port, check whether the data source FQDN is connected and whether port 6030 is accessible. +If you encounter this error, check whether the data source FQDN is connected and whether port 6030 is listening and accessible. -2. If using a WebSocket connection, the task fails to start and reports the following error: +### Connection Issues + +A connection issue is indicated by the task failing to start and reporting the following error: ```text Error: tmq to td task exec error @@ -67,15 +113,16 @@ Caused by: 2: failed to lookup address information: Temporary failure in name resolution ``` -When using a WebSocket connection, you may encounter various types of errors, which can be seen after "Caused by". Here are some possible errors: +The following are some possible errors for WebSocket connections: +- "Temporary failure in name resolution": DNS resolution error. Check whether the specified IP address or FQDN can be accessed normally. +- "IO error: Connection refused (os error 111)": Port access failed. Check whether the port is configured correctly and is enabled and accessible. +- "IO error: received corrupt message": Message parsing failed. This may be because SSL was enabled using the WSS method, but the source port is not supported. +- "HTTP error: *": Confirm that you are connecting to the correct taosAdapter port and that your LSB/Nginx/Proxy has been configured correctly. +- "WebSocket protocol error: Handshake not finished": WebSocket connection error. This is typically caused by an incorrectly configured port. -- "Temporary failure in name resolution": DNS resolution error, check if the IP or FQDN can be accessed normally. -- "IO error: Connection refused (os error 111)": Port access failure, check if the port is configured correctly or if it is open and accessible. -- "IO error: received corrupt message": Message parsing failed, possibly because SSL was enabled using wss, but the source port does not support it. -- "HTTP error: *": Possibly connected to the wrong taosAdapter port or incorrect LSB/Nginx/Proxy configuration. -- "WebSocket protocol error: Handshake not finished": WebSocket connection error, usually because the configured port is incorrect. +### WAL Configuration -3. If the task fails to start and reports the following error: +A WAL configuration issue is indicated by the task failing to start and reporting the following error: ```text Error: tmq to td task exec error @@ -84,11 +131,8 @@ Caused by: [0x038C] WAL retention period is zero ``` -This is due to incorrect WAL configuration in the source database, preventing subscription. - -Solution: -Modify the data WAL configuration: +To resolve this error, modify the WAL retention period for the affected database: ```sql -alter database test wal_retention_period 3600; +ALTER DATABASE test WAL_RETENTION_PERIOD 3600; ``` diff --git a/docs/en/28-releases/03-notes/index.md b/docs/en/28-releases/03-notes/index.md index 5ff7350e6c..8e89765865 100644 --- a/docs/en/28-releases/03-notes/index.md +++ b/docs/en/28-releases/03-notes/index.md @@ -3,13 +3,9 @@ title: Release Notes slug: /release-history/release-notes --- -[3.3.5.0](./3-3-5-0/) +```mdx-code-block +import DocCardList from '@theme/DocCardList'; +import {useCurrentSidebarCategory} from '@docusaurus/theme-common'; -[3.3.5.2](./3.3.5.2) -[3.3.4.8](./3-3-4-8/) - -[3.3.4.3](./3-3-4-3/) - -[3.3.3.0](./3-3-3-0/) - -[3.3.2.0](./3-3-2-0/) + +``` \ No newline at end of file diff --git a/docs/en/assets/data-backup-01.png b/docs/en/assets/data-backup-01.png new file mode 100644 index 0000000000..b05c571f6c Binary files /dev/null and b/docs/en/assets/data-backup-01.png differ diff --git a/docs/examples/JDBC/mybatisplus-demo/pom.xml b/docs/examples/JDBC/mybatisplus-demo/pom.xml index 322842ea3e..30b3f7792b 100644 --- a/docs/examples/JDBC/mybatisplus-demo/pom.xml +++ b/docs/examples/JDBC/mybatisplus-demo/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 2.4.0 + 2.7.18 com.taosdata.example @@ -18,6 +18,18 @@ 1.8 + + + + com.baomidou + mybatis-plus-bom + 3.5.10.1 + pom + import + + + + org.springframework.boot @@ -28,14 +40,21 @@ lombok true + com.baomidou mybatis-plus-boot-starter - 3.1.2 + + + + + com.baomidou + mybatis-plus-jsqlparser-4.9 com.h2database h2 + 2.3.232 runtime diff --git a/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/config/MybatisPlusConfig.java b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/config/MybatisPlusConfig.java index a6ac7f7fc2..f7c57e031d 100644 --- a/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/config/MybatisPlusConfig.java +++ b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/config/MybatisPlusConfig.java @@ -1,34 +1,26 @@ package com.taosdata.example.mybatisplusdemo.config; -import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; +@EnableTransactionManagement @Configuration +@MapperScan("com.taosdata.example.mybatisplusdemo.mapper") public class MybatisPlusConfig { - - /** mybatis 3.4.1 pagination config start ***/ -// @Bean -// public MybatisPlusInterceptor mybatisPlusInterceptor() { -// MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); -// interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); -// return interceptor; -// } - -// @Bean -// public ConfigurationCustomizer configurationCustomizer() { -// return configuration -> configuration.setUseDeprecatedExecutor(false); -// } - + /** + * 添加分页插件 + */ @Bean - public PaginationInterceptor paginationInterceptor() { -// return new PaginationInterceptor(); - PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); - //TODO: mybatis-plus do not support TDengine, use postgresql Dialect - paginationInterceptor.setDialectType("postgresql"); - - return paginationInterceptor; + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + return interceptor; } - } diff --git a/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/MetersMapper.java b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/MetersMapper.java index 441c340886..f3eab76d8c 100644 --- a/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/MetersMapper.java +++ b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/MetersMapper.java @@ -5,6 +5,7 @@ import com.taosdata.example.mybatisplusdemo.domain.Meters; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Update; +import org.apache.ibatis.executor.BatchResult; import java.util.List; @@ -15,17 +16,6 @@ public interface MetersMapper extends BaseMapper { @Insert("insert into meters (tbname, ts, groupid, location, current, voltage, phase) values(#{tbname}, #{ts}, #{groupid}, #{location}, #{current}, #{voltage}, #{phase})") int insertOne(Meters one); - - @Insert({ - "" - }) - int insertBatch(@Param("list") List metersList); - @Update("drop stable if exists meters") void dropTable(); } diff --git a/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapper.java b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapper.java index 3e122524d5..a43a40a89e 100644 --- a/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapper.java +++ b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapper.java @@ -11,9 +11,6 @@ public interface TemperatureMapper extends BaseMapper { @Update("CREATE TABLE if not exists temperature(ts timestamp, temperature float) tags(location nchar(64), tbIndex int)") int createSuperTable(); - @Update("create table #{tbName} using temperature tags( #{location}, #{tbindex})") - int createTable(@Param("tbName") String tbName, @Param("location") String location, @Param("tbindex") int tbindex); - @Update("drop table if exists temperature") void dropSuperTable(); diff --git a/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapper.java b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapper.java index 1f0338db34..04d26202a0 100644 --- a/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapper.java +++ b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapper.java @@ -10,7 +10,7 @@ public interface WeatherMapper extends BaseMapper { @Update("CREATE TABLE if not exists weather(ts timestamp, temperature float, humidity int, location nchar(100))") int createTable(); - @Insert("insert into weather (ts, temperature, humidity, location) values(#{ts}, #{temperature}, #{humidity}, #{location})") + @Insert("insert into weather (ts, temperature, humidity, location) values(#{ts}, #{temperature}, #{humidity}, #{location, jdbcType=NCHAR})") int insertOne(Weather one); @Update("drop table if exists weather") diff --git a/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/service/DatabaseConnectionService.java b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/service/DatabaseConnectionService.java new file mode 100644 index 0000000000..1c1a62cee5 --- /dev/null +++ b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/service/DatabaseConnectionService.java @@ -0,0 +1,19 @@ +package com.taosdata.example.mybatisplusdemo.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; + +@Service +public class DatabaseConnectionService { + + @Autowired + private DataSource dataSource; + + public Connection getConnection() throws SQLException { + return dataSource.getConnection(); + } +} diff --git a/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/service/TemperatureService.java b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/service/TemperatureService.java new file mode 100644 index 0000000000..6b81eac479 --- /dev/null +++ b/docs/examples/JDBC/mybatisplus-demo/src/main/java/com/taosdata/example/mybatisplusdemo/service/TemperatureService.java @@ -0,0 +1,23 @@ +package com.taosdata.example.mybatisplusdemo.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +@Service +public class TemperatureService { + @Autowired + private DatabaseConnectionService databaseConnectionService; + + public void createTable(String tableName, String location, int tbIndex) throws SQLException { + + + try (Connection connection = databaseConnectionService.getConnection(); + Statement statement = connection.createStatement()) { + statement.executeUpdate("create table " + tableName + " using temperature tags( '" + location +"', " + tbIndex + ")"); + } + } +} diff --git a/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/MetersMapperTest.java b/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/MetersMapperTest.java index 2d8458e9d9..8405777ab0 100644 --- a/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/MetersMapperTest.java +++ b/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/MetersMapperTest.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.taosdata.example.mybatisplusdemo.domain.Meters; import com.taosdata.example.mybatisplusdemo.domain.Weather; +import org.apache.ibatis.executor.BatchResult; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -18,6 +19,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Random; +import static java.sql.Statement.SUCCESS_NO_INFO; + @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class MetersMapperTest { @@ -63,8 +66,19 @@ public class MetersMapperTest { metersList.add(one); } - int affectRows = mapper.insertBatch(metersList); - Assert.assertEquals(100, affectRows); + List affectRowsList = mapper.insert(metersList, 10000); + + long totalAffectedRows = 0; + for (BatchResult batchResult : affectRowsList) { + int[] updateCounts = batchResult.getUpdateCounts(); + for (int status : updateCounts) { + if (status == SUCCESS_NO_INFO) { + totalAffectedRows++; + } + } + } + + Assert.assertEquals(100, totalAffectedRows); } @Test @@ -93,7 +107,7 @@ public class MetersMapperTest { @Test public void testSelectCount() { - int count = mapper.selectCount(null); + long count = mapper.selectCount(null); // Assert.assertEquals(5, count); System.out.println(count); } diff --git a/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapperTest.java b/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapperTest.java index 4d9dbf8d2f..016466ffec 100644 --- a/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapperTest.java +++ b/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/TemperatureMapperTest.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.taosdata.example.mybatisplusdemo.domain.Temperature; +import com.taosdata.example.mybatisplusdemo.service.TemperatureService; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -13,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Timestamp; import java.util.HashMap; import java.util.List; @@ -22,18 +25,20 @@ import java.util.Random; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class TemperatureMapperTest { + @Autowired + private TemperatureService temperatureService; private static Random random = new Random(System.currentTimeMillis()); private static String[] locations = {"北京", "上海", "深圳", "广州", "杭州"}; @Before - public void before() { + public void before() throws SQLException { mapper.dropSuperTable(); // create table temperature mapper.createSuperTable(); // create table t_X using temperature for (int i = 0; i < 10; i++) { - mapper.createTable("t" + i, locations[random.nextInt(locations.length)], i); + temperatureService.createTable("t" + i, locations[i % locations.length], i); } // insert into table int affectRows = 0; @@ -107,7 +112,7 @@ public class TemperatureMapperTest { * **/ @Test public void testSelectCount() { - int count = mapper.selectCount(null); + long count = mapper.selectCount(null); Assert.assertEquals(10, count); } diff --git a/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java b/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java index dba8abd1ed..19f2e70f3d 100644 --- a/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java +++ b/docs/examples/JDBC/mybatisplus-demo/src/test/java/com/taosdata/example/mybatisplusdemo/mapper/WeatherMapperTest.java @@ -52,7 +52,7 @@ public class WeatherMapperTest { one.setTemperature(random.nextFloat() * 50); one.setHumidity(random.nextInt(100)); one.setLocation("望京"); - int affectRows = mapper.insert(one); + int affectRows = mapper.insertOne(one); Assert.assertEquals(1, affectRows); } @@ -82,7 +82,7 @@ public class WeatherMapperTest { @Test public void testSelectCount() { - int count = mapper.selectCount(null); + long count = mapper.selectCount(null); // Assert.assertEquals(5, count); System.out.println(count); } diff --git a/docs/examples/JDBC/springbootdemo/pom.xml b/docs/examples/JDBC/springbootdemo/pom.xml index ed8c66544a..098f3d1f39 100644 --- a/docs/examples/JDBC/springbootdemo/pom.xml +++ b/docs/examples/JDBC/springbootdemo/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 2.6.15 + 2.7.18 com.taosdata.example @@ -34,7 +34,7 @@ org.mybatis.spring.boot mybatis-spring-boot-starter - 2.1.1 + 2.3.2 diff --git a/docs/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml b/docs/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml index 4899ec4654..c142031e97 100644 --- a/docs/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml +++ b/docs/examples/JDBC/springbootdemo/src/main/java/com/taosdata/example/springbootdemo/dao/WeatherMapper.xml @@ -50,13 +50,6 @@ ), groupId int) - - create table if not exists test.t#{groupId} using test.weather tags - ( - #{location}, - #{groupId} - ) - - insert into test.t#{groupId} (ts, temperature, humidity, note, bytes) - values (#{ts}, ${temperature}, ${humidity}, #{note}, #{bytes}) + insert into test.t${groupId} (ts, temperature, humidity, note, bytes) + values (#{ts}, #{temperature}, #{humidity}, #{note}, #{bytes})