Replace c3p0 with dbcp2, so there is only one pooling library in use

This commit is contained in:
Graham Triggs 2017-09-20 14:08:36 +01:00
parent 6cbdcd6842
commit 4543e65d08
3 changed files with 31 additions and 32 deletions

View file

@ -26,7 +26,7 @@ import org.apache.jena.sdb.sql.SDBConnection;
import org.apache.jena.sdb.store.DatabaseType; import org.apache.jena.sdb.store.DatabaseType;
import org.apache.jena.sdb.store.LayoutType; import org.apache.jena.sdb.store.LayoutType;
import org.apache.jena.sdb.util.StoreUtils; import org.apache.jena.sdb.util.StoreUtils;
import com.mchange.v2.c3p0.ComboPooledDataSource; import org.apache.commons.dbcp2.BasicDataSource;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset; import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
@ -86,7 +86,7 @@ public class ContentTripleSourceSDB extends ContentTripleSource {
static final boolean DEFAULT_TESTONRETURN = true; static final boolean DEFAULT_TESTONRETURN = true;
private ServletContext ctx; private ServletContext ctx;
private ComboPooledDataSource ds; private BasicDataSource ds;
private RDFServiceFactory rdfServiceFactory; private RDFServiceFactory rdfServiceFactory;
private RDFService rdfService; private RDFService rdfService;
private Dataset dataset; private Dataset dataset;
@ -233,10 +233,14 @@ public class ContentTripleSourceSDB extends ContentTripleSource {
this.rdfService.close(); this.rdfService.close();
} }
if (ds != null) { if (ds != null) {
String driverClassName = ds.getDriverClass(); String driverClassName = ds.getDriverClassName();
ds.close(); try {
attemptToDeregisterJdbcDriver(driverClassName); ds.close();
cleanupAbandonedConnectionThread(driverClassName); } catch (SQLException e) {
}finally {
attemptToDeregisterJdbcDriver(driverClassName);
cleanupAbandonedConnectionThread(driverClassName);
}
} }
} }

View file

@ -10,7 +10,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import com.mchange.v2.c3p0.ComboPooledDataSource; import org.apache.commons.dbcp2.BasicDataSource;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
@ -48,26 +48,26 @@ public class SDBDataSource {
this.configProps = ConfigurationProperties.getBean(ctx); this.configProps = ConfigurationProperties.getBean(ctx);
} }
public ComboPooledDataSource getDataSource() { public BasicDataSource getDataSource() {
try { BasicDataSource cpds = new BasicDataSource();
ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setDriverClassName(getDbDriverClassName());
cpds.setDriverClass(getDbDriverClassName()); cpds.setUrl(getJdbcUrl());
cpds.setJdbcUrl(getJdbcUrl()); cpds.setUsername(configProps.getProperty(PROPERTY_DB_USERNAME));
cpds.setUser(configProps.getProperty(PROPERTY_DB_USERNAME)); cpds.setPassword(configProps.getProperty(PROPERTY_DB_PASSWORD));
cpds.setPassword(configProps.getProperty(PROPERTY_DB_PASSWORD)); cpds.setMaxTotal(getMaxActive());
cpds.setMaxPoolSize(getMaxActive()); cpds.setMaxIdle(getMaxIdle());
cpds.setMinPoolSize(getMaxIdle()); cpds.setMinEvictableIdleTimeMillis(getMaxIdleTime());
cpds.setMaxIdleTime(getMaxIdleTime()); cpds.setTestOnBorrow(DEFAULT_TESTONBORROW);
cpds.setMaxIdleTimeExcessConnections(getMaxIdleTimeExcess()); cpds.setTestOnReturn(DEFAULT_TESTONRETURN);
cpds.setAcquireIncrement(5); cpds.setValidationQuery(getValidationQuery());
cpds.setNumHelperThreads(6); return cpds;
cpds.setTestConnectionOnCheckout(DEFAULT_TESTONBORROW); // try {
cpds.setTestConnectionOnCheckin(DEFAULT_TESTONRETURN); // cpds.setMaxIdleTimeExcessConnections(getMaxIdleTimeExcess());
cpds.setPreferredTestQuery(getValidationQuery()); // cpds.setAcquireIncrement(5);
return cpds; // cpds.setNumHelperThreads(6);
} catch (PropertyVetoException pve) { // } catch (PropertyVetoException pve) {
throw new RuntimeException(pve); // throw new RuntimeException(pve);
} // }
} }
private String getDbDriverClassName() { private String getDbDriverClassName() {

View file

@ -70,11 +70,6 @@
<artifactId>icu4j</artifactId> <artifactId>icu4j</artifactId>
<version>3.4.4</version> <version>3.4.4</version>
</dependency> </dependency>
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
<dependency> <dependency>
<groupId>com.twelvemonkeys.imageio</groupId> <groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId> <artifactId>imageio-jpeg</artifactId>