Chris2018998 / beecp

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

支持国产数据库吗?现在单位用的金仓 #41

Closed biankobe24 closed 3 years ago

biankobe24 commented 3 years ago

不支持的话,以后考虑支持么?还有这个支持jdk8或者更高版本吗?

Chris2018998 commented 3 years ago

一般提供标准化JDBC驱动的数据库,理论上说应该可以的,我先了解一下这个数据库,过几天做个测试验证看看。

biankobe24 commented 3 years ago

一般提供标准化JDBC驱动的数据库,理论上说应该可以的,我先了解一下这个数据库,过几天做个测试验证看看。

明天我去单位用你这个试下,考虑打算支持更高版本么?现在新项目都是1.8起步了

Chris2018998 commented 3 years ago

3.x版本是可以支持Java8的, 未来考虑支持更高版本.

biankobe24 commented 3 years ago

版本:数据库mysql8.0,jdk11,spingboot 初步测试了一小时,3.1.8版本是支持jdk11的,可以成功启动,也能正常查询,其他未测试。 但是缓存bBeeCP-Starter会报错: Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beeDataSource' defined in class path resource [cn/beecp/boot/datasource/SingleDataSourceRegister.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'beeDataSource' threw exception; nested exception is cn.beecp.boot.datasource.factory.SpringBootDataSourceException: Failed to set config value to sql-trace pool at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1179) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1503) ~[spring-beans-5.3.3.jar:5.3.3] ... 37 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beeDataSource' defined in class path resource [cn/beecp/boot/datasource/SingleDataSourceRegister.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'beeDataSource' threw exception; nested exception is cn.beecp.boot.datasource.factory.SpringBootDataSourceException: Failed to set config value to sql-trace pool at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1179) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.3.jar:5.3.3] ... 50 common frames omitted Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'beeDataSource' threw exception; nested exception is cn.beecp.boot.datasource.factory.SpringBootDataSourceException: Failed to set config value to sql-trace pool at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.3.jar:5.3.3] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.3.jar:5.3.3] ... 64 common frames omitted Caused by: cn.beecp.boot.datasource.factory.SpringBootDataSourceException: Failed to set config value to sql-trace pool at cn.beecp.boot.datasource.SingleDataSourceRegister.configSqlTracePool(SingleDataSourceRegister.java:99) ~[beecp-spring-boot-starter-1.5.3.jar:na] at cn.beecp.boot.datasource.SingleDataSourceRegister.beeDataSource(SingleDataSourceRegister.java:60) ~[beecp-spring-boot-starter-1.5.3.jar:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.3.jar:5.3.3] ... 65 common frames omitted Caused by: cn.beecp.BeeDataSourceConfigException: Properties value map can't be empty at cn.beecp.pool.PoolStaticCenter.setPropertiesValue(PoolStaticCenter.java:162) ~[beecp-3.1.7.jar:na] at cn.beecp.boot.datasource.SingleDataSourceRegister.configSqlTracePool(SingleDataSourceRegister.java:92) ~[beecp-spring-boot-starter-1.5.3.jar:na] ... 71 common frames omitted

另外,BeeDataSourceConfig.java这个类connectionTestSQL ,使用private String connectionTestSQL = "SELECT 1"比较好;

Chris2018998 commented 3 years ago

感谢您的反馈,我尽快排查一下,能把beecp-starter的配置贴一下吗?

Chris2018998 commented 3 years ago

可能是配置項格式有点问题,导致代码没有读取到信息,这里有一个参考例子:

https://github.com/Chris2018998/BeeCP-Starter/blob/master/doc/SingleDsDemo_JPA.rar

biankobe24 commented 3 years ago

可能是配置項格式有点问题,导致代码没有读取到信息,这里有一个参考例子:

https://github.com/Chris2018998/BeeCP-Starter/blob/master/doc/SingleDsDemo_JPA.rar

配置: spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver username: root password: root url: jdbc:mysql://localhost:3306/ry?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai type: cn.beecp.BeeDataSource poolName: BeeCP connection-test-s-q-l: SELECT 1

这个用3.1.8版本就没问题

Chris2018998 commented 3 years ago

下个版本调整一下为:connection-test-sql

biankobe24 commented 3 years ago

下个版本调整一下为:connection-test-sql

早上单位试过了,这个链接不了金仓数据库,创建dataSource失败

Chris2018998 commented 3 years ago

异常产生原因:在springboot下未读取到配置項信息导致的。麻烦提供springboot,数据库,还有驱动的版本信息。我做个例子验证一下。

biankobe24 commented 3 years ago

https://gitee.com/b1an/bian/tree/master 都在里面

biankobe24 commented 3 years ago

之前金仓配置有点问题,现在可以用,但是走到FastConnectionPool这个类,rawCon.getNetworkTimeout();这个值获取不到,抛出异常,这个能改进支持下吗

[WARN ] [2021-04-30 14:48:15] BeeCP(FastPool-1)driver not support 'networkTimeout' [INFO ] [2021-04-30 14:48:15] BeeCP(FastPool-1)has startup{mode:compete,init size:1,max size:10,semaphore size:5,max wait:8000ms,driver:com.kingbase.Driver}

biankobe24 commented 3 years ago

另外老项目是在application-datasource.xml配置一个bean, 阿里的Druid是这么配置的 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> BeeCp我是这么配置的: <bean id="dataSource" class="cn.beecp.BeeDataSource" destroy-method="close">

请问下这个不需要inin-method么?在BeeDataSource没看到init方法

Chris2018998 commented 3 years ago

我刚安装了一个金仓数据库,是可以跑的的 image image

Chris2018998 commented 3 years ago

之前金仓配置有点问题,现在可以用,但是走到FastConnectionPool这个类,rawCon.getNetworkTimeout();这个值获取不到,抛出异常,这个能改进支持下吗

[WARN ] [2021-04-30 14:48:15] BeeCP(FastPool-1)driver not support 'networkTimeout' [INFO ] [2021-04-30 14:48:15] BeeCP(FastPool-1)has startup{mode:compete,init size:1,max size:10,semaphore size:5,max wait:8000ms,driver:com.kingbase.Driver}

一句警告信息,说明驱动不支持networkTimeout,那么就不可以通过SetNetworkTimeout方法来修改底层Socket的Read时间。

连接池端不用做什么处理。

image

Chris2018998 commented 3 years ago

另外老项目是在application-datasource.xml配置一个bean, 阿里的Druid是这么配置的 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> BeeCp我是这么配置的: <bean id="dataSource" class="cn.beecp.BeeDataSource" destroy-method="close">

请问下这个不需要inin-method么?在BeeDataSource没看到init方法

BeeCP是支持Lazy方式, 不用配置Init方法

biankobe24 commented 3 years ago

我刚安装了一个金仓数据库,是可以跑的的 image image

谢谢,可以跑我这个用单位的上午试过了,金仓的驱动信息里面确实没这个值,打断点跟着跑了,看了rawCon确实没有,这个能优化下日志么,感觉也不是每个数据库都会支持这个,打个warn日志会感觉这个驱动不是很兼容

Tbdgithub commented 3 years ago

一般提供标准化JDBC驱动的数据库,理论上说应该可以的,我先了解一下这个数据库,过几天做个测试验证看看。 建议适配所有国产数据库

Chris2018998 commented 3 years ago

@Tbdgithub 不好意思,没有注意到你的信息。 时间过去比较久的issue可能不会太注意到。

后面我试一下其他国产数据库。