diff --git a/webapp/lib/c3p0-0.9.2-pre4.jar b/webapp/lib/c3p0-0.9.2-pre4.jar new file mode 100644 index 000000000..645f39dd4 Binary files /dev/null and b/webapp/lib/c3p0-0.9.2-pre4.jar differ diff --git a/webapp/lib/c3p0-oracle-thin-extras-0.9.2-pre4.jar b/webapp/lib/c3p0-oracle-thin-extras-0.9.2-pre4.jar new file mode 100644 index 000000000..0a67fb4d8 Binary files /dev/null and b/webapp/lib/c3p0-oracle-thin-extras-0.9.2-pre4.jar differ diff --git a/webapp/lib/mchange-commons-java-0.2.2.jar b/webapp/lib/mchange-commons-java-0.2.2.jar new file mode 100644 index 000000000..19f947e8a Binary files /dev/null and b/webapp/lib/mchange-commons-java-0.2.2.jar differ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java index 64c342564..adc58c56f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java @@ -29,8 +29,8 @@ import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.sql.DataSource; -import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -966,7 +966,7 @@ public class JenaIngestController extends BaseEditController { log.debug("Connecting to DB at "+jdbcUrl); StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash,dbTypeObj) ; ServletContext ctx = vreq.getSession().getServletContext(); - BasicDataSource bds = WebappDaoSetup.makeBasicDataSource( + DataSource bds = WebappDaoSetup.makeBasicDataSource( driver, jdbcUrl, username, password, ctx); try { VitroJenaSDBModelMaker vsmm = new VitroJenaSDBModelMaker(storeDesc, bds); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/RDBGraphGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/RDBGraphGenerator.java index 2e955abd6..9d3ed7b6f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/RDBGraphGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/RDBGraphGenerator.java @@ -2,10 +2,11 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena; -import java.sql.SQLException; import java.sql.Connection; +import java.sql.SQLException; + +import javax.sql.DataSource; -import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -21,13 +22,13 @@ public class RDBGraphGenerator implements SQLGraphGenerator { private static final Log log = LogFactory.getLog(RDBGraphGenerator.class.getName()); - private BasicDataSource ds = null; + private DataSource ds = null; private Connection connection = null; private String dbTypeStr = null; private String graphID = null; - public RDBGraphGenerator(BasicDataSource bds, String dbTypeStr, String graphID) { - this.ds = bds; + public RDBGraphGenerator(DataSource ds, String dbTypeStr, String graphID) { + this.ds = ds; this.dbTypeStr = dbTypeStr; this.graphID = graphID; } @@ -43,10 +44,10 @@ public class RDBGraphGenerator implements SQLGraphGenerator { public Graph generateGraph() { log.info("Regenerate the graph."); try { - if (log.isDebugEnabled()) { - log.debug(ds.getNumActive() + " active SQL connections"); - log.debug(ds.getNumIdle() + " idle SQL connections"); - } +// if (log.isDebugEnabled()) { +// log.debug(ds.getNumActive() + " active SQL connections"); +// log.debug(ds.getNumIdle() + " idle SQL connections"); +// } if ( ( this.connection == null ) || ( this.connection.isClosed() ) ) { this.connection = ds.getConnection(); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SDBGraphConnectionGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SDBGraphConnectionGenerator.java index 79adfe190..0992db146 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SDBGraphConnectionGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SDBGraphConnectionGenerator.java @@ -5,7 +5,8 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena; import java.sql.Connection; import java.sql.SQLException; -import org.apache.commons.dbcp.BasicDataSource; +import javax.sql.DataSource; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -14,10 +15,10 @@ public class SDBGraphConnectionGenerator { private final static Log log = LogFactory.getLog( SDBGraphConnectionGenerator.class); - private BasicDataSource ds = null; + private DataSource ds = null; private Connection connection = null; - public SDBGraphConnectionGenerator(BasicDataSource dataSource) { + public SDBGraphConnectionGenerator(DataSource dataSource) { this.ds = dataSource; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SDBGraphGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SDBGraphGenerator.java index 9fe94ec17..f96ada96b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SDBGraphGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/SDBGraphGenerator.java @@ -2,7 +2,11 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena; -import org.apache.commons.dbcp.BasicDataSource; +import java.sql.Connection; +import java.sql.SQLException; + +import javax.sql.DataSource; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -10,8 +14,6 @@ import com.hp.hpl.jena.graph.Graph; import com.hp.hpl.jena.sdb.SDBFactory; import com.hp.hpl.jena.sdb.Store; import com.hp.hpl.jena.sdb.StoreDesc; -import java.sql.Connection; -import java.sql.SQLException; public class SDBGraphGenerator implements SQLGraphGenerator { @@ -22,7 +24,7 @@ public class SDBGraphGenerator implements SQLGraphGenerator { private StoreDesc storeDesc; private String graphID; - public SDBGraphGenerator(BasicDataSource dataSource, StoreDesc storeDesc, + public SDBGraphGenerator(DataSource dataSource, StoreDesc storeDesc, String graphID) { this.connGen = new SDBGraphConnectionGenerator(dataSource); this.storeDesc = storeDesc; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java index 04522af87..d2ed5b30f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaModelMaker.java @@ -8,8 +8,8 @@ import java.util.List; import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; -import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -47,7 +47,7 @@ public class VitroJenaModelMaker implements ModelMaker { private String username; private String password; private String dbTypeStr; - private BasicDataSource dataSource; + private DataSource dataSource; private HashMap modelCache; private HttpServletRequest request = null; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSDBModelMaker.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSDBModelMaker.java index 2eeb8900f..ea372c777 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSDBModelMaker.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VitroJenaSDBModelMaker.java @@ -11,7 +11,8 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import org.apache.commons.dbcp.BasicDataSource; +import javax.sql.DataSource; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -46,7 +47,7 @@ public class VitroJenaSDBModelMaker implements ModelMaker { private final static Log log = LogFactory.getLog(VitroJenaSDBModelMaker.class); private StoreDesc storeDesc = null; - private BasicDataSource bds = null; + private DataSource ds = null; private SDBConnection conn = null; private SDBGraphConnectionGenerator connGen = null; @@ -58,12 +59,12 @@ public class VitroJenaSDBModelMaker implements ModelMaker { private Resource sdbResource; // a resource representing the SDB database - public VitroJenaSDBModelMaker(StoreDesc storeDesc, BasicDataSource bds) + public VitroJenaSDBModelMaker(StoreDesc storeDesc, DataSource ds) throws SQLException { this.storeDesc = storeDesc; - this.bds = bds; - connGen = new SDBGraphConnectionGenerator(bds); + this.ds = ds; + connGen = new SDBGraphConnectionGenerator(ds); Store store = getStore(); try { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java index 109be552a..b6c039efe 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/VitroRequestPrep.java @@ -23,8 +23,8 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.sql.DataSource; -import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -248,7 +248,7 @@ public class VitroRequestPrep implements Filter { // If they asked for other models by URI, set them. if (anyOtherSpecialProperties(vreq)) { - BasicDataSource bds = JenaDataSourceSetupBase.getApplicationDataSource(_context); + DataSource bds = JenaDataSourceSetupBase.getApplicationDataSource(_context); String dbType = ConfigurationProperties.getBean(_context) .getProperty("VitroConnection.DataSource.dbtype", "MySQL"); @@ -286,7 +286,7 @@ public class VitroRequestPrep implements Filter { * if it's not found. */ private OntModel createSpecialModel(VitroRequest vreq, String key, - BasicDataSource bds, String dbType) { + DataSource bds, String dbType) { if (!isParameterPresent(vreq, key)) { return null; } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/WebappDaoFactorySparqlPrep.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/WebappDaoFactorySparqlPrep.java index 2812c9434..770fb8c5a 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/WebappDaoFactorySparqlPrep.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/WebappDaoFactorySparqlPrep.java @@ -21,7 +21,6 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; -import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -92,7 +91,7 @@ public class WebappDaoFactorySparqlPrep implements Filter { } } - BasicDataSource bds = JenaDataSourceSetupBase.getApplicationDataSource(_ctx); + javax.sql.DataSource ds = JenaDataSourceSetupBase.getApplicationDataSource(_ctx); StoreDesc storeDesc = (StoreDesc) _ctx.getAttribute("storeDesc"); OntModelSelector oms = (OntModelSelector) _ctx.getAttribute("unionOntModelSelector"); String defaultNamespace = (String) _ctx.getAttribute("defaultNamespace"); @@ -103,12 +102,12 @@ public class WebappDaoFactorySparqlPrep implements Filter { WebappDaoFactory wadf = null; try { - if (bds == null || storeDesc == null || oms == null) { + if (ds == null || storeDesc == null || oms == null) { throw new RuntimeException("SDB store not property set up"); } try { - sqlConn = bds.getConnection(); + sqlConn = ds.getConnection(); conn = new SDBConnection(sqlConn) ; } catch (SQLException sqe) { throw new RuntimeException("Unable to connect to database", sqe); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/sdb/RDFServiceSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/sdb/RDFServiceSDB.java index adf722775..6c818c03f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/sdb/RDFServiceSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/rdfservice/impl/jena/sdb/RDFServiceSDB.java @@ -6,6 +6,8 @@ import java.io.ByteArrayInputStream; import java.sql.SQLException; import java.util.Iterator; +import javax.sql.DataSource; + import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; @@ -32,18 +34,18 @@ public class RDFServiceSDB extends RDFServiceJena implements RDFService { private final static Log log = LogFactory.getLog(RDFServiceSDB.class); - private BasicDataSource bds; + private DataSource ds; private StoreDesc storeDesc; - public RDFServiceSDB(BasicDataSource dataSource, StoreDesc storeDesc) { - this.bds = dataSource; + public RDFServiceSDB(DataSource dataSource, StoreDesc storeDesc) { + this.ds = dataSource; this.storeDesc = storeDesc; } @Override protected DatasetWrapper getDatasetWrapper() { try { - SDBConnection conn = new SDBConnection(bds.getConnection()); + SDBConnection conn = new SDBConnection(ds.getConnection()); return new DatasetWrapper(getDataset(conn), conn); } catch (SQLException sqle) { log.error(sqle, sqle); @@ -64,7 +66,7 @@ public class RDFServiceSDB extends RDFServiceJena implements RDFService { SDBConnection conn = null; try { - conn = new SDBConnection(bds.getConnection()); + conn = new SDBConnection(ds.getConnection()); } catch (SQLException sqle) { log.error(sqle, sqle); throw new RDFServiceException(sqle); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java index 31c07f590..15fc6a49f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/ApplicationModelSetup.java @@ -1,14 +1,13 @@ /* $This file is distributed under the terms of the license in /doc/license.txt$ */ package edu.cornell.mannlib.vitro.webapp.servlet.setup; -import static edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary.DISPLAY_ONT_MODEL; - import java.io.File; import java.io.FileOutputStream; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import javax.sql.DataSource; import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; @@ -16,7 +15,6 @@ import org.apache.commons.logging.LogFactory; import org.joda.time.DateTime; import org.joda.time.format.ISODateTimeFormat; -import com.hp.hpl.jena.ontology.OntDocumentManager; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; @@ -53,7 +51,7 @@ implements ServletContextListener { * Also, at each start of tomcat, load The display TBox and the * display/display model. */ - private void setupDisplayModel(BasicDataSource bds, ServletContext ctx, + private void setupDisplayModel(DataSource bds, ServletContext ctx, StartupStatus ss) { // display, editing and navigation Model @@ -242,7 +240,7 @@ implements ServletContextListener { public void contextInitialized(ServletContextEvent sce) { ServletContext ctx = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(ctx); - BasicDataSource bds = getApplicationDataSource(ctx); + DataSource bds = getApplicationDataSource(ctx); setupDisplayModel(bds, ctx, ss); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java index eddee1b45..8ddf0b6a5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupBase.java @@ -2,6 +2,7 @@ package edu.cornell.mannlib.vitro.webapp.servlet.setup; +import java.beans.PropertyVetoException; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; @@ -9,6 +10,7 @@ import java.sql.SQLException; import java.util.Set; import javax.servlet.ServletContext; +import javax.sql.DataSource; import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.lang.StringUtils; @@ -31,6 +33,7 @@ import com.hp.hpl.jena.sdb.Store; import com.hp.hpl.jena.sdb.StoreDesc; import com.hp.hpl.jena.sdb.store.DatabaseType; import com.hp.hpl.jena.sdb.store.LayoutType; +import com.mchange.v2.c3p0.ComboPooledDataSource; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary; @@ -174,9 +177,10 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon { "VitroConnection.DataSource.username"); String password = ConfigurationProperties.getBean(ctx).getProperty( "VitroConnection.DataSource.password"); - BasicDataSource ds = makeBasicDataSource( + DataSource ds = makeC3poDataSource( getDbDriverClassName(ctx), jdbcUrl, username, password, ctx); - +// DataSource ds = makeBasicDataSource( +// getDbDriverClassName(ctx), jdbcUrl, username, password, ctx); jenaDbOntModelSpec = (jenaDbOntModelSpec != null) ? jenaDbOntModelSpec : DB_ONT_MODEL_SPEC; @@ -186,10 +190,10 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon { } /** - * Sets up a BasicDataSource using values from + * Sets up a DataSource using values from * a properties file. */ - public final BasicDataSource makeDataSourceFromConfigurationProperties( + public final DataSource makeDataSourceFromConfigurationProperties( ServletContext ctx) { String dbDriverClassname = ConfigurationProperties.getBean(ctx) .getProperty("VitroConnection.DataSource.driver", @@ -199,35 +203,51 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon { "VitroConnection.DataSource.username"); String password = ConfigurationProperties.getBean(ctx).getProperty( "VitroConnection.DataSource.password"); - return makeBasicDataSource( + return makeC3poDataSource( dbDriverClassname, jdbcUrl, username, password, ctx); +// makeBasicDataSource( +// dbDriverClassname, jdbcUrl, username, password, ctx); } - public void setApplicationDataSource(BasicDataSource bds, + public void setApplicationDataSource(DataSource ds, ServletContext ctx) { - ctx.setAttribute(getDataSourceAttributeName(), bds); + ctx.setAttribute(getDataSourceAttributeName(), ds); } - public static BasicDataSource getApplicationDataSource(ServletContext ctx) { - return (BasicDataSource) ctx.getAttribute(getDataSourceAttributeName()); + public static DataSource getApplicationDataSource(ServletContext ctx) { + return (DataSource) ctx.getAttribute(getDataSourceAttributeName()); } private static String getDataSourceAttributeName() { return JenaDataSourceSetupBase.class.getName() + ".dataSource"; } - - public static BasicDataSource makeBasicDataSource(String dbDriverClassname, + + public static DataSource makeC3poDataSource(String dbDriverClassname, String jdbcUrl, String username, String password, ServletContext ctx) { - log.debug("makeBasicDataSource('" + dbDriverClassname + "', '" - + jdbcUrl + "', '" + username + "', '" + password + "')"); - BasicDataSource ds = new BasicDataSource(); - ds.setDriverClassName(dbDriverClassname); - ds.setUrl(jdbcUrl); - ds.setUsername(username); - ds.setPassword(password); + + ComboPooledDataSource cpds = new ComboPooledDataSource(); + try { + cpds.setDriverClass(dbDriverClassname); + } catch (PropertyVetoException pve) { + throw new RuntimeException(pve); + } + cpds.setJdbcUrl(jdbcUrl); + cpds.setUser(username); + cpds.setPassword(password); + int[] maxActiveAndIdle = getMaxActiveAndIdle(ctx); + cpds.setMaxPoolSize(maxActiveAndIdle[0]); + cpds.setMinPoolSize(maxActiveAndIdle[1]); + cpds.setMaxIdleTime(3600); // ms + cpds.setMaxIdleTimeExcessConnections(300); + cpds.setAcquireIncrement(5); + cpds.setNumHelperThreads(6); + return cpds; + } + + private static int[] getMaxActiveAndIdle(ServletContext ctx) { int maxActiveInt = DEFAULT_MAXACTIVE; String maxActiveStr = ConfigurationProperties.getBean(ctx).getProperty( MAX_ACTIVE_PROPERTY); @@ -247,11 +267,11 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon { + maxActiveStr + " as an integer"); } } + String maxIdleStr = ConfigurationProperties.getBean(ctx).getProperty( + MAX_IDLE_PROPERTY); int maxIdleInt = (maxActiveInt > DEFAULT_MAXACTIVE) ? maxActiveInt / 4 : DEFAULT_MAXIDLE; - String maxIdleStr = ConfigurationProperties.getBean(ctx).getProperty( - MAX_IDLE_PROPERTY); if (!StringUtils.isEmpty(maxIdleStr)) { try { maxIdleInt = Integer.parseInt(maxIdleStr); @@ -259,15 +279,34 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon { log.error("Unable to parse connection pool maxIdle setting " + maxIdleStr + " as an integer"); } - } - ds.setMaxActive(maxActiveInt); - ds.setMaxIdle(maxIdleInt); + } + int[] result = new int[2]; + result[0] = maxActiveInt; + result[1] = maxIdleInt; + return result; + } + + public static DataSource makeBasicDataSource(String dbDriverClassname, + String jdbcUrl, + String username, + String password, + ServletContext ctx) { + log.debug("makeBasicDataSource('" + dbDriverClassname + "', '" + + jdbcUrl + "', '" + username + "', '" + password + "')"); + BasicDataSource ds = new BasicDataSource(); + ds.setDriverClassName(dbDriverClassname); + ds.setUrl(jdbcUrl); + ds.setUsername(username); + ds.setPassword(password); + int[] maxActiveAndIdle = getMaxActiveAndIdle(ctx); + ds.setMaxActive(maxActiveAndIdle[0]); + ds.setMaxIdle(maxActiveAndIdle[1]); ds.setMaxWait(DEFAULT_MAXWAIT); ds.setValidationQuery(getValidationQuery(ctx)); ds.setTestOnBorrow(DEFAULT_TESTONBORROW); ds.setTestOnReturn(DEFAULT_TESTONRETURN); ds.setMinEvictableIdleTimeMillis(DEFAULT_MINEVICTIONIDLETIME); - ds.setNumTestsPerEvictionRun(maxActiveInt); + ds.setNumTestsPerEvictionRun(maxActiveAndIdle[0]); ds.setTimeBetweenEvictionRunsMillis(DEFAULT_TIMEBETWEENEVICTIONS); ds.setInitialSize(ds.getMaxActive() / 10); @@ -292,7 +331,7 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon { firstStartup = true; } - protected Model makeDBModel(BasicDataSource ds, + protected Model makeDBModel(DataSource ds, String jenaDbModelname, OntModelSpec jenaDbOntModelSpec, ServletContext ctx) { @@ -300,7 +339,7 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon { ds, jenaDbModelname, jenaDbOntModelSpec, TripleStoreType.RDB, ctx); } - protected Model makeDBModel(BasicDataSource ds, + protected Model makeDBModel(DataSource ds, String jenaDbModelName, OntModelSpec jenaDbOntModelSpec, TripleStoreType storeType, ServletContext ctx) { @@ -308,7 +347,7 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon { getDbType(ctx), ctx); } - public static Model makeDBModel(BasicDataSource ds, + public static Model makeDBModel(DataSource ds, String jenaDbModelName, OntModelSpec jenaDbOntModelSpec, TripleStoreType storeType, String dbType, @@ -343,7 +382,7 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon { "Unsupported store type " + storeType); } dbModel = ModelFactory.createModelForGraph(g); - log.debug("Using database at "+ds.getUrl()); + //log.debug("Using database at " + ds.getUrl()); } catch (Throwable t) { t.printStackTrace(); } @@ -429,11 +468,13 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon { } else if (TripleStoreType.SDB.equals(type)) { StoreDesc storeDesc = new StoreDesc( LayoutType.LayoutTripleNodesHash, DatabaseType.fetch(dbtypeStr)); - BasicDataSource bds = WebappDaoSetup.makeBasicDataSource( + DataSource bds = WebappDaoSetup.makeC3poDataSource( getDbDriverClassName(ctx), jdbcUrl, username, password, ctx); - bds.setMaxActive(4); // for now, the SDB model makers should not use more - // than a small handful of connections - bds.setMaxIdle(2); +// DataSource bds = WebappDaoSetup.makeBasicDataSource( +// getDbDriverClassName(ctx), jdbcUrl, username, password, ctx); +// bds.setMaxActive(4); // for now, the SDB model makers should not use more +// // than a small handful of connections +// bds.setMaxIdle(2); try { vsmm = new VitroJenaSDBModelMaker(storeDesc, bds); } catch (SQLException sqle) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaPersistentDataSourceSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaPersistentDataSourceSetup.java index c0b5d3320..26397c4ab 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaPersistentDataSourceSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaPersistentDataSourceSetup.java @@ -5,17 +5,13 @@ package edu.cornell.mannlib.vitro.webapp.servlet.setup; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import javax.sql.DataSource; -import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.ontology.OntDocumentManager; -import com.hp.hpl.jena.ontology.OntModel; -import com.hp.hpl.jena.rdf.model.Model; -import com.hp.hpl.jena.rdf.model.ModelFactory; -import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer; import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus; /** @@ -35,7 +31,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase // we do not want to fetch imports when we wrap Models in OntModels OntDocumentManager.getInstance().setProcessImports(false); - BasicDataSource bds = makeDataSourceFromConfigurationProperties(ctx); + DataSource bds = makeDataSourceFromConfigurationProperties(ctx); setApplicationDataSource(bds, ctx); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/RDFServiceSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/RDFServiceSetup.java index 12d7d1300..9c859efaf 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/RDFServiceSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/RDFServiceSetup.java @@ -5,6 +5,7 @@ import java.sql.SQLException; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; +import javax.sql.DataSource; import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; @@ -82,8 +83,8 @@ implements javax.servlet.ServletContextListener { } private void useSDB(ServletContext ctx, StartupStatus ss) throws SQLException { - BasicDataSource bds = getApplicationDataSource(ctx); - if( bds == null ){ + DataSource ds = getApplicationDataSource(ctx); + if( ds == null ){ ss.fatal(this, "A DataSource must be setup before SDBSetup "+ "is run. Make sure that JenaPersistentDataSourceSetup runs before "+ "SDBSetup."); @@ -96,7 +97,7 @@ implements javax.servlet.ServletContextListener { StoreDesc storeDesc = makeStoreDesc(ctx); setApplicationStoreDesc(storeDesc, ctx); - Store store = connectStore(bds, storeDesc); + Store store = connectStore(ds, storeDesc); setApplicationStore(store, ctx); if (!isSetUp(store)) { @@ -104,7 +105,7 @@ implements javax.servlet.ServletContextListener { setupSDB(ctx, store); } - RDFService rdfService = new RDFServiceSDB(bds, storeDesc); + RDFService rdfService = new RDFServiceSDB(ds, storeDesc); RDFServiceFactory rdfServiceFactory = new RDFServiceFactorySingle(rdfService); RDFServiceUtils.setRDFServiceFactory(ctx, rdfServiceFactory); @@ -145,7 +146,7 @@ implements javax.servlet.ServletContextListener { DatabaseType.fetch(dbtypeStr) ); } - public static Store connectStore(BasicDataSource bds, StoreDesc storeDesc) + public static Store connectStore(DataSource bds, StoreDesc storeDesc) throws SQLException { SDBConnection conn = new SDBConnection(bds.getConnection()); return SDBFactory.connectStore(conn, storeDesc); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java index 60a6ee5d8..42f5bf2ba 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/SimpleReasonerSetup.java @@ -12,8 +12,8 @@ import java.util.List; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import javax.sql.DataSource; -import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -82,7 +82,7 @@ public class SimpleReasonerSetup implements ServletContextListener { // set up simple reasoning for the ABox ServletContext ctx = sce.getServletContext(); - BasicDataSource bds = JenaDataSourceSetupBase + DataSource bds = JenaDataSourceSetupBase .getApplicationDataSource(ctx); String dbType = ConfigurationProperties.getBean(ctx).getProperty( // database type "VitroConnection.DataSource.dbtype","MySQL"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UserModelSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UserModelSetup.java index d7688149c..3d1a54d6f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UserModelSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/UserModelSetup.java @@ -4,6 +4,7 @@ package edu.cornell.mannlib.vitro.webapp.servlet.setup; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; +import javax.sql.DataSource; import org.apache.commons.dbcp.BasicDataSource; import org.apache.commons.logging.Log; @@ -33,7 +34,7 @@ public class UserModelSetup extends JenaDataSourceSetupBase ServletContext ctx = sce.getServletContext(); StartupStatus ss = StartupStatus.getBean(ctx); - BasicDataSource bds = getApplicationDataSource(ctx); + DataSource bds = getApplicationDataSource(ctx); if( bds == null ){ ss.fatal(this, "A DataSource must be setup before ModelSetup "+ "is run. Make sure that JenaPersistentDataSourceSetup runs before "+ @@ -49,7 +50,7 @@ public class UserModelSetup extends JenaDataSourceSetupBase // Does nothing. } - private void setupUserAccountModel (BasicDataSource bds, ServletContext ctx ,StartupStatus ss){ + private void setupUserAccountModel (DataSource bds, ServletContext ctx ,StartupStatus ss){ try { Model userAccountsDbModel = makeDBModel(bds, JENA_USER_ACCOUNTS_MODEL, DB_ONT_MODEL_SPEC, ctx);