Example usage for org.apache.commons.dbcp BasicDataSource BasicDataSource

List of usage examples for org.apache.commons.dbcp BasicDataSource BasicDataSource

Introduction

In this page you can find the example usage for org.apache.commons.dbcp BasicDataSource BasicDataSource.

Prototype

BasicDataSource

Source Link

Usage

From source file:gtu._work.ui.RegexCatchReplacer_Ebao.java

private DataSource getDbDataSource() {
    String url = null;/*from   ww  w  . jav a  2  s  .c  o m*/
    String username = null;
    String password = null;
    if (ebaoProp.containsKey("url")) {
        url = ebaoProp.getProperty("url");
    }
    if (ebaoProp.containsKey("username")) {
        username = ebaoProp.getProperty("username");
    }
    if (ebaoProp.containsKey("password")) {
        password = ebaoProp.getProperty("password");
    }
    BasicDataSource bds = new BasicDataSource();
    bds.setUrl(url);
    bds.setUsername(username);
    bds.setPassword(password);
    bds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    return bds;
}

From source file:com.jolbox.benchmark.BenchmarkTests.java

/**
 * Benchmarks PreparedStatement functionality (single thread) 
 * @return result//from   www .  j a  v a2s  .c  om
 * 
 * @throws PropertyVetoException
 * @throws SQLException
 */
private long testPreparedStatementSingleThreadDBCP() throws PropertyVetoException, SQLException {
    BasicDataSource cpds = new BasicDataSource();
    cpds.setDriverClassName("com.jolbox.bonecp.MockJDBCDriver");
    cpds.setUrl(url);
    cpds.setUsername(username);
    cpds.setPassword(password);
    cpds.setMaxIdle(-1);
    cpds.setMinIdle(-1);
    cpds.setPoolPreparedStatements(true);
    cpds.setMaxOpenPreparedStatements(30);
    cpds.setInitialSize(pool_size);
    cpds.setMaxActive(pool_size);
    Connection conn = cpds.getConnection();

    long start = System.currentTimeMillis();
    for (int i = 0; i < MAX_CONNECTIONS; i++) {
        Statement st = conn.prepareStatement(TEST_QUERY);
        st.close();
    }
    conn.close();

    long end = (System.currentTimeMillis() - start);
    System.out.println("DBCP PreparedStatement Single thread benchmark: " + end);
    results.add("DBCP, " + end);
    // dispose of pool
    cpds.close();
    return end;
}

From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexerSettings.java

@Override
public void initProperties(Properties properties) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(properties.getProperty("provider", "org.postgresql.Driver"));
    dataSource.setUrl(properties.getProperty("url"));
    dataSource.setUsername(properties.getProperty("username"));
    dataSource.setPassword(properties.getProperty("password"));
    this.setDataSource(dataSource);
    this.setIndexGraph((IndexGraph) properties.get("index-graph"));
    this.tableName = properties.getProperty("index-table");
}

From source file:nl.surfnet.coin.db.AbstractInMemoryDatabaseTest.java

/**
 * We use an in-memory database - no need for Spring in this one - and
 * populate it with the sql statements in test-data-eb.sql
 * //from  ww w.  j a  va  2  s.co  m
 * @throws Exception
 *           unexpected
 */
@Before
public void before() throws Exception {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setPassword("");
    dataSource.setUsername("sa");
    String url = getDataSourceUrl();
    dataSource.setUrl(url);
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");

    jdbcTemplate = new JdbcTemplate(dataSource);

    ClassPathResource resource = new ClassPathResource(getMockDataContentFilename());
    logger.debug("Loading database content from " + resource);
    if (resource.exists()) {
        final String sql = IOUtils.toString(resource.getInputStream());
        final String[] split = sql.split(";");
        for (String s : split) {
            if (!StringUtils.hasText(s)) {
                continue;
            }
            jdbcTemplate.execute(s + ';');
        }
    }
}

From source file:nl.surfnet.coin.db.MigrationsTest.java

private BasicDataSource hsqldbDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.hsqldb.jdbcDriver");
    ds.setUrl("jdbc:hsqldb:mem:api");
    ds.setUsername("sa");
    ds.setPassword("");
    return ds;//w w  w.  ja v a 2 s.  c o m
}

From source file:nl.surfnet.coin.db.MigrationsTest.java

private BasicDataSource mysqlDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUrl("jdbc:mysql://localhost:3306/apitest");
    ds.setUsername("root");
    ds.setPassword("");
    return ds;//  w  w w.j a  v  a 2s  .  c o  m
}

From source file:nl.trivento.albero.repositories.DatabaseRepository.java

private DataSource createBasicDataSource(Map<String, String> parameters) throws ConfigurationException {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(parameters.get(DRIVER));
    dataSource.setUrl(parameters.get(URL));
    dataSource.setUsername(parameters.get(USER));
    dataSource.setPassword(parameters.get(PASSWORD));

    return dataSource;
}

From source file:org.activiti.spring.test.jpa.JPASpringTest.java

@Bean
public DataSource dataSource() {
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setUsername("sa");
    basicDataSource.setUrl("jdbc:h2:mem:activiti");
    basicDataSource.setDefaultAutoCommit(false);
    basicDataSource.setDriverClassName(org.h2.Driver.class.getName());
    basicDataSource.setPassword("");
    return basicDataSource;
}

From source file:org.alexlg.bankit.Launcher.java

public static void main(String[] args) throws Exception {
    LoadingFrame loadingFrame = new LoadingFrame();
    loadingFrame.display();// w w  w.  j a  v a2s  .  c  om

    File warFile = null;
    if (!(args.length > 0 && args[0].equals("nowar"))) { //can be deactivated for tests
        //searching war file in lib dir
        File libDir = new File("lib");
        if (!libDir.isDirectory())
            throw new Exception("Directory [lib] doesn't exists in [" + libDir.getAbsolutePath() + "]");

        for (File file : libDir.listFiles()) {
            if (file.getName().endsWith(".war")) {
                warFile = file;
                break;
            }
        }
        if (warFile == null)
            throw new Exception("Cant find any .war file in [" + libDir.getAbsolutePath() + "]");
    }

    final int port = findAvailablePort(8080);

    //server definition
    Server server = new Server();
    server.setGracefulShutdown(1000);
    server.setStopAtShutdown(true);

    //http connector
    Connector connector = new SelectChannelConnector();
    connector.setHost("localhost");
    connector.setPort(port);
    server.addConnector(connector);

    //handlers context
    ContextHandlerCollection contexts = new ContextHandlerCollection();

    //shutdown servlet
    ServletContextHandler shutdownServletCtx = new ServletContextHandler();
    shutdownServletCtx.setContextPath("/shutdown");
    shutdownServletCtx.addServlet(new ServletHolder(new ShutdownServlet(server)), "/*");
    contexts.addHandler(shutdownServletCtx);

    //bankit war
    if (warFile != null) {
        WebAppContext webAppContext = new WebAppContext();
        webAppContext.setContextPath("/bankit");
        webAppContext.setWar(warFile.getAbsolutePath());
        webAppContext.setTempDirectory(new File("tmp/"));

        //prevent slf4j api to be loaded by the webapp
        //in order to keep the jetty logback configuration
        webAppContext.setClassLoader(new WebAppClassLoaderNoSlf4J(webAppContext));

        contexts.addHandler(webAppContext);
    }

    //database datasource
    BasicDataSource datasource = new BasicDataSource();
    datasource.setDriverClassName("org.h2.Driver");
    datasource.setUrl("jdbc:h2:bankit");
    new Resource("jdbc/bankit", datasource);

    //standalone jndi resource
    Boolean standalone = true;
    new Resource("java:comp/env/standalone", standalone);

    //adding Handlers for servlet and war
    server.setHandler(contexts);
    server.start();

    //start the user browser after the server started
    startBrowser("http://localhost:" + port + "/bankit/");
    loadingFrame.close();

    server.join();
}

From source file:org.ambraproject.doi.BaseResolverTest.java

@BeforeClass
public void createDB() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    dataSource.setUrl("jdbc:hsqldb:mem:testdb");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    this.dataSource = dataSource;
    jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("drop table if exists annotation;" + "drop table if exists article;"
            + "create table article (" + "  articleID bigint not null," + "  doi varchar(255) not null,"
            + "  primary key (articleID)" + ");" + "create table annotation ("
            + "  annotationID bigint not null," + "  annotationURI varchar(255) not null,"
            + "  articleID bigint null," + "  type varchar(16) default null," + "  primary key (annotationID)"
            + ");" + "alter table annotation add foreign key (articleID) references article (articleID);");
}