List of usage examples for org.apache.commons.dbcp BasicDataSource setMaxWait
public synchronized void setMaxWait(long maxWait)
From source file:com.alibaba.otter.manager.biz.common.DataSourceCreator.java
private DataSource createDataSource(String url, String userName, String password, String driverClassName, DataMediaType dataMediaType, String encoding) { BasicDataSource dbcpDs = new BasicDataSource(); dbcpDs.setInitialSize(initialSize);// ? dbcpDs.setMaxActive(maxActive);// ????? dbcpDs.setMaxIdle(maxIdle);// ?? dbcpDs.setMinIdle(minIdle);// ?0? dbcpDs.setMaxWait(maxWait);// ??-1? dbcpDs.setRemoveAbandoned(true);// ??removeAbandonedTimeout dbcpDs.setLogAbandoned(true);// ?? dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // ? dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// ?? dbcpDs.setTestOnBorrow(false);// ?? dbcpDs.setTestOnReturn(false);// ?? dbcpDs.setTestWhileIdle(true);// ???? dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // ???????? dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // ??????? // ??//w ww . ja v a 2s. c o m dbcpDs.setDriverClassName(driverClassName); dbcpDs.setUrl(url); dbcpDs.setUsername(userName); dbcpDs.setPassword(password); if (dataMediaType.isOracle()) { dbcpDs.addConnectionProperty("restrictGetTables", "true"); // dbcpDs.setValidationQuery("select 1 from dual"); } else if (dataMediaType.isMysql()) { // open the batch mode for mysql since 5.1.8 dbcpDs.addConnectionProperty("useServerPrepStmts", "false"); dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true"); dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 0000-00-00null dbcpDs.addConnectionProperty("yearIsDateType", "false");// ??year?date? dbcpDs.addConnectionProperty("noDatetimeStringSync", "true");// ,??? if (StringUtils.isNotEmpty(encoding)) { if (StringUtils.equalsIgnoreCase(encoding, "utf8mb4")) { dbcpDs.addConnectionProperty("characterEncoding", "utf8"); dbcpDs.setConnectionInitSqls(Arrays.asList("set names utf8mb4")); } else { dbcpDs.addConnectionProperty("characterEncoding", encoding); } } // dbcpDs.setValidationQuery("select 1"); } else { logger.error("ERROR ## Unknow database type"); } return dbcpDs; }
From source file:com.alibaba.otter.node.etl.common.datasource.impl.DBDataSourceService.java
private DataSource createDataSource(String url, String userName, String password, String driverClassName, DataMediaType dataMediaType, String encoding) { BasicDataSource dbcpDs = new BasicDataSource(); dbcpDs.setInitialSize(initialSize);// ? dbcpDs.setMaxActive(maxActive);// ????? dbcpDs.setMaxIdle(maxIdle);// ?? dbcpDs.setMinIdle(minIdle);// ?0? dbcpDs.setMaxWait(maxWait);// ??-1? dbcpDs.setRemoveAbandoned(true);// ??removeAbandonedTimeout dbcpDs.setLogAbandoned(true);// ?? dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // ? dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// ?? dbcpDs.setTestOnBorrow(false);// ?? dbcpDs.setTestOnReturn(false);// ?? dbcpDs.setTestWhileIdle(true);// ???? dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // ???????? dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // ??????? // ??/*w w w . j a va2 s.co m*/ dbcpDs.setDriverClassName(driverClassName); dbcpDs.setUrl(url); dbcpDs.setUsername(userName); dbcpDs.setPassword(password); if (dataMediaType.isOracle()) { dbcpDs.addConnectionProperty("restrictGetTables", "true"); dbcpDs.setValidationQuery("select 1 from dual"); } else if (dataMediaType.isMysql()) { // open the batch mode for mysql since 5.1.8 dbcpDs.addConnectionProperty("useServerPrepStmts", "false"); dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true"); dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 0000-00-00null dbcpDs.addConnectionProperty("yearIsDateType", "false");// ??year?date? dbcpDs.addConnectionProperty("noDatetimeStringSync", "true");// ,??? if (StringUtils.isNotEmpty(encoding)) { if (StringUtils.equalsIgnoreCase(encoding, "utf8mb4")) { dbcpDs.addConnectionProperty("characterEncoding", "utf8"); dbcpDs.setConnectionInitSqls(Arrays.asList("set names utf8mb4")); } else { dbcpDs.addConnectionProperty("characterEncoding", encoding); } } dbcpDs.setValidationQuery("select 1"); } else { logger.error("ERROR ## Unknow database type"); } return dbcpDs; }
From source file:com.googlesource.gerrit.plugins.verifystatus.server.schema.CiDataSourceProvider.java
private DataSource open(Context context, CiDataSourceType dst) { // ConfigSection dbs = new ConfigSection(cfg, "database"); String driver = config.getString("driver"); if (Strings.isNullOrEmpty(driver)) { driver = dst.getDriver();// w ww . jav a 2 s .c om } String url = config.getString("dbUrl"); if (Strings.isNullOrEmpty(url)) { url = dst.getUrl(); } String username = config.getString("username"); String password = config.getString("password"); String interceptor = config.getString("dataSourceInterceptorClass"); boolean usePool; if (context == Context.SINGLE_USER) { usePool = false; } else { usePool = config.getBoolean("connectionpool", dst.usePool()); } if (usePool) { final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUrl(url); if (username != null && !username.isEmpty()) { ds.setUsername(username); } if (password != null && !password.isEmpty()) { ds.setPassword(password); } ds.setMaxActive(config.getInt("poollimit", DEFAULT_POOL_LIMIT)); ds.setMinIdle(config.getInt("poolminidle", 4)); ds.setMaxIdle(config.getInt("poolmaxidle", 4)); String valueString = config.getString("poolmaxwait"); if (Strings.isNullOrEmpty(valueString)) { ds.setMaxWait(MILLISECONDS.convert(30, SECONDS)); } else { ds.setMaxWait(ConfigUtil.getTimeUnit(valueString, MILLISECONDS.convert(30, SECONDS), MILLISECONDS)); } ds.setInitialSize(ds.getMinIdle()); exportPoolMetrics(ds); return intercept(interceptor, ds); } // Don't use the connection pool. try { Properties p = new Properties(); p.setProperty("driver", driver); p.setProperty("url", url); if (username != null) { p.setProperty("user", username); } if (password != null) { p.setProperty("password", password); } return intercept(interceptor, new SimpleDataSource(p)); } catch (SQLException se) { throw new ProvisionException("Database unavailable", se); } }
From source file:com.googlesource.gerrit.plugins.ci.server.schema.CiDataSourceProvider.java
private DataSource open(Context context, CiDataSourceType dst) { //ConfigSection dbs = new ConfigSection(cfg, "database"); String driver = config.getString("driver"); if (Strings.isNullOrEmpty(driver)) { driver = dst.getDriver();//from w w w .jav a 2s .c om } String url = config.getString("dbUrl"); if (Strings.isNullOrEmpty(url)) { url = dst.getUrl(); } String username = config.getString("username"); String password = config.getString("password"); String interceptor = config.getString("dataSourceInterceptorClass"); boolean usePool; if (context == Context.SINGLE_USER) { usePool = false; } else { usePool = config.getBoolean("connectionpool", dst.usePool()); } if (usePool) { final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUrl(url); if (username != null && !username.isEmpty()) { ds.setUsername(username); } if (password != null && !password.isEmpty()) { ds.setPassword(password); } ds.setMaxActive(config.getInt("poollimit", DEFAULT_POOL_LIMIT)); ds.setMinIdle(config.getInt("poolminidle", 4)); ds.setMaxIdle(config.getInt("poolmaxidle", 4)); String valueString = config.getString("poolmaxwait"); if (Strings.isNullOrEmpty(valueString)) { ds.setMaxWait(MILLISECONDS.convert(30, SECONDS)); } else { ds.setMaxWait(ConfigUtil.getTimeUnit(valueString, MILLISECONDS.convert(30, SECONDS), MILLISECONDS)); } ds.setInitialSize(ds.getMinIdle()); exportPoolMetrics(ds); return intercept(interceptor, ds); } else { // Don't use the connection pool. // try { Properties p = new Properties(); p.setProperty("driver", driver); p.setProperty("url", url); if (username != null) { p.setProperty("user", username); } if (password != null) { p.setProperty("password", password); } return intercept(interceptor, new SimpleDataSource(p)); } catch (SQLException se) { throw new ProvisionException("Database unavailable", se); } } }
From source file:com.alibaba.otter.common.push.datasource.media.MediaPushDataSource.java
protected DataSource doCreateDataSource(String url) { BasicDataSource dbcpDs = new BasicDataSource(); dbcpDs.setInitialSize(initialSize);// ? dbcpDs.setMaxActive(maxActive);// ????? dbcpDs.setMaxIdle(maxIdle);// ?? dbcpDs.setMinIdle(minIdle);// ?0? dbcpDs.setMaxWait(maxWait);// ??-1? dbcpDs.setRemoveAbandoned(true);// ??removeAbandonedTimeout dbcpDs.setLogAbandoned(true);// ?? dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // ? dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// ?? dbcpDs.setTestOnBorrow(false);// ?? dbcpDs.setTestOnReturn(false);// ?? dbcpDs.setTestWhileIdle(true);// ???? dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // ???????? dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // ??????? // ??/*from w w w. j a va 2s.c om*/ dbcpDs.setDriverClassName(driverClassName); dbcpDs.setUrl(url); dbcpDs.setUsername(userName); dbcpDs.setPassword(password); if (dataMediaType.isOracle()) { dbcpDs.addConnectionProperty("restrictGetTables", "true"); dbcpDs.setValidationQuery("select 1 from dual"); } else if (dataMediaType.isMysql()) { // open the batch mode for mysql since 5.1.8 dbcpDs.addConnectionProperty("useServerPrepStmts", "false"); dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true"); dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 0000-00-00null dbcpDs.addConnectionProperty("yearIsDateType", "false");// ??year?date? if (StringUtils.isNotEmpty(encoding)) { dbcpDs.addConnectionProperty("characterEncoding", encoding); } dbcpDs.setValidationQuery("select 1"); } else { logger.error("ERROR ## Unknow database type"); } return dbcpDs; }
From source file:net.comze.framework.orm.datasource.DbcpDataSourceFactory.java
private BasicDataSource initialize(Properties properties) { ObjectUtils.notNull(properties, "properties"); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(properties.getProperty(JDBC_DRIVER)); basicDataSource.setUrl(properties.getProperty(JDBC_URL)); basicDataSource.setUsername(properties.getProperty(JDBC_USERNAME)); basicDataSource.setPassword(properties.getProperty(JDBC_PASSWORD)); if (properties.containsKey(DBCP_INITIALSIZE)) { basicDataSource.setInitialSize(Integer.parseInt(properties.getProperty(DBCP_INITIALSIZE))); }//from www. j av a 2s .c o m if (properties.containsKey(DBCP_MAXACTIVE)) { basicDataSource.setMaxActive(Integer.parseInt(properties.getProperty(DBCP_MAXACTIVE))); } if (properties.containsKey(DBCP_MAXIDLE)) { basicDataSource.setMaxIdle(Integer.parseInt(properties.getProperty(DBCP_MAXIDLE))); } if (properties.containsKey(DBCP_MAXWAIT)) { basicDataSource.setMaxWait(Long.parseLong(properties.getProperty(DBCP_MAXWAIT))); } if (properties.containsKey(DBCP_MINEVICTABLEIDLETIMEMILLIS)) { basicDataSource.setMinEvictableIdleTimeMillis( Long.parseLong(properties.getProperty(DBCP_MINEVICTABLEIDLETIMEMILLIS))); } if (properties.containsKey(DBCP_MINIDLE)) { basicDataSource.setMinIdle(Integer.parseInt(properties.getProperty(DBCP_MINIDLE))); } if (properties.containsKey(DBCP_NUMTESTSPEREVICTIONRUN)) { basicDataSource.setNumTestsPerEvictionRun( Integer.parseInt(properties.getProperty(DBCP_NUMTESTSPEREVICTIONRUN))); } if (properties.containsKey(DBCP_REMOVEABANDONED)) { basicDataSource.setRemoveAbandoned(Boolean.parseBoolean(properties.getProperty(DBCP_REMOVEABANDONED))); } if (properties.containsKey(DBCP_REMOVEABANDONEDTIMEOUT)) { basicDataSource.setRemoveAbandonedTimeout( Integer.parseInt(properties.getProperty(DBCP_REMOVEABANDONEDTIMEOUT))); } if (properties.containsKey(DBCP_TESTONBORROW)) { basicDataSource.setTestOnBorrow(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONBORROW))); } if (properties.containsKey(DBCP_TESTONCREATE)) { basicDataSource.setTestOnReturn(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONCREATE))); } if (properties.containsKey(DBCP_TESTONRETURN)) { basicDataSource.setTestOnReturn(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONRETURN))); } if (properties.containsKey(DBCP_TESTWHILEIDLE)) { basicDataSource.setTestWhileIdle(Boolean.parseBoolean(properties.getProperty(DBCP_TESTWHILEIDLE))); } if (properties.containsKey(DBCP_TIMEBETWEENEVICTIONRUNSMILLIS)) { basicDataSource.setTimeBetweenEvictionRunsMillis( Long.parseLong(properties.getProperty(DBCP_TIMEBETWEENEVICTIONRUNSMILLIS))); } if (properties.containsKey(DBCP_VALIDATIONQUERY)) { basicDataSource.setValidationQuery(properties.getProperty(DBCP_VALIDATIONQUERY)); } if (properties.containsKey(DBCP_VALIDATIONQUERYTIMEOUT)) { basicDataSource.setValidationQueryTimeout( Integer.parseInt(properties.getProperty(DBCP_VALIDATIONQUERYTIMEOUT))); } return basicDataSource; }
From source file:com.alfaariss.oa.util.database.jdbc.DataSourceFactory.java
private static DataSource addOptionalSettings(IConfigurationManager configurationManager, Element eConfig, BasicDataSource dataSource) throws DatabaseException { try {/*w w w .j a v a 2s . c o m*/ String sMaxActive = configurationManager.getParam(eConfig, "maxactive"); int iMaxActive = -1; if (sMaxActive != null) { try { iMaxActive = Integer.parseInt(sMaxActive); } catch (NumberFormatException e) { _logger.error("Wrong 'maxactive' item found in configuration: " + sMaxActive, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } } dataSource.setMaxActive(iMaxActive); String sMaxIdle = configurationManager.getParam(eConfig, "maxidle"); if (sMaxIdle != null) { int iMaxIdle = -1; try { iMaxIdle = Integer.parseInt(sMaxIdle); } catch (NumberFormatException e) { _logger.error("Wrong 'maxidle' item found in configuration: " + sMaxIdle, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setMaxIdle(iMaxIdle); } String sMaxWait = configurationManager.getParam(eConfig, "maxwait"); if (sMaxWait != null) { int iMaxWait = -1; try { iMaxWait = Integer.parseInt(sMaxWait); } catch (NumberFormatException e) { _logger.error("Wrong 'maxwait' item found in configuration: " + sMaxWait, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setMaxWait(iMaxWait); } String sTestOnBorrow = configurationManager.getParam(eConfig, "testonborrow"); if (sTestOnBorrow != null) { boolean bTestOnBorrow = false; if (sTestOnBorrow.equalsIgnoreCase("true")) bTestOnBorrow = true; else if (!sTestOnBorrow.equalsIgnoreCase("false")) { _logger.error("Wrong 'testonborrow' item found in configuration: " + sTestOnBorrow); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setTestOnBorrow(bTestOnBorrow); } String sTestOnReturn = configurationManager.getParam(eConfig, "testonreturn"); if (sTestOnReturn != null) { boolean bTestOnReturn = false; if (sTestOnReturn.equalsIgnoreCase("true")) bTestOnReturn = true; else if (!sTestOnReturn.equalsIgnoreCase("false")) { _logger.error("Wrong 'testonreturn' item found in configuration: " + sTestOnReturn); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setTestOnReturn(bTestOnReturn); } String sTimeBetweenEvictionRunsMillis = configurationManager.getParam(eConfig, "timebetweenevictionrunsmillis"); if (sTimeBetweenEvictionRunsMillis != null) { try { long lTimeBetweenEvictionRunsMillis = Long.parseLong(sTimeBetweenEvictionRunsMillis); dataSource.setTimeBetweenEvictionRunsMillis(lTimeBetweenEvictionRunsMillis); } catch (NumberFormatException e) { _logger.error("Wrong 'timebetweenevictionrunsmillis' item found in configuration: " + sTimeBetweenEvictionRunsMillis, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } } String sNumTestsPerEvictionRun = configurationManager.getParam(eConfig, "numtestsperevictionrun"); if (sNumTestsPerEvictionRun != null) { int iNumTestsPerEvictionRun = -1; try { iNumTestsPerEvictionRun = Integer.parseInt(sNumTestsPerEvictionRun); } catch (NumberFormatException e) { _logger.error("Wrong 'numtestsperevictionrun' item found in configuration: " + sNumTestsPerEvictionRun, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setNumTestsPerEvictionRun(iNumTestsPerEvictionRun); } String sMinEvictableIdleTimeMillis = configurationManager.getParam(eConfig, "minevictableidletimemillis"); if (sMinEvictableIdleTimeMillis != null) { try { long lMinEvictableIdleTimeMillis = Long.parseLong(sMinEvictableIdleTimeMillis); dataSource.setMinEvictableIdleTimeMillis(lMinEvictableIdleTimeMillis); } catch (NumberFormatException e) { _logger.error("Wrong 'minevictableidletimemillis' item found in configuration: " + sMinEvictableIdleTimeMillis, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } } String sTestWhileIdle = configurationManager.getParam(eConfig, "testwhileidle"); if (sTestWhileIdle != null) { boolean bTestWhileIdle = false; if (sTestWhileIdle.equalsIgnoreCase("true")) bTestWhileIdle = true; else if (!sTestWhileIdle.equalsIgnoreCase("false")) { _logger.error("Wrong 'testwhileidle' item found in configuration: " + sTestWhileIdle); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setTestWhileIdle(bTestWhileIdle); } String sValidationQuery = configurationManager.getParam(eConfig, "validationquery"); if (sValidationQuery != null) { dataSource.setValidationQuery(sValidationQuery); } } catch (DatabaseException e) { throw e; } catch (Exception e) { _logger.fatal("Could not create datasource", e); throw new DatabaseException(SystemErrors.ERROR_INTERNAL); } return dataSource; }
From source file:com.bstek.dorado.core.store.SqlBaseStoreSupport.java
protected synchronized DataSource getDataSource() throws Exception { if (dataSource != null) { return dataSource; }//from w w w . j a v a2 s . c o m if (StringUtils.isBlank(namespace)) { throw new IllegalArgumentException("The namespace of store cannot be empty. "); } prepareNamespace(); BasicDataSource pds = new BasicDataSource(); dataSource = pds; pds.setDriverClassName(driverClassName); pds.setUrl(getConnectionUrl()); pds.setUsername(username); pds.setPassword(password); pds.setDefaultCatalog(defaultCatalog); if (defaultAutoCommit != null) { pds.setDefaultAutoCommit(defaultAutoCommit.booleanValue()); } if (defaultReadOnly != null) { pds.setDefaultReadOnly(defaultReadOnly.booleanValue()); } if (defaultTransactionIsolation != null) { pds.setDefaultTransactionIsolation(defaultTransactionIsolation.intValue()); } if (maxActive != null) { pds.setMaxActive(maxActive.intValue()); } if (maxIdle != null) { pds.setMaxIdle(maxIdle.intValue()); } if (minIdle != null) { pds.setMinIdle(minIdle.intValue()); } if (initialSize != null) { pds.setInitialSize(initialSize.intValue()); } if (maxWait != null) { pds.setMaxWait(maxWait.longValue()); } if (timeBetweenEvictionRunsMillis != null) { pds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis.longValue()); } if (minEvictableIdleTimeMillis != null) { pds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis.longValue()); } return dataSource; }
From source file:com.ibatis.common.jdbc.DbcpConfiguration.java
private BasicDataSource legacyDbcpConfiguration(Map map) { BasicDataSource basicDataSource = null; if (map.containsKey("JDBC.Driver")) { basicDataSource = new BasicDataSource(); String driver = (String) map.get("JDBC.Driver"); String url = (String) map.get("JDBC.ConnectionURL"); String username = (String) map.get("JDBC.Username"); String password = (String) map.get("JDBC.Password"); String validationQuery = (String) map.get("Pool.ValidationQuery"); String maxActive = (String) map.get("Pool.MaximumActiveConnections"); String maxIdle = (String) map.get("Pool.MaximumIdleConnections"); String maxWait = (String) map.get("Pool.MaximumWait"); basicDataSource.setUrl(url);/*from w ww . ja v a 2s . co m*/ basicDataSource.setDriverClassName(driver); basicDataSource.setUsername(username); basicDataSource.setPassword(password); if (notEmpty(validationQuery)) { basicDataSource.setValidationQuery(validationQuery); } if (notEmpty(maxActive)) { basicDataSource.setMaxActive(Integer.parseInt(maxActive)); } if (notEmpty(maxIdle)) { basicDataSource.setMaxIdle(Integer.parseInt(maxIdle)); } if (notEmpty(maxWait)) { basicDataSource.setMaxWait(Integer.parseInt(maxWait)); } Iterator props = map.keySet().iterator(); while (props.hasNext()) { String propertyName = (String) props.next(); if (propertyName.startsWith(ADD_DRIVER_PROPS_PREFIX)) { String value = (String) map.get(propertyName); basicDataSource.addConnectionProperty(propertyName.substring(ADD_DRIVER_PROPS_PREFIX_LENGTH), value); } } } return basicDataSource; }
From source file:jetsennet.orm.datasource.DbcpDataSourceCreator.java
@Override public DataSource createDatasource(ConnectionInfo conn, DbPoolInfo props) throws SQLException { org.apache.commons.dbcp.BasicDataSource dataSource = new org.apache.commons.dbcp.BasicDataSource(); dataSource.setDriverClassName(conn.driver); dataSource.setUrl(conn.url);/*from ww w. j av a 2 s .c o m*/ dataSource.setUsername(conn.user); dataSource.setPassword(conn.pwd); String connectionProperties = props.get("connectionProperties"); if (connectionProperties != null && connectionProperties.trim().length() > 0) { dataSource.setConnectionProperties(connectionProperties); } Boolean defaultAutoCommit = Utils.str2Boolean(props.get("defaultAutoCommit")); if (defaultAutoCommit != null) { dataSource.setDefaultAutoCommit(defaultAutoCommit); } Boolean defaultReadOnly = Utils.str2Boolean(props.get("defaultReadOnly")); if (defaultReadOnly != null) { dataSource.setDefaultReadOnly(defaultReadOnly); } Integer defaultTransactionIsolation = Utils.strToInteger(props.get("defaultTransactionIsolation")); if (defaultTransactionIsolation != null) { dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); } String defaultCatalog = props.get("defaultCatalog"); if (defaultCatalog != null && defaultCatalog.trim().length() > 0) { dataSource.setDefaultCatalog(defaultCatalog); } int initialSize = Utils.strToInt(props.get("initialSize")); if (initialSize > 0) { dataSource.setInitialSize(initialSize); } int maxActive = Utils.strToInt(props.get("maxActive")); if (maxActive > 0) { dataSource.setMaxActive(maxActive); } int maxIdle = Utils.strToInt(props.get("maxIdle")); if (maxIdle > 0) { dataSource.setMaxIdle(maxIdle); } int minIdle = Utils.strToInt(props.get("minIdle")); if (minIdle > 0) { dataSource.setMinIdle(minIdle); } int maxWait = Utils.strToInt(props.get("maxWait")); if (maxWait > 0) { dataSource.setMaxWait(maxWait); } String validationQuery = props.get("validationQuery"); if (validationQuery != null && validationQuery.trim().length() > 0) { dataSource.setValidationQuery(validationQuery); } Integer validationQueryTimeout = Utils.strToInteger(props.get("validationQueryTimeout")); if (validationQueryTimeout != null) { dataSource.setValidationQueryTimeout(validationQueryTimeout); } Boolean testOnBorrow = Utils.str2Boolean(props.get("testOnBorrow")); if (testOnBorrow != null) { dataSource.setTestOnBorrow(testOnBorrow); } Boolean testOnReturn = Utils.str2Boolean(props.get("testOnReturn")); if (testOnReturn != null) { dataSource.setTestOnReturn(testOnReturn); } Boolean testWhileIdle = Utils.str2Boolean(props.get("testWhileIdle")); if (testWhileIdle != null) { dataSource.setTestWhileIdle(testWhileIdle); } Integer timeBetweenEvictionRunsMillis = Utils.strToInteger(props.get("timeBetweenEvictionRunsMillis")); if (timeBetweenEvictionRunsMillis != null) { dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); } Integer numTestsPerEvictionRun = Utils.strToInteger(props.get("numTestsPerEvictionRun")); if (numTestsPerEvictionRun != null) { dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun); } int minEvictableIdleTimeMillis = Utils.strToInt(props.get("minEvictableIdleTimeMillis")); if (minEvictableIdleTimeMillis > 0) { dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); } Boolean removeAbandoned = Utils.str2Boolean(props.get("removeAbandoned")); if (removeAbandoned != null) { dataSource.setRemoveAbandoned(removeAbandoned); } int removeAbandonedTimeout = Utils.strToInt(props.get("removeAbandonedTimeout")); if (removeAbandonedTimeout > 0) { dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); } Boolean logAbandoned = Utils.str2Boolean(props.get("logAbandoned")); if (logAbandoned != null) { dataSource.setLogAbandoned(logAbandoned); } return dataSource; }