List of usage examples for org.apache.commons.dbcp BasicDataSource setPoolPreparedStatements
public synchronized void setPoolPreparedStatements(boolean poolingStatements)
Sets whether to pool statements or not.
Note: this method currently has no effect once the pool has been initialized.
From source file:org.lucane.server.database.DatabaseAbstractionLayer.java
/** * DatabaseLayer Factory//from w w w . j a v a 2 s . c o m * Get the layer corresponding to the driver */ public static DatabaseAbstractionLayer createLayer(ServerConfig config) throws Exception { Class.forName(config.getDbDriver()); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(config.getDbDriver()); ds.setUsername(config.getDbLogin()); ds.setPassword(config.getDbPassword()); ds.setUrl(config.getDbUrl()); ds.setPoolPreparedStatements(true); ds.setInitialSize(config.getDbPoolInitialSize()); ds.setMaxActive(config.getDbPoolMaxActive()); ds.setMaxIdle(config.getDbPoolMaxIdle()); ds.setMinIdle(config.getDbPoolMinIdle()); ds.setMaxWait(config.getDbPoolMaxWait()); Logging.getLogger() .info("Pool initialized (" + "initial size=" + config.getDbPoolInitialSize() + ", max active=" + config.getDbPoolMaxActive() + ", max idle=" + config.getDbPoolMaxIdle() + ", min idle=" + config.getDbPoolMinIdle() + ", max wait=" + config.getDbPoolMaxWait() + ")"); //-- dynamic layer loading Class klass = Class.forName(config.getDbLayer()); Class[] types = { DataSource.class }; Object[] values = { ds }; Constructor constr = klass.getConstructor(types); return (DatabaseAbstractionLayer) constr.newInstance(values); }
From source file:org.mskcc.cbio.portal.dao.JdbcUtil.java
private static DataSource initDataSource() { DatabaseProperties dbProperties = DatabaseProperties.getInstance(); String host = dbProperties.getDbHost(); String userName = dbProperties.getDbUser(); String password = dbProperties.getDbPassword(); String database = dbProperties.getDbName(); String url = "jdbc:mysql://" + host + "/" + database + "?user=" + userName + "&password=" + password + "&zeroDateTimeBehavior=convertToNull"; // Set up poolable data source BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setUsername(userName);/*from www . j av a 2s . com*/ ds.setPassword(password); ds.setUrl(url); // By pooling/reusing PreparedStatements, we get a major performance gain ds.setPoolPreparedStatements(true); ds.setMaxActive(100); activeConnectionCount = new HashMap<String, Integer>(); return ds; }
From source file:org.ngrinder.infra.config.Database.java
/** * Setup the database common features./*from w w w. ja va2s.co m*/ * * @param dataSource datasource */ protected void setupCommon(BasicDataSource dataSource) { dataSource.setDriverClassName(getJdbcDriverName()); dataSource.setInitialSize(DB_INITIAL_SIZE); dataSource.setMaxActive(DB_MAX_ACTIVE); dataSource.setMinIdle(DB_MIN_IDLE); dataSource.setMaxWait(DB_MAX_WAIT); dataSource.setPoolPreparedStatements(true); dataSource.setMaxOpenPreparedStatements(DB_MAX_OPEN_PREPARED_STATEMENTS); dataSource.setTestWhileIdle(true); dataSource.setTestOnBorrow(true); dataSource.setTestOnReturn(true); dataSource.setValidationQuery("SELECT 1"); }
From source file:org.orbisgis.geoserver.h2gis.datastore.H2GISDataStoreFactory.java
@Override protected DataSource createDataSource(Map params, SQLDialect dialect) throws IOException { String database = (String) DATABASE.lookUp(params); String host = (String) HOST.lookUp(params); Boolean mvcc = (Boolean) MVCC.lookUp(params); Boolean mvstore = (Boolean) MVSTORE.lookUp(params); BasicDataSource dataSource = new BasicDataSource(); if (host != null && !host.equals("")) { Integer port = (Integer) PORT.lookUp(params); if (port != null) { dataSource.setUrl("jdbc:h2:tcp://" + host + ":" + port + "/" + database); } else {/* ww w .jav a 2 s .c o m*/ dataSource.setUrl("jdbc:h2:tcp://" + host + "/" + database); } } else if (baseDirectory == null) { //use current working directory dataSource.setUrl("jdbc:h2:" + database + ";AUTO_SERVER=TRUE" + (mvcc != null ? (";MVCC=" + mvcc) : "") + (mvstore != null ? (";MVSTORE=" + mvstore) : "")); } else { //use directory specified if the patch is relative String location; if (!new File(database).isAbsolute()) { location = new File(baseDirectory, database).getAbsolutePath(); } else { location = database; } dataSource.setUrl("jdbc:h2:file:" + location + ";AUTO_SERVER=TRUE" + (mvcc != null ? (";MVCC=" + mvcc) : "") + (mvstore != null ? (";MVSTORE=" + mvstore) : "")); } String username = (String) USER.lookUp(params); if (username != null) { dataSource.setUsername(username); } String password = (String) PASSWD.lookUp(params); if (password != null) { dataSource.setPassword(password); } dataSource.setDriverClassName("org.h2.Driver"); dataSource.setPoolPreparedStatements(false); // if we got here the database has been created, now verify it has the H2GIS extension // and eventually try to create them JDBCDataStore closer = new JDBCDataStore(); Connection cx = null; try { cx = dataSource.getConnection(); //Add the spatial function if (!JDBCUtilities.tableExists(cx, "PUBLIC.GEOMETRY_COLUMNS")) { CreateSpatialExtension.initSpatialExtension(cx); } } catch (SQLException e) { throw new IOException("Failed to create the target database", e); } finally { closer.closeSafe(cx); } return new DBCPDataSource(dataSource); }
From source file:org.polymap.catalog.h2.data.H2DataStoreFactory.java
protected DataSource createDataSource(Map params, SQLDialect dialect) throws IOException { String database = (String) DATABASE.lookUp(params); String host = (String) HOST.lookUp(params); BasicDataSource dataSource = new BasicDataSource(); if (host != null && !host.equals("")) { Integer port = (Integer) PORT.lookUp(params); if (port != null && !port.equals("")) { dataSource.setUrl("jdbc:h2:tcp://" + host + ":" + port + "/" + database); } else {// ww w . j a v a 2 s . c o m dataSource.setUrl("jdbc:h2:tcp://" + host + "/" + database); } } else if (baseDirectory == null) { //use current working directory dataSource.setUrl("jdbc:h2:" + database); } else { //use directory specified if the patch is relative String location; if (!new File(database).isAbsolute()) { location = new File(baseDirectory, database).getAbsolutePath(); } else { location = database; } // falko: add support for NIO String osName = System.getProperty("os.name"); Boolean nio = (Boolean) NIO.lookUp(params); Boolean nioMapped = (Boolean) NIO_MAPPED.lookUp(params); String url = null; if ((nio != null && nio.booleanValue()) /*|| osName.toLowerCase().contains( "linux" )*/) { url = "jdbc:h2:nio:" + location; } else if ((nioMapped != null && nioMapped.booleanValue())) { url = "jdbc:h2:nioMapped:" + location; } else { url = "jdbc:h2:file:" + location; } // falko: multi threaded on //url += ";MULTI_THREADED=1"; dataSource.setUrl(url); } String username = (String) USER.lookUp(params); if (username != null) { dataSource.setUsername(username); } String password = (String) PASSWD.lookUp(params); if (password != null) { dataSource.setPassword(password); } dataSource.setDriverClassName("org.h2.Driver"); dataSource.setPoolPreparedStatements(false); return dataSource; }
From source file:xbird.util.jdbc.datasource.DbcpDataSourceProvider.java
public DataSource setupDataSource(String connectURI) { // creates DataSource BasicDataSource ds = new BasicDataSource(); // for debugging. if (Settings.isLoggingEnabled) { ds.setAccessToUnderlyingConnectionAllowed(true); }//from w ww . j a va 2s. c o m ds.setDriverClassName(DriverClassNameResolver.resolve(Settings.get("xbird.db.kind"))); // sets up DataSource ds.setUrl(connectURI); final String dbuser = Settings.get("xbird.db.user"); final String dbpasswd = Settings.get("xbird.db.passwd"); if (dbuser != null && dbuser.length() != 0) { ds.setUsername(dbuser); ds.setPassword(dbpasswd); } // addtinal settings. final String maxactive = Settings.get("xbird.db.pool.maxactive"); if (maxactive != null) ds.setMaxActive(Integer.parseInt(maxactive)); final String maxidle = Settings.get("xbird.db.pool.maxidle"); if (maxidle != null) ds.setMaxIdle(Integer.parseInt(maxidle)); final String maxwait = Settings.get("xbird.db.pool.maxwait"); ds.setMaxWait(maxwait == null ? DEFAULT_MAXWAIT : Integer.parseInt(maxwait)); ds.setDefaultAutoCommit(true); //ds.setDefaultReadOnly(false); final String initialsize = Settings.get("xbird.db.pool.initialsize"); ds.setInitialSize(initialsize == null ? DEFAULT_INITIAL_POLLSIZE : Integer.parseInt(initialsize)); // sets up for PreparedStatements. ds.setPoolPreparedStatements(true); final String maxOpenPreparedStatements = Settings.get("xbird.db.pool.statement.cache_size"); ds.setMaxOpenPreparedStatements(maxOpenPreparedStatements == null ? MAX_OPEN_PREPARED_STATEMENTS : Integer.parseInt(maxOpenPreparedStatements)); return ds; }