Skip to content

Commit

Permalink
fix: datasource close 20240819 (#879)
Browse files Browse the repository at this point in the history
* feat: add prometheus-trace-etl release

* feat: add gitlab log release jdk21

* feat: update athena

* feat: update check code file path

* feat: add code generator and mybatis generator

* feat: add mybtais generator

* fix: update test error

* fix: add HikariDataSource close
  • Loading branch information
sadadw1 authored Aug 19, 2024
1 parent d5f6724 commit f3cdec0
Showing 1 changed file with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import run.mone.ai.codegen.bo.FeatureGenerateType;
import run.mone.ai.codegen.bo.FeatureGenerateBo;
import run.mone.ai.codegen.bo.FeatureGenerateType;
import run.mone.ai.codegen.util.TemplateUtils;

import java.lang.reflect.Type;
import run.mone.ai.codegen.bo.FeatureGeneratType;
import run.mone.ai.codegen.bo.FeatureGenerateBo;
import run.mone.ai.codegen.util.TemplateUtils;

import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -141,26 +137,29 @@ public static void generateWithGenerator(FeatureGenerateBo featureGenerateBo) {
}

//配置数据源
HikariDataSource dataSource = new HikariDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setJdbcUrl(featureGenerateBo.getJdbcUrl());
dataSource.setUsername(featureGenerateBo.getUserName());
dataSource.setPassword(featureGenerateBo.getPassword());

//创建mapper相关代码

if (FeatureGenerateType.CODE_WITH_TEMPLATE == featureGenType) {
GlobalConfig globalConfig = createGlobalConfigUseStyle(featureGenerateBo);
Generator generator = new Generator(dataSource, globalConfig);
generator.generate();
return;
}
try (HikariDataSource dataSource = new HikariDataSource()) {
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setJdbcUrl(featureGenerateBo.getJdbcUrl());
dataSource.setUsername(featureGenerateBo.getUserName());
dataSource.setPassword(featureGenerateBo.getPassword());

//创建mapper相关代码

if (FeatureGenerateType.CODE_WITH_TEMPLATE == featureGenType) {
GlobalConfig globalConfig = createGlobalConfigUseStyle(featureGenerateBo);
Generator generator = new Generator(dataSource, globalConfig);
generator.generate();
return;
}

//创建table
//创建table

if (FeatureGenerateType.TABLE == featureGenType) {
JdbcTemplate jt = new JdbcTemplate(dataSource);
jt.update(featureGenerateBo.getSql());
if (FeatureGenerateType.TABLE == featureGenType) {
JdbcTemplate jt = new JdbcTemplate(dataSource);
jt.update(featureGenerateBo.getSql());
}
} catch (Exception e) {
log.error("generate with template error", e);
}
}

Expand Down

0 comments on commit f3cdec0

Please sign in to comment.