feat: jdbc 封装(测试成功)

master
rouchen 2024-05-11 14:12:14 +08:00
parent db1da8613d
commit 59cc24f8c9
9 changed files with 37 additions and 9 deletions

View File

@ -22,6 +22,12 @@
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.26</version>
</dependency>
</dependencies>
</project>

View File

@ -1,5 +1,7 @@
package com.muyu.mysql;
import lombok.extern.log4j.Log4j2;
/**
* mysql MySqlConfig
*
@ -7,6 +9,7 @@ package com.muyu.mysql;
* on 2024/5/10
*/
@Log4j2
public class MySqlConfig {
/**
@ -17,7 +20,9 @@ public class MySqlConfig {
public static void dirver(String dirverName)
{
try {
//加载驱动
Class.forName(dirverName);
log.info("加载驱动成功");
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}

View File

@ -28,12 +28,15 @@ public class MysqlApp {
Mysql mysql = new Mysql();
mysql.setId("1");
mysql.setName("root");
mysql.setSystemName("2222");
mysql.setUsername("root");
mysql.setPassword("root");
mysql.setHost("localhost");
mysql.setDatabaseName("data_basete");
mysql.setHost("127.0.0.1");
mysql.setDatabaseName("damo01");
mysql.setPort("3306");
mysql.setType("mysql");
mysql.setType("Mysql");
mysql.setDriverName("com.mysql.cj.jdbc.Driver");
mysql.setConnectionParam("useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
mySqlConfigs.add(mysql);
@ -47,7 +50,8 @@ public class MysqlApp {
.databaseName(mysql1.getDatabaseName())
.port(mysql1.getPort())
.type(mysql1.getType())
.driverName(mysql1.getConnectionParam())
.driverName(mysql1.getDriverName())
.param(mysql1.getConnectionParam())
.ip(mysql1.getHost())
.build();

View File

@ -45,6 +45,7 @@ public class MySqlConfilg {
*/
private String type;
/**
*
*/

View File

@ -42,4 +42,6 @@ public class Mysql {
/** 数据连接参数 */
private String connectionParam;
private String driverName;
}

View File

@ -1,11 +1,14 @@
package com.muyu.kvt.client.pool;
import lombok.extern.log4j.Log4j2;
/**
* BaseConfig
*
* @author LeYang
* on 2024/5/9
*/
@Log4j2
public class BaseConfig {
/**
@ -16,6 +19,7 @@ public class BaseConfig {
public static void dirver(String dirverName){
try {
Class.forName(dirverName);
log.info("加载驱动成功",dirverName,Class.forName(dirverName));
}catch (ClassNotFoundException e){
throw new RuntimeException(e);
}

View File

@ -2,12 +2,9 @@ package com.muyu.engine.remote;
import com.muyu.common.core.constant.ServiceNameConstants;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.engine.domain.RuleEngine;
import com.muyu.engine.domain.req.RuleEngineQueryReq;
import com.muyu.engine.remote.factory.RuleEngineManangerServiceFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.List;
@ -18,10 +15,18 @@ import java.util.List;
* @author LeYang
* on 2024/5/9
*/
/**
* 使Feign
*
*/
@FeignClient(
//定义上下文ID用于区分不同的Feign客户端实例。
contextId = "RuleEngineManangerService",
//指定要调用的服务的名称
value = ServiceNameConstants.MUYU_RULE_ENGINE,
//指定服务调用失败时的回退工厂
fallbackFactory = RuleEngineManangerServiceFactory.class,
// 指定服务访问的路径前缀。
path = "/engine"
)
public interface RuleEngineManangerService {

View File

@ -1,9 +1,7 @@
package com.muyu.engine.remote.factory;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.engine.domain.RuleEngine;
import com.muyu.engine.domain.req.RuleEngineQueryReq;
import com.muyu.engine.remote.RuleEngineManangerService;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

View File

@ -96,8 +96,10 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper, RuleEng
//找到文件并读取
Path path = Paths.get(url + ruleEngine.getWriteCode() + ".java");
if (Files.exists(path)) {
// 读取文件内容
BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(path), StandardCharsets.UTF_8));
String line;
// 将每一行内容拼接起来
StringBuilder content = new StringBuilder();
while ((line = reader.readLine()) != null) {
content.append(line).append("\n");
@ -204,6 +206,7 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineMapper, RuleEng
System.out.println(compileResult == 0 ? "编译成功" : "编译失败");
ProcessBuilder pbRun = new ProcessBuilder("java",ruleEngine.getWriteCode());
// 设置工作目录
pbRun.directory(Paths.get(url).toFile());
Process runProcess = pbRun.start();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(runProcess.getInputStream()));