|
|
|
@ -17,13 +17,12 @@
|
|
|
|
|
|
|
|
|
|
package com.fr.third.v2.org.quartz.utils; |
|
|
|
|
|
|
|
|
|
import java.beans.PropertyVetoException; |
|
|
|
|
import java.sql.Connection; |
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
import java.util.Properties; |
|
|
|
|
|
|
|
|
|
import com.fr.third.alibaba.druid.pool.DruidDataSource; |
|
|
|
|
import com.fr.third.v2.org.quartz.SchedulerException; |
|
|
|
|
import com.mchange.v2.c3p0.ComboPooledDataSource; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* <p> |
|
|
|
@ -112,7 +111,7 @@ public class PoolingConnectionProvider implements ConnectionProvider {
|
|
|
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
private ComboPooledDataSource datasource; |
|
|
|
|
private DruidDataSource datasource; |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
|
|
@ -206,27 +205,35 @@ public class PoolingConnectionProvider implements ConnectionProvider {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
datasource = new ComboPooledDataSource(); |
|
|
|
|
try { |
|
|
|
|
datasource.setDriverClass(dbDriver); |
|
|
|
|
} catch (PropertyVetoException e) { |
|
|
|
|
throw new SchedulerException("Problem setting driver class name on datasource: " + e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
datasource.setJdbcUrl(dbURL); |
|
|
|
|
datasource.setUser(dbUser); |
|
|
|
|
datasource = new DruidDataSource(); |
|
|
|
|
datasource.setDriverClassName(dbDriver); |
|
|
|
|
datasource.setUrl(dbURL); |
|
|
|
|
datasource.setUsername(dbUser); |
|
|
|
|
datasource.setPassword(dbPassword); |
|
|
|
|
datasource.setMaxPoolSize(maxConnections); |
|
|
|
|
datasource.setMinPoolSize(1); |
|
|
|
|
datasource.setMaxIdleTime(maxIdleSeconds); |
|
|
|
|
datasource.setMaxStatementsPerConnection(maxStatementsPerConnection); |
|
|
|
|
datasource.setMaxActive(maxConnections); |
|
|
|
|
|
|
|
|
|
datasource.setTimeBetweenEvictionRunsMillis(idleValidationSeconds * 1000); |
|
|
|
|
if (maxIdleSeconds > 0) { |
|
|
|
|
// 最小值30秒
|
|
|
|
|
maxIdleSeconds = maxIdleSeconds < 30 ? 30 : maxIdleSeconds; |
|
|
|
|
datasource.setMaxEvictableIdleTimeMillis(maxIdleSeconds * 1000); |
|
|
|
|
} |
|
|
|
|
datasource.setMaxPoolPreparedStatementPerConnectionSize(maxStatementsPerConnection); |
|
|
|
|
|
|
|
|
|
if (dbValidationQuery != null) { |
|
|
|
|
datasource.setPreferredTestQuery(dbValidationQuery); |
|
|
|
|
if(!validateOnCheckout) |
|
|
|
|
datasource.setTestConnectionOnCheckin(true); |
|
|
|
|
else |
|
|
|
|
datasource.setTestConnectionOnCheckout(true); |
|
|
|
|
datasource.setIdleConnectionTestPeriod(idleValidationSeconds); |
|
|
|
|
datasource.setValidationQuery(dbValidationQuery); |
|
|
|
|
if (!validateOnCheckout) { |
|
|
|
|
datasource.setTestOnReturn(true); |
|
|
|
|
datasource.setTestOnBorrow(false); |
|
|
|
|
} else { |
|
|
|
|
datasource.setTestOnReturn(false); |
|
|
|
|
datasource.setTestOnBorrow(true); |
|
|
|
|
} |
|
|
|
|
datasource.setTestWhileIdle(true); |
|
|
|
|
} else { |
|
|
|
|
datasource.setTestOnReturn(false); |
|
|
|
|
datasource.setTestOnBorrow(false); |
|
|
|
|
datasource.setTestWhileIdle(false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -238,7 +245,7 @@ public class PoolingConnectionProvider implements ConnectionProvider {
|
|
|
|
|
* subclass's constructor. |
|
|
|
|
* </p> |
|
|
|
|
*/ |
|
|
|
|
public ComboPooledDataSource getDataSource() { |
|
|
|
|
public DruidDataSource getDataSource() { |
|
|
|
|
return datasource; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|