shardingsphere scenario remove commons-dbcp (#5788)
This commit is contained in:
parent
b69aff1e2b
commit
d625f2905b
|
|
@ -45,11 +45,6 @@
|
|||
<artifactId>sharding-jdbc-core</artifactId>
|
||||
<version>${test.framework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
|
|
|
|||
|
|
@ -18,13 +18,6 @@
|
|||
|
||||
package org.apache.skywalking.apm.testcase.shardingsphere;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.api.service.CommonService;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.config.ShardingDatabasesAndTablesConfigurationPrecise;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderItemRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.service.RawPojoService;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config.DataSourceUtil;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
|
|
@ -33,18 +26,6 @@ import org.springframework.boot.web.support.SpringBootServletInitializer;
|
|||
public class Application extends SpringBootServletInitializer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
DataSourceUtil.createDataSource("");
|
||||
DataSourceUtil.createSchema("demo_ds_0");
|
||||
DataSourceUtil.createSchema("demo_ds_1");
|
||||
DataSourceUtil.createDataSource("demo_ds_0");
|
||||
DataSourceUtil.createDataSource("demo_ds_1");
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().createDataSource();
|
||||
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.initEnvironment();
|
||||
SpringApplication.run(Application.class, args);
|
||||
} catch (Exception e) {
|
||||
// Never do this
|
||||
}
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,32 +18,42 @@
|
|||
|
||||
package org.apache.skywalking.apm.testcase.shardingsphere.controller;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.api.service.CommonService;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.config.ShardingDatabasesAndTablesConfigurationPrecise;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderItemRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.service.RawPojoService;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config.DataSourceUtil;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/case")
|
||||
public class CaseController {
|
||||
|
||||
private CommonService commonService = null;
|
||||
|
||||
@RequestMapping("/healthCheck")
|
||||
@ResponseBody
|
||||
public String healthCheck() {
|
||||
public String healthCheck() throws SQLException {
|
||||
DataSourceUtil.createDataSource("");
|
||||
DataSourceUtil.createSchema("demo_ds_0");
|
||||
DataSourceUtil.createSchema("demo_ds_1");
|
||||
DataSourceUtil.createDataSource("demo_ds_0");
|
||||
DataSourceUtil.createDataSource("demo_ds_1");
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().createDataSource();
|
||||
commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.initEnvironment();
|
||||
return "Success";
|
||||
}
|
||||
|
||||
@RequestMapping("/execute")
|
||||
@ResponseBody
|
||||
public String execute() throws SQLException {
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().getDataSource();
|
||||
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
public String execute() {
|
||||
commonService.processSuccess(false);
|
||||
return "Success";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,15 +32,18 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.
|
|||
public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
public JDBCOrderItemRepositoryImpl(final DataSource dataSource) {
|
||||
public JDBCOrderItemRepositoryImpl(final DataSource dataSource) throws SQLException {
|
||||
this.dataSource = dataSource;
|
||||
this.connection = dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTableIfNotExists() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS t_order_item " + "(order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id))";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -49,7 +52,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void dropTable() {
|
||||
String sql = "DROP TABLE t_order_item";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -58,7 +61,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void truncateTable() {
|
||||
String sql = "TRUNCATE TABLE t_order_item";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -67,7 +70,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public Long insert(final OrderItem orderItem) {
|
||||
String sql = "INSERT INTO t_order_item (order_id, user_id, status) VALUES (?, ?, ?)";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
preparedStatement.setLong(1, orderItem.getOrderId());
|
||||
preparedStatement.setInt(2, orderItem.getUserId());
|
||||
preparedStatement.setString(3, orderItem.getStatus());
|
||||
|
|
@ -85,7 +88,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void delete(final Long orderItemId) {
|
||||
String sql = "DELETE FROM t_order_item WHERE order_item_id=?";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
preparedStatement.setLong(1, orderItemId);
|
||||
preparedStatement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
|
|
@ -106,7 +109,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
|
||||
private List<OrderItem> getOrderItems(final String sql) {
|
||||
List<OrderItem> result = new LinkedList<>();
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
OrderItem orderItem = new OrderItem();
|
||||
|
|
|
|||
|
|
@ -32,15 +32,18 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.
|
|||
public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
public JDBCOrderRepositoryImpl(final DataSource dataSource) {
|
||||
public JDBCOrderRepositoryImpl(final DataSource dataSource) throws SQLException {
|
||||
this.dataSource = dataSource;
|
||||
this.connection = dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTableIfNotExists() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id))";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -49,7 +52,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void dropTable() {
|
||||
String sql = "DROP TABLE t_order";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -58,7 +61,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void truncateTable() {
|
||||
String sql = "TRUNCATE TABLE t_order";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -67,7 +70,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public Long insert(final Order order) {
|
||||
String sql = "INSERT INTO t_order (user_id, status) VALUES (?, ?)";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
preparedStatement.setInt(1, order.getUserId());
|
||||
preparedStatement.setString(2, order.getStatus());
|
||||
preparedStatement.executeUpdate();
|
||||
|
|
@ -84,7 +87,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void delete(final Long orderId) {
|
||||
String sql = "DELETE FROM t_order WHERE order_id=?";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
preparedStatement.setLong(1, orderId);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (final SQLException ignored) {
|
||||
|
|
@ -105,7 +108,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
|
||||
private List<Order> getOrders(final String sql) {
|
||||
List<Order> result = new LinkedList<>();
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
Order order = new Order();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import java.sql.Statement;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
|
||||
public class DataSourceUtil {
|
||||
|
||||
|
|
@ -33,10 +33,9 @@ public class DataSourceUtil {
|
|||
private static final Map<String, DataSource> datasourceMap = new HashMap<>();
|
||||
|
||||
public static void createDataSource(final String dataSourceName) {
|
||||
BasicDataSource result = new BasicDataSource();
|
||||
result.setDriverClassName("org.h2.Driver");
|
||||
result.setUrl(String.format("jdbc:h2:mem:%s", dataSourceName));
|
||||
result.setUsername("sa");
|
||||
JdbcDataSource result = new JdbcDataSource();
|
||||
result.setUrl("jdbc:h2:mem:" + dataSourceName + ";DB_CLOSE_DELAY=-1");
|
||||
result.setUser("sa");
|
||||
result.setPassword("");
|
||||
datasourceMap.put(dataSourceName, result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,11 +47,6 @@
|
|||
<artifactId>sharding-jdbc-core</artifactId>
|
||||
<version>${test.framework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
|
|
|
|||
|
|
@ -18,34 +18,14 @@
|
|||
|
||||
package org.apache.skywalking.apm.testcase.shardingsphere;
|
||||
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.api.service.CommonService;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.config.ShardingDatabasesAndTablesConfigurationPrecise;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderItemRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.service.RawPojoService;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config.DataSourceUtil;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application extends SpringBootServletInitializer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
DataSourceUtil.createDataSource("");
|
||||
DataSourceUtil.createSchema("demo_ds_0");
|
||||
DataSourceUtil.createSchema("demo_ds_1");
|
||||
DataSourceUtil.createDataSource("demo_ds_0");
|
||||
DataSourceUtil.createDataSource("demo_ds_1");
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().createDataSource();
|
||||
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.initEnvironment();
|
||||
SpringApplication.run(Application.class, args);
|
||||
} catch (Exception e) {
|
||||
// Never do this
|
||||
}
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,27 +23,37 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.config.Sharding
|
|||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderItemRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.service.RawPojoService;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config.DataSourceUtil;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/case")
|
||||
public class CaseController {
|
||||
|
||||
private CommonService commonService = null;
|
||||
|
||||
@RequestMapping("/healthCheck")
|
||||
@ResponseBody
|
||||
public String healthCheck() {
|
||||
public String healthCheck() throws SQLException {
|
||||
DataSourceUtil.createDataSource("");
|
||||
DataSourceUtil.createSchema("demo_ds_0");
|
||||
DataSourceUtil.createSchema("demo_ds_1");
|
||||
DataSourceUtil.createDataSource("demo_ds_0");
|
||||
DataSourceUtil.createDataSource("demo_ds_1");
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().createDataSource();
|
||||
commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.initEnvironment();
|
||||
return "Success";
|
||||
}
|
||||
|
||||
@RequestMapping("/execute")
|
||||
@ResponseBody
|
||||
public String execute() {
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().getDataSource();
|
||||
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.processSuccess(false);
|
||||
return "Success";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,31 +22,39 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.api.entity.Orde
|
|||
import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.OrderItemRepository;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
public JDBCOrderItemRepositoryImpl(final DataSource dataSource) {
|
||||
public JDBCOrderItemRepositoryImpl(final DataSource dataSource) throws SQLException {
|
||||
this.dataSource = dataSource;
|
||||
this.connection = dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTableIfNotExists() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS t_order_item " + "(order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id))";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropTable() {
|
||||
String sql = "DROP TABLE t_order_item";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -55,7 +63,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void truncateTable() {
|
||||
String sql = "TRUNCATE TABLE t_order_item";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -64,7 +72,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public Long insert(final OrderItem orderItem) {
|
||||
String sql = "INSERT INTO t_order_item (order_id, user_id, status) VALUES (?, ?, ?)";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
preparedStatement.setLong(1, orderItem.getOrderId());
|
||||
preparedStatement.setInt(2, orderItem.getUserId());
|
||||
preparedStatement.setString(3, orderItem.getStatus());
|
||||
|
|
@ -82,7 +90,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void delete(final Long orderItemId) {
|
||||
String sql = "DELETE FROM t_order_item WHERE order_item_id=?";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
preparedStatement.setLong(1, orderItemId);
|
||||
preparedStatement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
|
|
@ -103,7 +111,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
|
||||
private List<OrderItem> getOrderItems(final String sql) {
|
||||
List<OrderItem> result = new LinkedList<>();
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
OrderItem orderItem = new OrderItem();
|
||||
|
|
@ -114,6 +122,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
result.add(orderItem);
|
||||
}
|
||||
} catch (final SQLException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,15 +29,18 @@ import java.util.List;
|
|||
public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
public JDBCOrderRepositoryImpl(final DataSource dataSource) {
|
||||
public JDBCOrderRepositoryImpl(final DataSource dataSource) throws SQLException {
|
||||
this.dataSource = dataSource;
|
||||
this.connection = dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTableIfNotExists() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id))";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -46,7 +49,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void dropTable() {
|
||||
String sql = "DROP TABLE t_order";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -55,7 +58,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void truncateTable() {
|
||||
String sql = "TRUNCATE TABLE t_order";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -64,7 +67,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public Long insert(final Order order) {
|
||||
String sql = "INSERT INTO t_order (user_id, status) VALUES (?, ?)";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
preparedStatement.setInt(1, order.getUserId());
|
||||
preparedStatement.setString(2, order.getStatus());
|
||||
preparedStatement.executeUpdate();
|
||||
|
|
@ -81,7 +84,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void delete(final Long orderId) {
|
||||
String sql = "DELETE FROM t_order WHERE order_id=?";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
preparedStatement.setLong(1, orderId);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (final SQLException ignored) {
|
||||
|
|
@ -102,7 +105,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
|
||||
private List<Order> getOrders(final String sql) {
|
||||
List<Order> result = new LinkedList<>();
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
Order order = new Order();
|
||||
|
|
@ -112,6 +115,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
result.add(order);
|
||||
}
|
||||
} catch (final SQLException ignored) {
|
||||
ignored.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
package org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config;
|
||||
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
|
|
@ -34,10 +34,9 @@ public class DataSourceUtil {
|
|||
private static final Map<String, DataSource> datasourceMap = new HashMap<>();
|
||||
|
||||
public static void createDataSource(final String dataSourceName) {
|
||||
BasicDataSource result = new BasicDataSource();
|
||||
result.setDriverClassName("org.h2.Driver");
|
||||
result.setUrl(String.format("jdbc:h2:mem:%s", dataSourceName));
|
||||
result.setUsername("sa");
|
||||
JdbcDataSource result = new JdbcDataSource();
|
||||
result.setUrl("jdbc:h2:mem:" + dataSourceName + ";DB_CLOSE_DELAY=-1");
|
||||
result.setUser("sa");
|
||||
result.setPassword("");
|
||||
datasourceMap.put(dataSourceName, result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,11 +48,6 @@
|
|||
<artifactId>sharding-jdbc-core</artifactId>
|
||||
<version>${test.framework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
|
|
|
|||
|
|
@ -34,14 +34,7 @@ public class Application extends SpringBootServletInitializer {
|
|||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
DataSourceUtil.createDataSource("");
|
||||
DataSourceUtil.createSchema("demo_ds_0");
|
||||
DataSourceUtil.createSchema("demo_ds_1");
|
||||
DataSourceUtil.createDataSource("demo_ds_0");
|
||||
DataSourceUtil.createDataSource("demo_ds_1");
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().createDataSource();
|
||||
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.initEnvironment();
|
||||
|
||||
SpringApplication.run(Application.class, args);
|
||||
} catch (Exception e) {
|
||||
// Never do this
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.config.Sharding
|
|||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderItemRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.service.RawPojoService;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config.DataSourceUtil;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
|
@ -32,18 +33,26 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RestController
|
||||
@RequestMapping("/case")
|
||||
public class CaseController {
|
||||
|
||||
private CommonService commonService = null;
|
||||
|
||||
@RequestMapping("/healthCheck")
|
||||
@ResponseBody
|
||||
public String healthCheck() {
|
||||
public String healthCheck() throws SQLException {
|
||||
DataSourceUtil.createDataSource("");
|
||||
DataSourceUtil.createSchema("demo_ds_0");
|
||||
DataSourceUtil.createSchema("demo_ds_1");
|
||||
DataSourceUtil.createDataSource("demo_ds_0");
|
||||
DataSourceUtil.createDataSource("demo_ds_1");
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().createDataSource();
|
||||
commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.initEnvironment();
|
||||
return "Success";
|
||||
}
|
||||
|
||||
@RequestMapping("/execute")
|
||||
@ResponseBody
|
||||
public String execute() throws SQLException {
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().getDataSource();
|
||||
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
public String execute() {
|
||||
commonService.processSuccess(false);
|
||||
return "Success";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,15 +32,18 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.
|
|||
public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
public JDBCOrderItemRepositoryImpl(final DataSource dataSource) {
|
||||
public JDBCOrderItemRepositoryImpl(final DataSource dataSource) throws SQLException {
|
||||
this.dataSource = dataSource;
|
||||
this.connection = dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTableIfNotExists() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS t_order_item " + "(order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id))";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -49,7 +52,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void dropTable() {
|
||||
String sql = "DROP TABLE t_order_item";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -58,7 +61,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void truncateTable() {
|
||||
String sql = "TRUNCATE TABLE t_order_item";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -67,7 +70,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public Long insert(final OrderItem orderItem) {
|
||||
String sql = "INSERT INTO t_order_item (order_id, user_id, status) VALUES (?, ?, ?)";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
preparedStatement.setLong(1, orderItem.getOrderId());
|
||||
preparedStatement.setInt(2, orderItem.getUserId());
|
||||
preparedStatement.setString(3, orderItem.getStatus());
|
||||
|
|
@ -85,7 +88,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void delete(final Long orderItemId) {
|
||||
String sql = "DELETE FROM t_order_item WHERE order_item_id=?";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
preparedStatement.setLong(1, orderItemId);
|
||||
preparedStatement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
|
|
@ -106,7 +109,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
|
||||
private List<OrderItem> getOrderItems(final String sql) {
|
||||
List<OrderItem> result = new LinkedList<>();
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
OrderItem orderItem = new OrderItem();
|
||||
|
|
|
|||
|
|
@ -32,15 +32,18 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.
|
|||
public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
public JDBCOrderRepositoryImpl(final DataSource dataSource) {
|
||||
public JDBCOrderRepositoryImpl(final DataSource dataSource) throws SQLException {
|
||||
this.dataSource = dataSource;
|
||||
this.connection = dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTableIfNotExists() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id))";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -49,7 +52,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void dropTable() {
|
||||
String sql = "DROP TABLE t_order";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -58,7 +61,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void truncateTable() {
|
||||
String sql = "TRUNCATE TABLE t_order";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -67,7 +70,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public Long insert(final Order order) {
|
||||
String sql = "INSERT INTO t_order (user_id, status) VALUES (?, ?)";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
preparedStatement.setInt(1, order.getUserId());
|
||||
preparedStatement.setString(2, order.getStatus());
|
||||
preparedStatement.executeUpdate();
|
||||
|
|
@ -84,7 +87,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void delete(final Long orderId) {
|
||||
String sql = "DELETE FROM t_order WHERE order_id=?";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
preparedStatement.setLong(1, orderId);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (final SQLException ignored) {
|
||||
|
|
@ -105,7 +108,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
|
||||
private List<Order> getOrders(final String sql) {
|
||||
List<Order> result = new LinkedList<>();
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
Order order = new Order();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import java.sql.Statement;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
|
||||
public class DataSourceUtil {
|
||||
|
||||
|
|
@ -33,10 +33,9 @@ public class DataSourceUtil {
|
|||
private static final Map<String, DataSource> datasourceMap = new HashMap<>();
|
||||
|
||||
public static void createDataSource(final String dataSourceName) {
|
||||
BasicDataSource result = new BasicDataSource();
|
||||
result.setDriverClassName("org.h2.Driver");
|
||||
result.setUrl(String.format("jdbc:h2:mem:%s", dataSourceName));
|
||||
result.setUsername("sa");
|
||||
JdbcDataSource result = new JdbcDataSource();
|
||||
result.setUrl("jdbc:h2:mem:" + dataSourceName + ";DB_CLOSE_DELAY=-1");
|
||||
result.setUser("sa");
|
||||
result.setPassword("");
|
||||
datasourceMap.put(dataSourceName, result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,11 +48,6 @@
|
|||
<artifactId>sharding-jdbc-core</artifactId>
|
||||
<version>${test.framework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-dbcp</groupId>
|
||||
<artifactId>commons-dbcp</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
|
|
|
|||
|
|
@ -34,14 +34,7 @@ public class Application extends SpringBootServletInitializer {
|
|||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
DataSourceUtil.createDataSource("");
|
||||
DataSourceUtil.createSchema("demo_ds_0");
|
||||
DataSourceUtil.createSchema("demo_ds_1");
|
||||
DataSourceUtil.createDataSource("demo_ds_0");
|
||||
DataSourceUtil.createDataSource("demo_ds_1");
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().createDataSource();
|
||||
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.initEnvironment();
|
||||
|
||||
SpringApplication.run(Application.class, args);
|
||||
} catch (Exception e) {
|
||||
// Never do this
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.config.Sharding
|
|||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderItemRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.service.RawPojoService;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config.DataSourceUtil;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
|
@ -32,18 +33,26 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RestController
|
||||
@RequestMapping("/case")
|
||||
public class CaseController {
|
||||
|
||||
private CommonService commonService = null;
|
||||
|
||||
@RequestMapping("/healthCheck")
|
||||
@ResponseBody
|
||||
public String healthCheck() {
|
||||
public String healthCheck() throws SQLException {
|
||||
DataSourceUtil.createDataSource("");
|
||||
DataSourceUtil.createSchema("demo_ds_0");
|
||||
DataSourceUtil.createSchema("demo_ds_1");
|
||||
DataSourceUtil.createDataSource("demo_ds_0");
|
||||
DataSourceUtil.createDataSource("demo_ds_1");
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().createDataSource();
|
||||
commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.initEnvironment();
|
||||
return "Success";
|
||||
}
|
||||
|
||||
@RequestMapping("/execute")
|
||||
@ResponseBody
|
||||
public String execute() throws SQLException {
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().getDataSource();
|
||||
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
public String execute() {
|
||||
commonService.processSuccess(false);
|
||||
return "Success";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,15 +32,18 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.
|
|||
public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
public JDBCOrderItemRepositoryImpl(final DataSource dataSource) {
|
||||
public JDBCOrderItemRepositoryImpl(final DataSource dataSource) throws SQLException {
|
||||
this.dataSource = dataSource;
|
||||
this.connection = dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTableIfNotExists() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS t_order_item " + "(order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id))";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -49,7 +52,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void dropTable() {
|
||||
String sql = "DROP TABLE t_order_item";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -58,7 +61,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void truncateTable() {
|
||||
String sql = "TRUNCATE TABLE t_order_item";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -67,7 +70,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public Long insert(final OrderItem orderItem) {
|
||||
String sql = "INSERT INTO t_order_item (order_id, user_id, status) VALUES (?, ?, ?)";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
preparedStatement.setLong(1, orderItem.getOrderId());
|
||||
preparedStatement.setInt(2, orderItem.getUserId());
|
||||
preparedStatement.setString(3, orderItem.getStatus());
|
||||
|
|
@ -85,7 +88,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void delete(final Long orderItemId) {
|
||||
String sql = "DELETE FROM t_order_item WHERE order_item_id=?";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
preparedStatement.setLong(1, orderItemId);
|
||||
preparedStatement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
|
|
@ -106,7 +109,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
|
||||
private List<OrderItem> getOrderItems(final String sql) {
|
||||
List<OrderItem> result = new LinkedList<>();
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
OrderItem orderItem = new OrderItem();
|
||||
|
|
|
|||
|
|
@ -32,15 +32,18 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.
|
|||
public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
public JDBCOrderRepositoryImpl(final DataSource dataSource) {
|
||||
public JDBCOrderRepositoryImpl(final DataSource dataSource) throws SQLException {
|
||||
this.dataSource = dataSource;
|
||||
this.connection = dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTableIfNotExists() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id))";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -49,7 +52,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void dropTable() {
|
||||
String sql = "DROP TABLE t_order";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -58,7 +61,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void truncateTable() {
|
||||
String sql = "TRUNCATE TABLE t_order";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -67,7 +70,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public Long insert(final Order order) {
|
||||
String sql = "INSERT INTO t_order (user_id, status) VALUES (?, ?)";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
preparedStatement.setInt(1, order.getUserId());
|
||||
preparedStatement.setString(2, order.getStatus());
|
||||
preparedStatement.executeUpdate();
|
||||
|
|
@ -84,7 +87,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void delete(final Long orderId) {
|
||||
String sql = "DELETE FROM t_order WHERE order_id=?";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
preparedStatement.setLong(1, orderId);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (final SQLException ignored) {
|
||||
|
|
@ -105,7 +108,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
|
||||
private List<Order> getOrders(final String sql) {
|
||||
List<Order> result = new LinkedList<>();
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
Order order = new Order();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import java.sql.Statement;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
|
||||
public class DataSourceUtil {
|
||||
|
||||
|
|
@ -33,10 +33,9 @@ public class DataSourceUtil {
|
|||
private static final Map<String, DataSource> datasourceMap = new HashMap<>();
|
||||
|
||||
public static void createDataSource(final String dataSourceName) {
|
||||
BasicDataSource result = new BasicDataSource();
|
||||
result.setDriverClassName("org.h2.Driver");
|
||||
result.setUrl(String.format("jdbc:h2:mem:%s", dataSourceName));
|
||||
result.setUsername("sa");
|
||||
JdbcDataSource result = new JdbcDataSource();
|
||||
result.setUrl("jdbc:h2:mem:" + dataSourceName + ";DB_CLOSE_DELAY=-1");
|
||||
result.setUser("sa");
|
||||
result.setPassword("");
|
||||
datasourceMap.put(dataSourceName, result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,11 +47,6 @@
|
|||
<artifactId>sharding-jdbc-core</artifactId>
|
||||
<version>${test.framework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
|
|
|
|||
|
|
@ -34,14 +34,7 @@ public class Application extends SpringBootServletInitializer {
|
|||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
DataSourceUtil.createDataSource("");
|
||||
DataSourceUtil.createSchema("demo_ds_0");
|
||||
DataSourceUtil.createSchema("demo_ds_1");
|
||||
DataSourceUtil.createDataSource("demo_ds_0");
|
||||
DataSourceUtil.createDataSource("demo_ds_1");
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().createDataSource();
|
||||
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.initEnvironment();
|
||||
|
||||
SpringApplication.run(Application.class, args);
|
||||
} catch (Exception e) {
|
||||
// Never do this
|
||||
|
|
|
|||
|
|
@ -24,25 +24,36 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.config.Sharding
|
|||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderItemRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.jdbc.JDBCOrderRepositoryImpl;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.repository.service.RawPojoService;
|
||||
import org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config.DataSourceUtil;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/case")
|
||||
public class CaseController {
|
||||
|
||||
private CommonService commonService = null;
|
||||
|
||||
@RequestMapping("/healthCheck")
|
||||
@ResponseBody
|
||||
public String healthCheck() {
|
||||
public String healthCheck() throws SQLException {
|
||||
DataSourceUtil.createDataSource("");
|
||||
DataSourceUtil.createSchema("demo_ds_0");
|
||||
DataSourceUtil.createSchema("demo_ds_1");
|
||||
DataSourceUtil.createDataSource("demo_ds_0");
|
||||
DataSourceUtil.createDataSource("demo_ds_1");
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().createDataSource();
|
||||
commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.initEnvironment();
|
||||
return "Success";
|
||||
}
|
||||
|
||||
@RequestMapping("/execute")
|
||||
@ResponseBody
|
||||
public String execute() {
|
||||
DataSource dataSource = new ShardingDatabasesAndTablesConfigurationPrecise().getDataSource();
|
||||
CommonService commonService = new RawPojoService(new JDBCOrderRepositoryImpl(dataSource), new JDBCOrderItemRepositoryImpl(dataSource));
|
||||
commonService.processSuccess(false);
|
||||
return "Success";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,15 +32,18 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.
|
|||
public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
public JDBCOrderItemRepositoryImpl(final DataSource dataSource) {
|
||||
public JDBCOrderItemRepositoryImpl(final DataSource dataSource) throws SQLException {
|
||||
this.dataSource = dataSource;
|
||||
this.connection = dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTableIfNotExists() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS t_order_item " + "(order_item_id BIGINT NOT NULL AUTO_INCREMENT, order_id BIGINT NOT NULL, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_item_id))";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -49,7 +52,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void dropTable() {
|
||||
String sql = "DROP TABLE t_order_item";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -58,7 +61,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void truncateTable() {
|
||||
String sql = "TRUNCATE TABLE t_order_item";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -67,7 +70,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public Long insert(final OrderItem orderItem) {
|
||||
String sql = "INSERT INTO t_order_item (order_id, user_id, status) VALUES (?, ?, ?)";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
preparedStatement.setLong(1, orderItem.getOrderId());
|
||||
preparedStatement.setInt(2, orderItem.getUserId());
|
||||
preparedStatement.setString(3, orderItem.getStatus());
|
||||
|
|
@ -85,7 +88,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
@Override
|
||||
public void delete(final Long orderItemId) {
|
||||
String sql = "DELETE FROM t_order_item WHERE order_item_id=?";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
preparedStatement.setLong(1, orderItemId);
|
||||
preparedStatement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
|
|
@ -106,7 +109,7 @@ public final class JDBCOrderItemRepositoryImpl implements OrderItemRepository {
|
|||
|
||||
private List<OrderItem> getOrderItems(final String sql) {
|
||||
List<OrderItem> result = new LinkedList<>();
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
OrderItem orderItem = new OrderItem();
|
||||
|
|
|
|||
|
|
@ -32,15 +32,18 @@ import org.apache.skywalking.apm.testcase.shardingsphere.service.api.repository.
|
|||
public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private final Connection connection;
|
||||
|
||||
public JDBCOrderRepositoryImpl(final DataSource dataSource) {
|
||||
public JDBCOrderRepositoryImpl(final DataSource dataSource) throws SQLException {
|
||||
this.dataSource = dataSource;
|
||||
this.connection = dataSource.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTableIfNotExists() {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS t_order (order_id BIGINT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL, status VARCHAR(50), PRIMARY KEY (order_id))";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -49,7 +52,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void dropTable() {
|
||||
String sql = "DROP TABLE t_order";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -58,7 +61,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void truncateTable() {
|
||||
String sql = "TRUNCATE TABLE t_order";
|
||||
try (Connection connection = dataSource.getConnection(); Statement statement = connection.createStatement()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.executeUpdate(sql);
|
||||
} catch (final SQLException ignored) {
|
||||
}
|
||||
|
|
@ -67,7 +70,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public Long insert(final Order order) {
|
||||
String sql = "INSERT INTO t_order (user_id, status) VALUES (?, ?)";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||
preparedStatement.setInt(1, order.getUserId());
|
||||
preparedStatement.setString(2, order.getStatus());
|
||||
preparedStatement.executeUpdate();
|
||||
|
|
@ -84,7 +87,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
@Override
|
||||
public void delete(final Long orderId) {
|
||||
String sql = "DELETE FROM t_order WHERE order_id=?";
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
|
||||
preparedStatement.setLong(1, orderId);
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (final SQLException ignored) {
|
||||
|
|
@ -105,7 +108,7 @@ public final class JDBCOrderRepositoryImpl implements OrderRepository {
|
|||
|
||||
private List<Order> getOrders(final String sql) {
|
||||
List<Order> result = new LinkedList<>();
|
||||
try (Connection connection = dataSource.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sql); ResultSet resultSet = preparedStatement
|
||||
.executeQuery()) {
|
||||
while (resultSet.next()) {
|
||||
Order order = new Order();
|
||||
|
|
|
|||
|
|
@ -18,14 +18,13 @@
|
|||
|
||||
package org.apache.skywalking.apm.testcase.shardingsphere.service.utility.config;
|
||||
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.sql.DataSource;
|
||||
import org.h2.jdbcx.JdbcDataSource;
|
||||
|
||||
public class DataSourceUtil {
|
||||
|
||||
|
|
@ -34,10 +33,9 @@ public class DataSourceUtil {
|
|||
private static final Map<String, DataSource> datasourceMap = new HashMap<>();
|
||||
|
||||
public static void createDataSource(final String dataSourceName) {
|
||||
BasicDataSource result = new BasicDataSource();
|
||||
result.setDriverClassName("org.h2.Driver");
|
||||
result.setUrl(String.format("jdbc:h2:mem:%s", dataSourceName));
|
||||
result.setUsername("sa");
|
||||
JdbcDataSource result = new JdbcDataSource();
|
||||
result.setUrl("jdbc:h2:mem:" + dataSourceName + ";DB_CLOSE_DELAY=-1");
|
||||
result.setUser("sa");
|
||||
result.setPassword("");
|
||||
datasourceMap.put(dataSourceName, result);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue