提交 7e61e683 authored 作者: Matrix's avatar Matrix

fix(SQL执行器): 结构优化|BUG修复

- 优化了项目结构 - 修复了各类执行器的BUG - 完成了环境变量替换,递归SQL变量的测试
上级 826e8fa5
......@@ -95,7 +95,6 @@
</dependency>
<!--swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
......@@ -159,6 +158,12 @@
<version>5.5.9</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package org.matrix;
import lombok.extern.slf4j.Slf4j;
import org.matrix.actuators.datasource.DataSourceDTO;
import org.matrix.actuators.datasource.IDataSourceService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* Hello world!
*
* @author matrix
*/
@Slf4j
@SpringBootApplication
public class BaseBootApplication {
@MapperScan("org.matrix.database.mapper")
public class BaseBootApplication implements CommandLineRunner {
@Value("${spring.datasource.dynamic.datasource.master.url}")
private String url;
@Value("${spring.datasource.dynamic.datasource.master.username}")
private String username;
@Value("${spring.datasource.dynamic.datasource.master.password}")
private String password;
@Value("${spring.datasource.dynamic.datasource.master.driverClassName}")
private String driverClassName;
private final IDataSourceService dataSourceService;
public BaseBootApplication(IDataSourceService dataSourceService) {
this.dataSourceService = dataSourceService;
}
public static void main(String[] args) {
SpringApplication.run(BaseBootApplication.class, args);
}
/**
* Callback used to run the bean.
*
* @param args incoming main method arguments
* @throws Exception on error
*/
@Override
public void run(String... args) throws Exception {
log.info("[初始化] 初始化数据源" + driverClassName);
dataSourceService.add(new DataSourceDTO("初始数据源",driverClassName,url,username,password));
}
}
......@@ -20,12 +20,16 @@ import java.util.Set;
* Suffering is the most powerful teacher of life.
*/
@Service
@RequiredArgsConstructor(onConstructor = @__(@Lazy))
public class IDataSourceServiceImpl implements IDataSourceService {
private final DataSource dataSource;
private final DefaultDataSourceCreator dataSourceCreator;
public IDataSourceServiceImpl(DataSource dataSource, DefaultDataSourceCreator dataSourceCreator) {
this.dataSource = dataSource;
this.dataSourceCreator = dataSourceCreator;
}
/**
* 将当前使用的数据替换为参数提供的数据源,如果还没有,则会添加,如果已经有了,则不会添加
*
......
......@@ -15,7 +15,7 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SqlRegObject {
public class SqlRegularObject {
/**
* 动态变量名
......
package org.matrix.database.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
......
package org.matrix.database.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.*;
import org.matrix.actuators.datasource.DataSourceDTO;
/**
......@@ -19,6 +14,7 @@ import org.matrix.actuators.datasource.DataSourceDTO;
* @since 2022-01-15
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
......@@ -46,7 +42,7 @@ public class Connect extends BaseEntity {
* @return {@link DataSourceDTO}
*/
public DataSourceDTO toDataSourceDTO() {
return new DataSourceDTO("name", driver, url, username, password);
return new DataSourceDTO(name, driver, url, username, password);
}
......
......@@ -5,10 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.*;
import org.matrix.actuators.sql.SqlExpDetail;
import org.matrix.enums.DynamicVarType;
import org.matrix.exception.GlobalException;
......@@ -22,6 +19,7 @@ import org.matrix.exception.GlobalException;
* @since 2022-01-15
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
......
package org.matrix.database.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import io.swagger.annotations.ApiModel;
......
package org.matrix.database.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import org.matrix.database.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
......
package org.matrix.database.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import org.matrix.database.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
......
package org.matrix.database.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import org.matrix.database.entity.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.matrix.database.mapper.ActionMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.matrix.database.mapper.ConnectMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.matrix.database.mapper.DynamicVariableMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.matrix.database.mapper.ExampleMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.matrix.database.mapper.MoveMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.matrix.database.mapper.ProjectMapper">
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.matrix.database.mapper.TestCaseMapper">
</mapper>
# config mysql database
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=ldf3291369
spring:
application:
name: keyStone
datasource:
dynamic:
primary: master #设置默认的数据源或者数据源组,默认值即为master
strict: true #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源
datasource:
master: #增加默认数据源
driverClassName: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: ldf3291369
mybatis-plus:
type-enums-package: org.matrix.enums
\ No newline at end of file
package org.matrix.actuators.sql;
import com.alibaba.fastjson.JSON;
import org.junit.Before;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.runner.RunWith;
import org.matrix.database.entity.Connect;
import org.matrix.database.entity.DynamicVariable;
import org.matrix.database.service.IConnectService;
import org.matrix.database.service.IDynamicVariableService;
import org.matrix.enums.DynamicVarType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* SqlExpActuatorTest.
......@@ -11,10 +20,25 @@ import static org.junit.jupiter.api.Assertions.*;
* @since 2022/1/20 at 3:08 PM
* Suffering is the most powerful teacher of life.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
class SqlExpActuatorTest {
@Autowired
private SqlExpActuator sqlExpActuator;
@Autowired
private IDynamicVariableService variableService;
@Autowired
private IConnectService connectService;
@Test
void parseVarByName() {
String reuslt = sqlExpActuator.parseVarByName("${componentName}[2]", 1L, 1L);
System.out.println(reuslt);
}
@Test
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论