From 0cc6efe9647664713274726583c10d6e3fa99134 Mon Sep 17 00:00:00 2001 From: loy Date: Mon, 26 Feb 2018 14:50:13 +0800 Subject: [PATCH] =?UTF-8?q?quartz=E9=BB=98=E8=AE=A4=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=B1=A0=E6=94=B9=E4=B8=BAdruid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/jdbcjobstore/CUBRIDDelegate.java | 23 ++------- .../utils/PoolingConnectionProvider.java | 51 +++++++++++-------- 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/fine-quartz/src/com/fr/third/v2/org/quartz/impl/jdbcjobstore/CUBRIDDelegate.java b/fine-quartz/src/com/fr/third/v2/org/quartz/impl/jdbcjobstore/CUBRIDDelegate.java index ed8fd13db..c9044d8bd 100644 --- a/fine-quartz/src/com/fr/third/v2/org/quartz/impl/jdbcjobstore/CUBRIDDelegate.java +++ b/fine-quartz/src/com/fr/third/v2/org/quartz/impl/jdbcjobstore/CUBRIDDelegate.java @@ -17,9 +17,7 @@ package com.fr.third.v2.org.quartz.impl.jdbcjobstore; -import com.mchange.v2.c3p0.C3P0ProxyConnection; import java.io.*; -import java.lang.reflect.Method; import java.sql.*; /** @@ -110,23 +108,8 @@ public class CUBRIDDelegate extends StdJDBCDelegate { byteArray = baos.toByteArray(); } - //quartz 2.x uses c3p0, c3p0 doesn't support createBlob method as of 0.9.2 - Connection conn = ps.getConnection(); - if (conn instanceof C3P0ProxyConnection) { - try { - C3P0ProxyConnection c3p0Conn = (C3P0ProxyConnection) conn; - Method m = Connection.class.getMethod("createBlob", new Class[]{}); //will call createBlob method on the underlying connection - Object[] args = new Object[]{}; //arguments to be passed to the method. none in this case - Blob blob = (Blob) c3p0Conn.rawConnectionOperation(m, C3P0ProxyConnection.RAW_CONNECTION, args); - blob.setBytes(1, byteArray); - ps.setBlob(index, blob); - } catch (Exception ex) { - ex.printStackTrace(); - } - } else { - Blob blob = ps.getConnection().createBlob(); - blob.setBytes(1, byteArray); - ps.setBlob(index, blob); - } + Blob blob = ps.getConnection().createBlob(); + blob.setBytes(1, byteArray); + ps.setBlob(index, blob); } } diff --git a/fine-quartz/src/com/fr/third/v2/org/quartz/utils/PoolingConnectionProvider.java b/fine-quartz/src/com/fr/third/v2/org/quartz/utils/PoolingConnectionProvider.java index 8e7c0a4be..38061aee9 100644 --- a/fine-quartz/src/com/fr/third/v2/org/quartz/utils/PoolingConnectionProvider.java +++ b/fine-quartz/src/com/fr/third/v2/org/quartz/utils/PoolingConnectionProvider.java @@ -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; /** *

@@ -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. *

*/ - public ComboPooledDataSource getDataSource() { + public DruidDataSource getDataSource() { return datasource; }