All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.flood.log.config.DruidDbProperties Maven / Gradle / Ivy

The newest version!
package cn.flood.log.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * 
* 

Title: DruidDbProperties

*

Description:

* @author mmdai * @date 2020年8月21日 */ @Data @ConfigurationProperties(prefix = "spring.audit-log.datasource.druid") public class DruidDbProperties { /** * 初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时 */ private int initialSize = 10; /** * 最小连接池数量 */ private int minIdle = 20; /** * 最大连接池数量 */ private int maxActive = 50; /** * 获取连接时最大等待时间,单位毫秒。配置了maxWait之后,缺省启用公平锁,并发效率会有所下降,如果需要可以通过配置useUnfairLock属性为true使用非公平锁。 */ private int maxWait = 30000; /** * 有两个含义: 1) * Destroy线程会检测连接的间隔时间,如果连接空闲时间大于等于minEvictableIdleTimeMillis则关闭物理连接。 2) * testWhileIdle的判断依据,详细看testWhileIdle属性的说明 */ private int timeBetweenEvictionRunsMillis = 60000; /** * 连接保持空闲而不被驱逐的最长时间 */ private int minEvictableIdleTimeMillis = 300000; /** * 用来检测连接是否有效的sql,要求是一个查询语句,常用select * 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会其作用。 */ private String validationQuery = "SELECT 1"; /** * 单位:秒,检测连接是否有效的超时时间。底层调用jdbc Statement对象的void setQueryTimeout(int seconds)方法 */ private int validationQueryTimeout = 5; /** * 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。 */ private boolean testWhileIdle = true; /** * 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */ private boolean testOnBorrow = false; /** * 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */ private boolean testOnReturn = false; /** * 当程序存在缺陷时,申请的连接忘记关闭,这时候,就存在连接泄漏了。Druid提供了RemoveAbandanded相关配置,用来关闭长时间不使用的连接。 * 注:配置removeAbandoned对性能会有一些影响,建议怀疑存在泄漏之后再打开。在上面的配置中,如果连接超过30分钟未关闭,就会被强行回收,并且日志记录连接申请时的调用堆栈 */ private boolean removeAbandoned = true; /** * 连接超时多长时间关闭,单位秒 */ private int removeAbandonedTimeout = 90; /** * 默认值为false。是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。在mysql下建议关闭 */ private boolean poolPreparedStatements = false; /** * 默认值-1。要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。 * 在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100 */ private int maxPoolPreparedStatementPerConnectionSize = 20; /** * 属性类型是字符串,通过别名的方式配置扩展插件,常用的插件有: 监控统计用的filter:stat 日志用的filter:log4j * 防御sql注入的filter:wall */ private String filters = "mergeStat,config,wall"; /** * 通过connectProperties属性来打开mergeSql功能;慢SQL记录 */ private String connectionProperties = "druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000"; /** * 合并多个DruidDataSource的监控数据 */ private boolean useGlobalDataSourceStat = true; /** * 白名单 */ private String allow = ""; /** * 黑名单 */ private String deny =""; public int getInitialSize() { return initialSize; } public void setInitialSize(int initialSize) { this.initialSize = initialSize; } public int getMinIdle() { return minIdle; } public void setMinIdle(int minIdle) { this.minIdle = minIdle; } public int getMaxActive() { return maxActive; } public void setMaxActive(int maxActive) { this.maxActive = maxActive; } public int getMaxWait() { return maxWait; } public void setMaxWait(int maxWait) { this.maxWait = maxWait; } public int getTimeBetweenEvictionRunsMillis() { return timeBetweenEvictionRunsMillis; } public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) { this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; } public int getMinEvictableIdleTimeMillis() { return minEvictableIdleTimeMillis; } public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) { this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; } public String getValidationQuery() { return validationQuery; } public void setValidationQuery(String validationQuery) { this.validationQuery = validationQuery; } public boolean isTestWhileIdle() { return testWhileIdle; } public void setTestWhileIdle(boolean testWhileIdle) { this.testWhileIdle = testWhileIdle; } public boolean isTestOnBorrow() { return testOnBorrow; } public void setTestOnBorrow(boolean testOnBorrow) { this.testOnBorrow = testOnBorrow; } public boolean isTestOnReturn() { return testOnReturn; } public void setTestOnReturn(boolean testOnReturn) { this.testOnReturn = testOnReturn; } public String getFilters() { return filters; } public void setFilters(String filters) { this.filters = filters; } public String getConnectionProperties() { return connectionProperties; } public void setConnectionProperties(String connectionProperties) { this.connectionProperties = connectionProperties; } public String getAllow() { return allow; } public void setAllow(String allow) { this.allow = allow; } public String getDeny() { return deny; } public void setDeny(String deny) { this.deny = deny; } public int getValidationQueryTimeout() { return validationQueryTimeout; } public void setValidationQueryTimeout(int validationQueryTimeout) { this.validationQueryTimeout = validationQueryTimeout; } public boolean isRemoveAbandoned() { return removeAbandoned; } public void setRemoveAbandoned(boolean removeAbandoned) { this.removeAbandoned = removeAbandoned; } public int getRemoveAbandonedTimeout() { return removeAbandonedTimeout; } public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) { this.removeAbandonedTimeout = removeAbandonedTimeout; } public boolean isPoolPreparedStatements() { return poolPreparedStatements; } public void setPoolPreparedStatements(boolean poolPreparedStatements) { this.poolPreparedStatements = poolPreparedStatements; } public int getMaxPoolPreparedStatementPerConnectionSize() { return maxPoolPreparedStatementPerConnectionSize; } public void setMaxPoolPreparedStatementPerConnectionSize(int maxPoolPreparedStatementPerConnectionSize) { this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize; } public boolean isUseGlobalDataSourceStat() { return useGlobalDataSourceStat; } public void setUseGlobalDataSourceStat(boolean useGlobalDataSourceStat) { this.useGlobalDataSourceStat = useGlobalDataSourceStat; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy