List of usage examples for org.apache.commons.dbcp BasicDataSource BasicDataSource
BasicDataSource
From source file:demo.learn.shiro.util.SqlUtil.java
/** * Gets the basic {@link DataSource}. Hard-coded * in this util. There is a script, mysql.sql, to * create the MySQL database./*from ww w. j ava 2s . com*/ * @return {@link DataSource}. */ public static DataSource getBasicDataSource() { if (null == _basicDataSource) { BasicDataSource ds = new BasicDataSource(); ds.setUsername("secure"); ds.setPassword("secure#123}{"); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setUrl("jdbc:mysql://mysql:3306/secure?profileSQL=false"); ds.setMaxActive(10); _basicDataSource = ds; } return _basicDataSource; }
From source file:gobblin.data.management.retention.sql.SqlBasedRetentionPoc.java
/** * <ul>/*from ww w.j a v a 2 s.c o m*/ * <li>Create the in-memory database and connect * <li>Create tables for snapshots and daily_paritions * <li>Attach all user defined functions from {@link SqlUdfs} * </ul> * */ @BeforeClass public void setup() throws SQLException { basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver"); basicDataSource.setUrl("jdbc:derby:memory:derbypoc;create=true"); Connection connection = basicDataSource.getConnection(); connection.setAutoCommit(false); this.connection = connection; execute("CREATE TABLE Snapshots (dataset_path VARCHAR(255), name VARCHAR(255), path VARCHAR(255), ts TIMESTAMP, row_count bigint)"); execute("CREATE TABLE Daily_Partitions (dataset_path VARCHAR(255), path VARCHAR(255), ts TIMESTAMP)"); // Register UDFs execute("CREATE FUNCTION TIMESTAMP_DIFF(timestamp1 TIMESTAMP, timestamp2 TIMESTAMP, unitString VARCHAR(50)) RETURNS BIGINT PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA EXTERNAL NAME 'gobblin.data.management.retention.sql.SqlUdfs.timestamp_diff'"); }
From source file:capture.MySQLDatabase.java
public MySQLDatabase() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(DRIVER);/* w w w . j a v a 2s . com*/ ds.setUsername(ConfigManager.getInstance().getConfigOption("database-username")); ds.setPassword(ConfigManager.getInstance().getConfigOption("database-password")); ds.setUrl(ConfigManager.getInstance().getConfigOption("database-url")); dataSource = ds; }
From source file:com.dangdang.ddframe.job.event.rdb.JobEventRdbConfigurationTest.java
@Test(expected = JobEventListenerConfigurationException.class) public void assertCreateJobEventListenerFailure() throws JobEventListenerConfigurationException { new JobEventRdbConfiguration(new BasicDataSource()).createJobEventListener(); }
From source file:com.qcadoo.model.Utils.java
public static DataSource createDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setUrl("jdbc:hsqldb:mem:mes"); dataSource.setUsername("sa"); dataSource.setPassword(""); return dataSource; }
From source file:com.dangdang.ddframe.rdb.sharding.spring.AbstractSpringDBUnitTest.java
private DataSource createDataSource(final String dataSetFile) { BasicDataSource result = new BasicDataSource(); result.setDriverClassName(org.h2.Driver.class.getName()); result.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL", getFileName(dataSetFile)));/* w w w .jav a2 s . c o m*/ result.setUsername("sa"); result.setPassword(""); result.setMaxActive(100); return result; }
From source file:com.pinterest.deployservice.db.DatabaseUtil.java
/** * Create a MySQL datasource./*w w w . j av a 2 s. c om*/ * * @param url the url of the DB. * @param user the user name to connect to MySQL as. * @param passwd the password for the corresponding MySQL user. * @param poolSize the connection pool size string, in the format of * initialSize:maxActive:maxIdle:minIdle. * @param maxWaitInMillis the max wait time in milliseconds to get a connection from the pool. * @return a BasicDataSource for the target MySQL instance. */ public static BasicDataSource createDataSource(String driverClassName, String url, String user, String passwd, String poolSize, int maxWaitInMillis) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverClassName); dataSource.setUrl(url); dataSource.setUsername(user); dataSource.setPassword(passwd); dataSource.setDefaultAutoCommit(true); dataSource.setDefaultReadOnly(false); // poolSize parsing, the poolsize string passed in the following format // initialSize:maxActive:maxIdle:minIdle String[] sizeStrs = poolSize.split(":"); dataSource.setInitialSize(Integer.parseInt(sizeStrs[0])); dataSource.setMaxActive(Integer.parseInt(sizeStrs[1])); dataSource.setMaxIdle(Integer.parseInt(sizeStrs[2])); dataSource.setMinIdle(Integer.parseInt(sizeStrs[3])); dataSource.setValidationQuery("SELECT 1"); dataSource.setTestOnBorrow(true); dataSource.setTestOnReturn(false); dataSource.setTestWhileIdle(true); dataSource.setMinEvictableIdleTimeMillis(5 * 60 * 1000); dataSource.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000); // dataSource.setNumTestsPerEvictionRun(3); // max wait in milliseconds for a connection. dataSource.setMaxWait(maxWaitInMillis); // force connection pool initialization. Connection conn = null; try { // Here not getting the connection from ThreadLocal no need to worry about that. conn = dataSource.getConnection(); } catch (SQLException e) { LOG.error(String.format("Failed to get a db connection when creating DataSource, url = %s", url), e); } finally { DbUtils.closeQuietly(conn); } return dataSource; }
From source file:be.ugent.tiwi.sleroux.newsrec.stormNewsFetch.dao.mysqlImpl.JDBCViewsDao.java
/** * * @throws ViewsDaoException// w w w . j av a 2s. co m */ public JDBCViewsDao() throws ViewsDaoException { logger.debug("JDBCViewsDao constructor called"); if (connectionPool == null) { logger.debug("creating connectionpool"); String driver = bundle.getString("dbDriver"); String user = bundle.getString("dbUser"); String pass = bundle.getString("dbPass"); String url = bundle.getString("dbUrl"); url = url + "?user=" + user + "&password=" + pass; connectionPool = new BasicDataSource(); connectionPool.setDriverClassName(driver); connectionPool.setUsername(user); connectionPool.setPassword(pass); connectionPool.setUrl(url); logger.debug("connectionpool created"); } try { logger.debug("creating preparedstatements"); String statementText = bundle.getString("selectViewsQuery"); selectStatement = connectionPool.getConnection().prepareStatement(statementText); statementText = bundle.getString("insertUpdateViewsQuery"); insertViewsStatement = connectionPool.getConnection().prepareStatement(statementText); statementText = bundle.getString("selectTopNViewsQuery"); selectTopNStatement = connectionPool.getConnection().prepareStatement(statementText); logger.debug("created preparedstatements"); } catch (SQLException ex) { logger.error(ex.getMessage(), ex); throw new ViewsDaoException(ex); } }
From source file:com.abixen.platform.core.configuration.PlatformDataSourceConfiguration.java
@Profile(PlatformProfiles.TEST) @Bean(destroyMethod = "close") public DataSource testDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(platformJdbcConfiguration.getDriverClassName()); dataSource.setUrl(platformJdbcConfiguration.getDatabaseUrl()); dataSource.setUsername(platformJdbcConfiguration.getUsername()); dataSource.setPassword(platformJdbcConfiguration.getPassword()); // DatabasePopulatorUtils.execute(databasePopulator(), dataSource); return dataSource; }
From source file:jp.go.nict.langrid.serviceexecutor.db.ConnectionManager.java
private void initWithBasicDataSource(String driverClassName, String connectionUrl, String userName, String password, int maxActive, int maxIdle, int maxWait, int maxPSActive) { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(driverClassName); bds.setUrl(connectionUrl);/*from ww w.j a va2 s . com*/ bds.setUsername(userName); bds.setPassword(password); bds.setMaxActive(maxActive); bds.setMaxIdle(maxIdle); bds.setMaxWait(maxWait); if (maxPSActive != -1) { bds.setMaxOpenPreparedStatements(maxPSActive); } this.dataSource = bds; }