Chris2018998 / beecp

A small JDBC Connection pool
Apache License 2.0
88 stars 18 forks source link

Hikari换成BeeCP报错(beetlsql) #40

Closed wyw19902006 closed 3 years ago

wyw19902006 commented 3 years ago

import cn.hutool.setting.dialect.Props; import com.zaxxer.hikari.HikariDataSource; import org.beetl.sql.core.*; import org.beetl.sql.core.db.MySqlStyle; import org.beetl.sql.gen.SourceBuilder; import org.beetl.sql.gen.SourceConfig; import org.beetl.sql.gen.simple.EntitySourceBuilder; import org.beetl.sql.gen.simple.MDSourceBuilder; import org.beetl.sql.gen.simple.MapperSourceBuilder; import org.beetl.sql.gen.simple.SimpleMavenProject;

import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicReference;

public class MysqlGenerator { public static void main(String[] args) { SQLManager sqlManager = createSQLManager(); SourceConfig config = new SourceConfig(sqlManager, createSourceBuilder()); config.setPreferDoubleType(SourceConfig.PreferDoubleType.BigDecimal); config.setPreferDateType(SourceConfig.PreferDateType.LocalDate); SimpleMavenProject mavenProject = createBaseProject(); config.genAll(mavenProject); }

public static SQLManager createSQLManager() {
    AtomicReference<Props> props = new AtomicReference<>(new Props("application.properties"));
    HikariDataSource ds = new HikariDataSource();
    ds.setJdbcUrl(props.get().getProperty("spring.datasource.url"));
    ds.setUsername(props.get().getProperty("spring.datasource.username"));
    ds.setPassword(props.get().getProperty("spring.datasource.password"));
    ds.setDriverClassName(props.get().getProperty("spring.datasource.driver-class-name"));
    ds.setAutoCommit(props.get().getBool("spring.datasource.hikari.auto-commit", true));
    ds.setConnectionTimeout(props.get().getLong("spring.datasource.hikari.connection-timeout", 30000L));
    ds.setIdleTimeout(props.get().getLong("spring.datasource.hikari.idle-timeout", 600000L));
    ds.setMaxLifetime(props.get().getLong("spring.datasource.hikari.max-lifetime", 1800000L));
    ds.setConnectionTestQuery(props.get().getProperty("spring.datasource.hikari.connection-test-query"));
    ds.setMinimumIdle(props.get().getInt("spring.datasource.hikari.minimum-idle", 10));
    ds.setMaximumPoolSize(props.get().getInt("spring.datasource.hikari.maximum-pool-size", 100));
    ds.setPoolName(props.get().getProperty("spring.datasource.hikari.pool-name"));
    ds.setReadOnly(props.get().getBool("spring.datasource.hikari.read-only", false));
    ConnectionSource connectionSource = ConnectionSourceHelper.getSingle(ds);
    String sqlPath = props.get().getProperty("beetlsql.sqlManager1.sqlPath");
    String charset = props.get().getProperty("beetlsql.sqlManager1.sqlFileCharset");
    SQLManagerBuilder sqlManagerBuilder = SQLManager.newBuilder(connectionSource)
            .setDbStyle(new MySqlStyle())
            .setNc(new UnderlinedNameConversion())
            .setSqlLoader(sqlPath, charset);
    return sqlManagerBuilder.build();
}

public static SimpleMavenProject createBaseProject() {
    AtomicReference<Props> props = new AtomicReference<>(new Props("application.properties"));
    String basePackage = props.get().getProperty("beetlsql.sqlManager1.basePackage");
    SimpleMavenProject project = new SimpleMavenProject();
    project.setBasePackage(basePackage);
    return project;
}

public static List<SourceBuilder> createSourceBuilder() {
    List<SourceBuilder> sourceBuilder = new ArrayList<>();
    SourceBuilder entityBuilder = new EntitySourceBuilder();
    SourceBuilder mapperBuilder = new MapperSourceBuilder();
    SourceBuilder mdBuilder = new MDSourceBuilder();
    sourceBuilder.add(entityBuilder);
    sourceBuilder.add(mapperBuilder);
    sourceBuilder.add(mdBuilder);
    return sourceBuilder;
}

} 原先的代码如下,将Hikari换成BeeCP后报错内容如下: Exception in thread "main" java.lang.NullPointerException at cn.beecp.pool.ProxyResultSetBase.close(ProxyResultSetBase.java:73) at org.beetl.sql.core.meta.SchemaMetadataManager.initMetadata(SchemaMetadataManager.java:257) at org.beetl.sql.core.meta.SchemaMetadataManager.allTable(SchemaMetadataManager.java:96) at org.beetl.sql.gen.SourceConfig.genAll(SourceConfig.java:176) at org.beetl.sql.gen.SourceConfig.genAll(SourceConfig.java:194) at com.msj.beetlsqldemo.util.MysqlGenerator.main(MysqlGenerator.java:26)

版本:3.1.5(1.6.9不报错)

Chris2018998 commented 3 years ago

好的,马上看看

Chris2018998 commented 3 years ago

这个错误的原因是: 从DatabaseMetaData上获得Resultset是没有为Restult附加owner属性导致,因此关闭时导致异常。 目前已经修复,临时包:https://github.com/Chris2018998/BeeCP/blob/master/doc/temp/beecp-3.1.6.jar