Browse Source

quartz默认连接池改为druid

10.0
loy 7 years ago
parent
commit
0cc6efe964
  1. 23
      fine-quartz/src/com/fr/third/v2/org/quartz/impl/jdbcjobstore/CUBRIDDelegate.java
  2. 51
      fine-quartz/src/com/fr/third/v2/org/quartz/utils/PoolingConnectionProvider.java

23
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; package com.fr.third.v2.org.quartz.impl.jdbcjobstore;
import com.mchange.v2.c3p0.C3P0ProxyConnection;
import java.io.*; import java.io.*;
import java.lang.reflect.Method;
import java.sql.*; import java.sql.*;
/** /**
@ -110,23 +108,8 @@ public class CUBRIDDelegate extends StdJDBCDelegate {
byteArray = baos.toByteArray(); byteArray = baos.toByteArray();
} }
//quartz 2.x uses c3p0, c3p0 doesn't support createBlob method as of 0.9.2 Blob blob = ps.getConnection().createBlob();
Connection conn = ps.getConnection(); blob.setBytes(1, byteArray);
if (conn instanceof C3P0ProxyConnection) { ps.setBlob(index, blob);
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);
}
} }
} }

51
fine-quartz/src/com/fr/third/v2/org/quartz/utils/PoolingConnectionProvider.java

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

Loading…
Cancel
Save