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

com.bixuebihui.dbcon.DatabaseConfig Maven / Gradle / Ivy

Go to download

a fast small database connection pool and a active record flavor mini framework

There is a newer version: 1.15.3.3
Show newest version
package com.bixuebihui.dbcon;

import com.bixuebihui.filter.IFilter;
import org.apache.commons.lang3.StringUtils;

import java.util.Properties;

/**
 * 数据库(链接池)的基本参数
 *
 * @author yexf
 * @version $Id: $Id
 */
public class DatabaseConfig
{
	private String alias;
	private String className;
	private String dburl;
	private String username;
	private String password;
	private int maxIdle;
	private int maxActive;
	/** 最大等待时间,毫秒 */
	private long maxWaitTime;
	/** 每个连接最大的使用次数,超出后自动回收 //bitmechanicDatasource */
	private int maxCheckOutCount;
	/** DbcpDataSource & bitmechanicDatasource */
	private int maxOpenPreparedStatements;
	private int sleepIntervalInSeconds;
	/** for DruidDataSource */
	private boolean removeAbandoned;

    /**
     * 

Constructor for DatabaseConfig.

*/ public DatabaseConfig(){ alias = ""; className = ""; dburl = ""; username = ""; maxIdle = 10; maxActive = 30; /** * 最大等待时间,毫秒 */ maxWaitTime = 300000; /** 每个连接最大的使用次数,超出后自动回收 bitmechanicDatasource */ setMaxCheckOutCount(5000); /** DbcpDataSource & bitmechanicDatasource */ maxOpenPreparedStatements=200; sleepIntervalInSeconds = 300; setRemoveAbandoned(false); } private IFilter filter= null; /** *

Getter for the field alias.

* * @return a {@link java.lang.String} object. */ public String getAlias() { return alias; } /** *

Setter for the field alias.

* * @param alias a {@link java.lang.String} object. */ public void setAlias(String alias) { this.alias = alias; } /** *

Getter for the field className.

* * @return a {@link java.lang.String} object. */ public String getClassName() { return className; } /** *

Setter for the field className.

* * @param className a {@link java.lang.String} object. */ public void setClassName(String className) { this.className = className; } /** *

Getter for the field dburl.

* * @return a {@link java.lang.String} object. */ public String getDburl() { if(filter!=null){ return filter.filter(dburl); } return dburl; } /** *

Setter for the field dburl.

* * @param dburl a {@link java.lang.String} object. */ public void setDburl(String dburl) { this.dburl = dburl; } /** *

Getter for the field maxActive.

* * @return a int. */ public int getMaxActive() { return maxActive; } /** *

Setter for the field maxActive.

* * @param maxActive a int. */ public void setMaxActive(int maxActive) { this.maxActive = maxActive; } /** *

Getter for the field maxIdle.

* * @return a int. */ public int getMaxIdle() { return maxIdle; } /** *

Setter for the field maxIdle.

* * @param maxIdle a int. */ public void setMaxIdle(int maxIdle) { this.maxIdle = maxIdle; } /** *

Getter for the field maxWaitTime.

* * @return a long. */ public long getMaxWaitTime() { return maxWaitTime; } /** *

Setter for the field maxWaitTime.

* * @param maxWaitTime a long. */ public void setMaxWaitTime(long maxWaitTime) { this.maxWaitTime = maxWaitTime; } /** *

Getter for the field password.

* * @return a {@link java.lang.String} object. */ public String getPassword() { return password; } /** *

Setter for the field password.

* * @param password a {@link java.lang.String} object. */ public void setPassword(String password) { this.password = password; } /** *

Getter for the field username.

* * @return a {@link java.lang.String} object. */ public String getUsername() { return username; } /** *

Setter for the field username.

* * @param username a {@link java.lang.String} object. */ public void setUsername(String username) { this.username = username; } /** *

Getter for the field filter.

* * @return a {@link IFilter} object. */ public IFilter getFilter() { return filter; } /** *

Setter for the field filter.

* * @param filter a {@link IFilter} object. */ public void setFilter(IFilter filter) { this.filter = filter; } /** *

Getter for the field maxOpenPreparedStatements.

* * @return a int. */ public int getMaxOpenPreparedStatements() { return maxOpenPreparedStatements; } /** *

Setter for the field maxOpenPreparedStatements.

* * @param maxOpenPreparedStatements a int. */ public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) { this.maxOpenPreparedStatements = maxOpenPreparedStatements; } /** *

Getter for the field sleepIntervalInSeconds.

* * @return a int. */ public int getSleepIntervalInSeconds() { return sleepIntervalInSeconds; } /** *

Setter for the field sleepIntervalInSeconds.

* * @param sleepIntervalInSeconds a int. */ public void setSleepIntervalInSeconds(int sleepIntervalInSeconds) { this.sleepIntervalInSeconds = sleepIntervalInSeconds; } /** *

toString.

* * @return a {@link java.lang.String} object. */ @Override public String toString(){ return this.getClass()+"(alias = "+alias+ ",className = "+className+ ",dburl = "+dburl+ ",username = "+username+ ",password = ******"+ ",maxIdle = "+maxIdle+ ",maxActive = "+maxActive+ ",maxWaitTime = "+maxWaitTime+ //最大等待时间,毫秒 ",maxCheckOutCount="+getMaxCheckOutCount()+ //每个连接最大的使用次数,超出后自动回收 //bitmechanicDatasource ",maxOpenPreparedStatements="+maxOpenPreparedStatements+ //DbcpDataSource & bitmechanicDatasource ",removeAbandoned="+isRemoveAbandoned()+ ",sleepIntervalInSeconds = "+sleepIntervalInSeconds+")"; } /** *

Getter for the field maxCheckOutCount.

* * @return a int. */ public int getMaxCheckOutCount() { return maxCheckOutCount; } /** *

Setter for the field maxCheckOutCount.

* * @param maxCheckOutCount a int. */ public void setMaxCheckOutCount(int maxCheckOutCount) { this.maxCheckOutCount = maxCheckOutCount; } /** *

isRemoveAbandoned.

* * @return a boolean. */ public boolean isRemoveAbandoned() { return removeAbandoned; } /** *

Setter for the field removeAbandoned.

* * @param removeAbandoned a boolean. */ public void setRemoveAbandoned(boolean removeAbandoned) { this.removeAbandoned = removeAbandoned; } public static DatabaseConfig newInstance(Properties props) { DatabaseConfig config = new DatabaseConfig(); config.setAlias(props.getProperty("alias")); config.setClassName(props.getProperty("className")); config.setDburl(props.getProperty("dburl")); config.setUsername(props.getProperty("username")); config.setPassword(props.getProperty("password")); if (StringUtils.trimToNull(config.getAlias()) == null) { config.setAlias("defaultdbcpalias"); } return config; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy