List of usage examples for org.apache.commons.dbcp2 BasicDataSource BasicDataSource
BasicDataSource
From source file:at.rocworks.oa4j.logger.dbs.NoSQLJDBC.java
public NoSQLJDBC(NoSQLSettings settings, String driver, String url, String username, String password, String archive) {/*w w w . ja v a 2s. c o m*/ super(settings); this.driver = driver; this.url = url; this.username = username; this.password = password; this.archive = archive; this.cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); // default insert this.sqlInsertStmt = "INSERT INTO " + archive + "HISTORY " + "(tag, ts, value_number, value_string, value_timestamp, status, manager, user_)" + "VALUES (?,?,?,?,?,?,?,?)"; // default select this.sqlSelectStmt = "SELECT %s FROM " + archive + "HISTORY " + " WHERE tag=? AND ts>=? AND ts<=?"; try { Class.forName(driver); dataSourceWrite = new BasicDataSource(); initStorage(dataSourceWrite, this.settings.getThreads()); dataSourceQuery = new BasicDataSource(); initStorage(dataSourceQuery, this.settings.getThreads() * this.settings.getThreads()); } catch (ClassNotFoundException ex) { JDebug.StackTrace(Level.SEVERE, ex); } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.topics.MMXTopicsItemsResourceTest.java
@BeforeClass public static void setupDatabase() throws Exception { InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties"); Properties testProperties = new Properties(); testProperties.load(inputStream);/* w ww . j av a2 s.c o m*/ String host = testProperties.getProperty("db.host"); String port = testProperties.getProperty("db.port"); String user = testProperties.getProperty("db.user"); String password = testProperties.getProperty("db.password"); String driver = testProperties.getProperty("db.driver"); String schema = testProperties.getProperty("db.schema"); String url = "jdbc:mysql://" + host + ":" + port + "/" + schema; ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUsername(user); ds.setPassword(password); ds.setUrl(url); DBTestUtil.setBasicDataSource(ds); new MockUp<AppDAOImpl>() { @Mock protected String getEncrypted(String value) { return value; } }; new MockUp<AppDAOImpl>() { @Mock protected String getEncrypted(String value) { return value; } }; new MockUp<DefaultOpenfireEncryptor>() { @Mock public String getDecrypted(String value) { return value; } @Mock public String getEncrypted(String value) { return value; } }; DBTestUtil.setupMockDBUtil(); appEntity = createRandomApp(); generatePubsubItems(); }
From source file:com.qwazr.library.jdbc.JdbcConnector.java
@Override public void load() throws IllegalAccessException, ClassNotFoundException, InstantiationException { if (pool == null) { JDBCConnection cnx = new JDBCConnection(); if (!StringUtils.isEmpty(driver)) cnx.setDriver(Thread.currentThread().getContextClassLoader(), SubstitutedVariables.propertyAndEnvironmentSubstitute(driver)); if (!StringUtils.isEmpty(url)) cnx.setUrl(SubstitutedVariables.propertyAndEnvironmentSubstitute(url)); if (!StringUtils.isEmpty(username)) cnx.setUsername(SubstitutedVariables.propertyAndEnvironmentSubstitute(username)); if (!StringUtils.isEmpty(password)) cnx.setPassword(SubstitutedVariables.propertyAndEnvironmentSubstitute(password)); connectionManager = cnx;/*from w ww. ja va2 s .c o m*/ basicDataSource = null; } else { basicDataSource = new BasicDataSource(); if (driver != null) basicDataSource.setDriverClassName(SubstitutedVariables.propertyAndEnvironmentSubstitute(driver)); if (url != null) basicDataSource.setUrl(SubstitutedVariables.propertyAndEnvironmentSubstitute(url)); if (username != null) basicDataSource.setUsername(SubstitutedVariables.propertyAndEnvironmentSubstitute(username)); if (password != null) basicDataSource.setPassword(SubstitutedVariables.propertyAndEnvironmentSubstitute(password)); if (pool.initial_size != null) basicDataSource.setInitialSize(pool.initial_size); if (pool.min_idle != null) basicDataSource.setMinIdle(pool.min_idle); if (pool.max_idle != null) basicDataSource.setMaxIdle(pool.max_idle); if (pool.max_total != null) basicDataSource.setMaxTotal(pool.max_total); if (pool.max_wait_millis != null) basicDataSource.setMaxWaitMillis(pool.max_wait_millis); if (pool.log_abandoned != null) basicDataSource.setLogAbandoned(pool.log_abandoned); if (pool.log_expired_connections != null) basicDataSource.setLogExpiredConnections(pool.log_expired_connections); if (pool.abandoned_usage_tracking != null) basicDataSource.setAbandonedUsageTracking(pool.abandoned_usage_tracking); connectionManager = new DataSourceConnection(basicDataSource); } }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.tags.MMXUserTagsResourceTest.java
public static void setupDatabase() throws Exception { InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties"); Properties testProperties = new Properties(); testProperties.load(inputStream);//from ww w . j av a2s . c om String host = testProperties.getProperty("db.host"); String port = testProperties.getProperty("db.port"); String user = testProperties.getProperty("db.user"); String password = testProperties.getProperty("db.password"); String driver = testProperties.getProperty("db.driver"); String schema = testProperties.getProperty("db.schema"); String url = "jdbc:mysql://" + host + ":" + port + "/" + schema; ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUsername(user); ds.setPassword(password); ds.setUrl(url); DBTestUtil.setBasicDataSource(ds); new MockUp<AppDAOImpl>() { @Mock protected String getEncrypted(String value) { return value; } }; DBTestUtil.setupMockDBUtil(); MMXUserTagsResourceTest.appEntity = createRandomApp(); userEntityList.add(createRandomUser(appEntity, 1)); userEntityList.add(createRandomUser(appEntity, 2)); }
From source file:com.searchbox.framework.config.DataConfiguration.java
@Bean public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER)); dataSource.setUrl(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_URL)); dataSource.setUsername(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME)); dataSource.setPassword(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_PASSWORD)); return dataSource; }
From source file:io.agi.framework.persistence.jdbc.JdbcUtil.java
public static void CreateDataSource(String dbUrl, String user, String password, String driverClassName) { _dataSource = new BasicDataSource(); _dataSource.setDriverClassName(driverClassName); _dataSource.setUrl(dbUrl);//from ww w .j a v a 2s. com _dataSource.setUsername(user); _dataSource.setPassword(password); _dataSource.setMaxIdle(100); }
From source file:com.bc.fiduceo.TestUtil.java
public static BasicDataSource getdatasourceMongoDb() { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("mongodb"); dataSource.setUrl("mongodb://localhost:27017"); dataSource.setUsername("fiduceo"); dataSource.setPassword("oecudif"); return dataSource; }
From source file:com.dsf.dbxtract.cdc.journal.JournalExecutor.java
/** * @param agentName//www . j a v a 2 s . co m * cdc agent's assigned name * @param zookeeper * connection string to ZooKeeper server * @param handler * {@link JournalHandler} * @param source * {@link Source} */ public JournalExecutor(String agentName, String zookeeper, JournalHandler handler, Source source) { logPrefix = agentName + " :: "; if (logger.isDebugEnabled()) logger.debug(logPrefix + "Creating executor for " + handler + " and " + source); this.agentName = agentName; this.zookeeper = zookeeper; this.handler = handler; this.source = source; BasicDataSource ds = dataSources.get(source); if (ds == null) { if (logger.isDebugEnabled()) logger.debug(agentName + " :: setting up a connection pool for " + source.toString()); ds = new BasicDataSource(); ds.setDriverClassName(source.getDriver()); ds.setUsername(source.getUser()); ds.setPassword(source.getPassword()); ds.setUrl(source.getConnection()); dataSources.put(source, ds); } if (statistics == null) statistics = new Statistics(); }
From source file:com.jf.javafx.services.Database.java
public DataSource getDataSource(String jndiName) { DBInfo i = infos.get(jndiName);/*from w w w . j a v a 2 s.c om*/ if (i == null) { return null; } DataSource ds = dss.get(jndiName); if (ds == null) { BasicDataSource t = new BasicDataSource(); t.setDriverClassName(i.dsProvider); t.setUrl(i.dbUrl); if (!i.dbUsername.isEmpty()) t.setUsername(i.dbUsername); if (!i.dbPassword.isEmpty()) t.setPassword(i.dbPassword); ds = t; dss.put(jndiName, ds); } return ds; }
From source file:com.thoughtworks.go.server.database.H2Database.java
private BasicDataSource createDataSource(Boolean mvccEnabled) { if (this.dataSource == null) { BasicDataSource source = new BasicDataSource(); if (systemEnvironment.inDbDebugMode()) { String url = String.format("jdbc:h2:tcp://%s:%s/%s", configuration.getHost(), configuration.getPort(), configuration.getName()); configureDataSource(source, url); LOG.info("Creating debug data source on port={}", configuration.getPort()); } else {/* w ww. ja v a2 s . co m*/ String url = dburl(mvccEnabled); configureDataSource(source, url); LOG.info("Creating data source with url={}", url); } this.dataSource = source; } return dataSource; }