List of usage examples for org.apache.commons.dbcp2 BasicDataSource setMaxTotal
public synchronized void setMaxTotal(int maxTotal)
From source file:com.thoughtworks.go.server.service.BackupServiceH2IntegrationTest.java
private BasicDataSource constructTestDataSource(File file) { BasicDataSource source = new BasicDataSource(); source.setDriverClassName("org.h2.Driver"); source.setUrl("jdbc:h2:" + file.getAbsolutePath() + "/cruise;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"); source.setUsername("sa"); source.setPassword(""); source.setMaxTotal(32); source.setMaxIdle(32);/* ww w. j a v a 2 s . c o m*/ return source; }
From source file:com.mycompany.configuration.SpringDateConfigMySQL.java
@Bean //? ? /*w w w .j ava 2s . com*/ public DataSource dataSource() { //MySQL BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); //? ds.setUrl("jdbc:mysql://localhost:3306/dateexam"); ds.setUsername("root"); ds.setPassword("root"); /* ds.setUsername("exam"); ds.setPassword("exam68");*/ // ds.setInitialSize(5); ds.setMaxIdle(5); ds.setMaxTotal(15); return ds; }
From source file:at.rocworks.oa4j.logger.dbs.NoSQLJDBC.java
private void initStorage(BasicDataSource dataSource, int threads) { JDebug.out.info("jdbc init storage..."); dataSource.setDriverClassName(driver); dataSource.setUrl(this.url); dataSource.setMaxTotal(threads); dataSource.setUsername(username);//from w w w . j a v a2 s .com dataSource.setPassword(password); JDebug.out.info("jdbc get connection..."); // open at least one connection to prevent delay on writing/reading Connection conn; try { conn = dataSource.getConnection(); conn.close(); } catch (SQLException ex) { JDebug.StackTrace(Level.SEVERE, ex); } JDebug.out.info("jdbc init storage...done"); }
From source file:com.thoughtworks.go.server.database.H2Database.java
private void configureDataSource(BasicDataSource source, String url) { String databaseUsername = configuration.getUser(); String databasePassword = configuration.getPassword(); LOG.info("[db] Using connection configuration {} [User: {}]", url, databaseUsername); source.setDriverClassName("org.h2.Driver"); source.setUrl(url);/*from w w w . j av a2s . c o m*/ source.setUsername(databaseUsername); source.setPassword(databasePassword); source.setMaxTotal(configuration.getMaxActive()); source.setMaxIdle(configuration.getMaxIdle()); }
From source file:net.gcolin.simplerepo.search.SearchController.java
public SearchController(ConfigurationManager configManager) throws IOException { this.configManager = configManager; File plugins = new File(configManager.getRoot(), "plugins"); plugins.mkdirs();/* w w w . j a va2s .c o m*/ System.setProperty("derby.system.home", plugins.getAbsolutePath()); BasicDataSource s = new BasicDataSource(); s.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver"); s.setUrl("jdbc:derby:search" + (new File(plugins, "search").exists() ? "" : ";create=true")); s.setUsername("su"); s.setPassword(""); s.setMaxTotal(10); s.setMinIdle(0); s.setDefaultAutoCommit(true); datasource = s; Set<String> allTables = new HashSet<>(); Connection connection = null; try { try { connection = datasource.getConnection(); connection.setAutoCommit(false); DatabaseMetaData dbmeta = connection.getMetaData(); try (ResultSet rs = dbmeta.getTables(null, null, null, new String[] { "TABLE" })) { while (rs.next()) { allTables.add(rs.getString("TABLE_NAME").toLowerCase()); } } if (!allTables.contains("artifact")) { QueryRunner run = new QueryRunner(); run.update(connection, "CREATE TABLE artifactindex(artifact bigint NOT NULL, version bigint NOT NULL)"); run.update(connection, "INSERT INTO artifactindex (artifact,version) VALUES (?,?)", 1L, 1L); run.update(connection, "CREATE TABLE artifact(id bigint NOT NULL,groupId character varying(120), artifactId character varying(120),CONSTRAINT artifact_pkey PRIMARY KEY (id))"); run.update(connection, "CREATE TABLE artifactversion(artifact_id bigint NOT NULL,id bigint NOT NULL," + "version character varying(100)," + "reponame character varying(30)," + "CONSTRAINT artifactversion_pkey PRIMARY KEY (id)," + "CONSTRAINT fk_artifactversion_artifact_id FOREIGN KEY (artifact_id) REFERENCES artifact (id) )"); run.update(connection, "CREATE TABLE artifacttype(version_id bigint NOT NULL,packaging character varying(20) NOT NULL,classifier character varying(30)," + "CONSTRAINT artifacttype_pkey PRIMARY KEY (version_id,packaging,classifier)," + "CONSTRAINT fk_artifacttype_version FOREIGN KEY (version_id) REFERENCES artifactversion (id))"); run.update(connection, "CREATE INDEX artifactindex ON artifact(groupId,artifactId)"); run.update(connection, "CREATE INDEX artifactgroupindex ON artifact(groupId)"); run.update(connection, "CREATE INDEX artifactversionindex ON artifactversion(version)"); } connection.commit(); } catch (SQLException ex) { connection.rollback(); throw ex; } finally { DbUtils.close(connection); } } catch (SQLException ex) { throw new IOException(ex); } }
From source file:de.micromata.genome.util.runtime.LocalSettingsEnv.java
/** * Parses the ds.// w ww . ja v a2s . com */ protected void parseDs() { // db.ds.rogerdb.name=RogersOracle // db.ds.rogerdb.drivername=oracle.jdbc.driver.OracleDriver // db.ds.rogerdb.url=jdbc:oracle:thin:@localhost:1521:rogdb // db.ds.rogerdb.username=genome // db.ds.rogerdb.password=genome List<String> dse = localSettings.getKeysPrefixWithInfix("db.ds", "name"); for (String dsn : dse) { String key = dsn + ".name"; String name = localSettings.get(key); if (StringUtils.isBlank(name) == true) { log.error("Name in local-settings is not defined with key: " + key); continue; } key = dsn + ".drivername"; String driverName = localSettings.get(key); if (StringUtils.isBlank(name) == true) { log.error("drivername in local-settings is not defined with key: " + key); continue; } key = dsn + ".url"; String url = localSettings.get(key); if (StringUtils.isBlank(name) == true) { log.error("url in local-settings is not defined with key: " + key); continue; } key = dsn + ".username"; String userName = localSettings.get(key); key = dsn + ".password"; String password = localSettings.get(key); BasicDataSource bd = dataSourceSuplier.get(); bd.setDriverClassName(driverName); bd.setUrl(url); bd.setUsername(userName); bd.setPassword(password); bd.setMaxTotal(localSettings.getIntValue(dsn + ".maxActive", GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL_PER_KEY)); bd.setMaxIdle(localSettings.getIntValue(dsn + ".maxIdle", GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE_PER_KEY)); bd.setMinIdle(localSettings.getIntValue(dsn + ".minIdle", GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE_PER_KEY)); bd.setMaxWaitMillis(localSettings.getLongValue(dsn + ".maxWait", GenericKeyedObjectPoolConfig.DEFAULT_MAX_WAIT_MILLIS)); bd.setInitialSize(localSettings.getIntValue(dsn + ".intialSize", 0)); bd.setDefaultCatalog(localSettings.get(dsn + ".defaultCatalog", null)); bd.setDefaultAutoCommit(localSettings.getBooleanValue(dsn + ".defaultAutoCommit", true)); bd.setValidationQuery(localSettings.get(dsn + ".validationQuery", null)); bd.setValidationQueryTimeout(localSettings.getIntValue(dsn + ".validationQueryTimeout", -1)); dataSources.put(name, bd); } }
From source file:com.emc.vipr.sync.filter.TrackingFilter.java
@Override public void parseCustomOptions(CommandLine line) { if (!line.hasOption(DB_URL_OPT)) throw new ConfigurationException("Must provide a database to use the tracking filter"); if (line.hasOption(TABLE_OPT)) tableName = line.getOptionValue(TABLE_OPT); createTable = line.hasOption(CREATE_TABLE_OPT); processAllObjects = line.hasOption(REPROCESS_OPT); if (line.hasOption(META_OPT)) metaTags = Arrays.asList(line.getOptionValue(META_OPT).split(",")); // Initialize a DB connection pool BasicDataSource ds = new BasicDataSource(); ds.setUrl(line.getOptionValue(DB_URL_OPT)); if (line.hasOption(DB_DRIVER_OPT)) ds.setDriverClassName(line.getOptionValue(DB_DRIVER_OPT)); ds.setUsername(line.getOptionValue(DB_USER_OPT)); ds.setPassword(line.getOptionValue(DB_PASSWORD_OPT)); ds.setMaxTotal(200); ds.setMaxOpenPreparedStatements(180); dataSource = ds;/*w w w .ja v a 2 s. c o m*/ }
From source file:com.emc.vipr.sync.source.AtmosSource.java
@Override public void parseCustomOptions(CommandLine line) { AtmosUtil.AtmosUri atmosUri = AtmosUtil.parseUri(sourceUri); endpoints = atmosUri.endpoints;//from w w w . j a v a 2 s . c o m uid = atmosUri.uid; secret = atmosUri.secret; namespaceRoot = atmosUri.rootPath; if (line.hasOption(SOURCE_OIDLIST_OPTION)) oidFile = line.getOptionValue(SOURCE_OIDLIST_OPTION); if (line.hasOption(SOURCE_NAMELIST_OPTION)) nameFile = line.getOptionValue(SOURCE_NAMELIST_OPTION); if (line.hasOption(SOURCE_SQLQUERY_OPTION)) { query = line.getOptionValue(SOURCE_SQLQUERY_OPTION); // Initialize a connection pool BasicDataSource ds = new BasicDataSource(); ds.setUrl(line.getOptionValue(JDBC_URL_OPT)); if (line.hasOption(JDBC_DRIVER_OPT)) ds.setDriverClassName(line.getOptionValue(JDBC_DRIVER_OPT)); ds.setUsername(line.getOptionValue(JDBC_USER_OPT)); ds.setPassword(line.getOptionValue(JDBC_PASSWORD_OPT)); ds.setMaxTotal(200); ds.setMaxOpenPreparedStatements(180); setDataSource(ds); } deleteTags = line.hasOption(DELETE_TAGS_OPT); }
From source file:no.kantega.publishing.common.util.database.dbConnectionFactory.java
public static void loadConfiguration() { try {/* ww w . j a v a 2 s .co m*/ setConfiguration(); verifyCompleteDatabaseConfiguration(); DriverManagerDataSource rawDataSource = new DriverManagerDataSource(); rawDataSource.setDriverClassName(dbDriver); rawDataSource.setUrl(dbUrl); if (!dbNTMLAuthentication) { rawDataSource.setUsername(dbUsername); rawDataSource.setPassword(dbPassword); } if (dbEnablePooling) { // Enable DBCP pooling BasicDataSource bds = new BasicDataSource(); bds.setMaxTotal(dbMaxConnections); bds.setMaxIdle(dbMaxIdleConnections); bds.setMinIdle(dbMinIdleConnections); if (dbMaxWait != -1) { bds.setMaxWaitMillis(1000 * dbMaxWait); } if (dbDefaultQueryTimeout != -1) { bds.setDefaultQueryTimeout(dbDefaultQueryTimeout); } bds.setDriverClassName(dbDriver); if (!dbNTMLAuthentication) { bds.setUsername(dbUsername); bds.setPassword(dbPassword); } bds.setUrl(dbUrl); if (dbUseTransactions) { bds.setDefaultTransactionIsolation(dbTransactionIsolationLevel); } if (dbCheckConnections) { // Gjr at connections frigjres ved lukking fra database/brannmur bds.setValidationQuery("SELECT max(ContentId) from content"); bds.setTimeBetweenEvictionRunsMillis(1000 * 60 * 2); bds.setMinEvictableIdleTimeMillis(1000 * 60 * 5); bds.setNumTestsPerEvictionRun(dbMaxConnections); if (dbRemoveAbandonedTimeout > 0) { bds.setRemoveAbandonedTimeout(dbRemoveAbandonedTimeout); bds.setLogAbandoned(true); } } ds = bds; } else { ds = rawDataSource; } // Use non-pooled datasource for table creation since validation query might fail ensureDatabaseExists(rawDataSource); if (shouldMigrateDatabase) { migrateDatabase(servletContext, rawDataSource); } if (dbUseTransactions) { log.info("Using transactions, database transaction isolation level set to " + dbTransactionIsolationLevel); } else { log.info("Not using transactions"); } if (debugConnections) { proxyDs = (DataSource) Proxy.newProxyInstance(DataSource.class.getClassLoader(), new Class[] { DataSource.class }, new DataSourceWrapper(ds)); } } catch (Exception e) { log.error("********* could not read aksess.conf **********", e); } }
From source file:org.apache.jmeter.protocol.jdbc.config.DataSourceElement.java
private BasicDataSource initPool(String maxPool) { BasicDataSource dataSource = new BasicDataSource(); if (log.isDebugEnabled()) { StringBuilder sb = new StringBuilder(40); sb.append("MaxPool: "); sb.append(maxPool);/*www. j av a2s . c o m*/ sb.append(" Timeout: "); sb.append(getTimeout()); sb.append(" TrimInt: "); sb.append(getTrimInterval()); sb.append(" Auto-Commit: "); sb.append(isAutocommit()); log.debug(sb.toString()); } int poolSize = Integer.parseInt(maxPool); dataSource.setMinIdle(0); dataSource.setInitialSize(poolSize); dataSource.setMaxIdle(poolSize); dataSource.setMaxTotal(poolSize); dataSource.setMaxWaitMillis(Long.parseLong(getTimeout())); dataSource.setDefaultAutoCommit(Boolean.valueOf(isAutocommit())); if (log.isDebugEnabled()) { StringBuilder sb = new StringBuilder(40); sb.append("KeepAlive: "); sb.append(isKeepAlive()); sb.append(" Age: "); sb.append(getConnectionAge()); sb.append(" CheckQuery: "); sb.append(getCheckQuery()); log.debug(sb.toString()); } dataSource.setTestOnBorrow(false); dataSource.setTestOnReturn(false); dataSource.setTestOnCreate(false); dataSource.setTestWhileIdle(false); if (isKeepAlive()) { dataSource.setTestWhileIdle(true); dataSource.setValidationQuery(getCheckQuery()); dataSource.setSoftMinEvictableIdleTimeMillis(Long.parseLong(getConnectionAge())); dataSource.setTimeBetweenEvictionRunsMillis(Integer.parseInt(getTrimInterval())); } int transactionIsolation = DataSourceElementBeanInfo.getTransactionIsolationMode(getTransactionIsolation()); if (transactionIsolation >= 0) { dataSource.setDefaultTransactionIsolation(transactionIsolation); } String _username = getUsername(); if (log.isDebugEnabled()) { StringBuilder sb = new StringBuilder(40); sb.append("Driver: "); sb.append(getDriver()); sb.append(" DbUrl: "); sb.append(getDbUrl()); sb.append(" User: "); sb.append(_username); log.debug(sb.toString()); } dataSource.setDriverClassName(getDriver()); dataSource.setUrl(getDbUrl()); if (_username.length() > 0) { dataSource.setUsername(_username); dataSource.setPassword(getPassword()); } // log is required to ensure errors are available //source.enableLogging(new LogKitLogger(log)); if (log.isDebugEnabled()) { log.debug("PoolConfiguration:" + this.dataSource); } return dataSource; }