update spring version, improve demo code
This commit is contained in:
parent
9468216991
commit
4ea40116d2
|
@ -22,19 +22,19 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>5.2.8.RELEASE</version>
|
||||
<version>5.3.39</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-jdbc</artifactId>
|
||||
<version>5.1.9.RELEASE</version>
|
||||
<version>5.3.39</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>5.1.9.RELEASE</version>
|
||||
<version>5.3.39</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -47,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.4.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.1.RELEASE</version>
|
||||
<version>2.6.15</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.taosdata.example</groupId>
|
||||
|
@ -65,6 +65,8 @@
|
|||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
|
|
|
@ -3,9 +3,10 @@ package com.taosdata.example.springbootdemo;
|
|||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.data.jdbc.JdbcRepositoriesAutoConfiguration;
|
||||
|
||||
@MapperScan(basePackages = {"com.taosdata.example.springbootdemo"})
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(exclude = {JdbcRepositoriesAutoConfiguration.class})
|
||||
public class SpringbootdemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -15,6 +15,8 @@ spring.datasource.druid.max-wait=30000
|
|||
spring.datasource.druid.validation-query=select SERVER_VERSION();
|
||||
spring.aop.auto=true
|
||||
spring.aop.proxy-target-class=true
|
||||
|
||||
spring.jooq.sql-dialect=
|
||||
#mybatis
|
||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||
logging.level.com.taosdata.jdbc.springbootdemo.dao=debug
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<description>Demo project for TDengine</description>
|
||||
|
||||
<properties>
|
||||
<spring.version>5.3.27</spring.version>
|
||||
<spring.version>5.3.39</spring.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -130,6 +130,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
|
|
|
@ -37,7 +37,7 @@ public class QueryService {
|
|||
stmt.execute("use " + dbName);
|
||||
ResultSet rs = stmt.executeQuery("show stables");
|
||||
while (rs.next()) {
|
||||
String name = rs.getString("name");
|
||||
String name = rs.getString("stable_name");
|
||||
sqls.add("select count(*) from " + dbName + "." + name);
|
||||
sqls.add("select first(*) from " + dbName + "." + name);
|
||||
sqls.add("select last(*) from " + dbName + "." + name);
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package com.taosdata.taosdemo.service;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class DatabaseServiceTest {
|
||||
private DatabaseService service;
|
||||
|
||||
private static DatabaseService service;
|
||||
|
||||
@Test
|
||||
public void testCreateDatabase1() {
|
||||
|
@ -20,4 +24,16 @@ public class DatabaseServiceTest {
|
|||
public void useDatabase() {
|
||||
service.useDatabase("test");
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws ClassNotFoundException {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setJdbcUrl("jdbc:TAOS://127.0.0.1:6030/?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8");
|
||||
config.setUsername("root");
|
||||
config.setPassword("taosdata");
|
||||
HikariDataSource dataSource = new HikariDataSource(config);
|
||||
service = new DatabaseService(dataSource);
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ public class QueryServiceTest {
|
|||
|
||||
@Test
|
||||
public void generateSuperTableQueries() {
|
||||
String[] sqls = queryService.generateSuperTableQueries("restful_test");
|
||||
String[] sqls = queryService.generateSuperTableQueries("test");
|
||||
for (String sql : sqls) {
|
||||
System.out.println(sql);
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ public class QueryServiceTest {
|
|||
|
||||
@Test
|
||||
public void querySuperTable() {
|
||||
String[] sqls = queryService.generateSuperTableQueries("restful_test");
|
||||
queryService.querySuperTable(sqls, 1000, 10, 10);
|
||||
String[] sqls = queryService.generateSuperTableQueries("test");
|
||||
queryService.querySuperTable(sqls, 100, 3, 3);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
|
|
|
@ -3,6 +3,9 @@ package com.taosdata.taosdemo.service;
|
|||
import com.taosdata.taosdemo.domain.FieldMeta;
|
||||
import com.taosdata.taosdemo.domain.SuperTableMeta;
|
||||
import com.taosdata.taosdemo.domain.TagMeta;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -10,7 +13,7 @@ import java.util.List;
|
|||
|
||||
public class SuperTableServiceTest {
|
||||
|
||||
private SuperTableService service;
|
||||
private static SuperTableService service;
|
||||
|
||||
@Test
|
||||
public void testCreate() {
|
||||
|
@ -29,4 +32,15 @@ public class SuperTableServiceTest {
|
|||
service.create(superTableMeta);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws ClassNotFoundException {
|
||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setJdbcUrl("jdbc:TAOS://127.0.0.1:6030/?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8");
|
||||
config.setUsername("root");
|
||||
config.setPassword("taosdata");
|
||||
HikariDataSource dataSource = new HikariDataSource(config);
|
||||
service = new SuperTableService(dataSource);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.taosdata.example;
|
||||
package com.taos.example;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
|
@ -8,11 +8,11 @@ import java.sql.Statement;
|
|||
public class DruidDemo {
|
||||
// ANCHOR: connection_pool
|
||||
public static void main(String[] args) throws Exception {
|
||||
String url = "jdbc:TAOS://127.0.0.1:6030/log";
|
||||
String url = "jdbc:TAOS-WS://127.0.0.1:6041/log";
|
||||
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
// jdbc properties
|
||||
dataSource.setDriverClassName("com.taosdata.jdbc.TSDBDriver");
|
||||
dataSource.setDriverClassName("com.taosdata.jdbc.ws.WebSocketDriver");
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername("root");
|
||||
dataSource.setPassword("taosdata");
|
||||
|
|
|
@ -144,8 +144,9 @@ public class GeometryDemo {
|
|||
|
||||
private void executeQuery(String sql) {
|
||||
long start = System.currentTimeMillis();
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
ResultSet resultSet = statement.executeQuery(sql);
|
||||
try (Statement statement = connection.createStatement();
|
||||
ResultSet resultSet = statement.executeQuery(sql)) {
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
printSql(sql, true, (end - start));
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.taosdata.example;
|
||||
package com.taos.example;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
|
@ -11,7 +11,7 @@ public class HikariDemo {
|
|||
public static void main(String[] args) throws Exception {
|
||||
HikariConfig config = new HikariConfig();
|
||||
// jdbc properties
|
||||
config.setJdbcUrl("jdbc:TAOS://127.0.0.1:6030/log");
|
||||
config.setJdbcUrl("jdbc:TAOS-WS://127.0.0.1:6041/log");
|
||||
config.setUsername("root");
|
||||
config.setPassword("taosdata");
|
||||
// connection pool configurations
|
||||
|
|
|
@ -39,6 +39,7 @@ public class TelnetLineProtocolExample {
|
|||
createDatabase(conn);
|
||||
SchemalessWriter writer = new SchemalessWriter(conn);
|
||||
writer.write(lines, SchemalessProtocolType.TELNET, SchemalessTimestampType.NOT_CONFIGURED);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue