Package org.apache.commons.dbcp

Examples of org.apache.commons.dbcp.BasicDataSource


            params.put( PORT.key, port );
            params.put( USER.key, username );
            params.put( PASSWD.key, password );
            params.put( DATABASE.key, "template1");
           
            BasicDataSource source = PostgisServiceExtension2.getFactory().createDataSource(params );
            Connection connection = source.getConnection();
            try {
               
                Statement statement = connection.createStatement();
                if (statement.execute("SELECT datname FROM pg_database")) {
                    ResultSet resultSet = statement.getResultSet();
                    while (resultSet.next()) {
                        databaseNames.add(resultSet.getString("datname"));
                    }
                }
                statement.close();
            } finally {
                if( connection != null ){
                    connection.close();
                }
                if( source != null ){
                    source.close();
                }
            }
        }
        catch (SQLException e) {
            checkSqlException(e);
View Full Code Here


            throw new SynapseException(msg);
        }

        if (dataSource instanceof BasicDataSource) {

            BasicDataSource basicDataSource = (BasicDataSource) dataSource;
            int numActive = basicDataSource.getNumActive();
            int numIdle = basicDataSource.getNumIdle();
            String connectionId = Integer.toHexString(con.hashCode());

            DBPoolView dbPoolView = getDbPoolView();
            if (dbPoolView != null) {
                dbPoolView.setNumActive(numActive);
View Full Code Here

                bindings = containerSystem.getJNDIContext().listBindings("openejb/Resource/");
                Set<String> dbnames = new TreeSet<String>();
                for (Binding binding : Collections.list(bindings)) {
                    Object value = binding.getObject();
                    if (value instanceof BasicDataSource) {
                        BasicDataSource jdbc = (BasicDataSource) value;
                        String path = getPath(jdbc);
                        if (path != null) {
                            if (dbnames.size() > 9) {
                                throw new ServiceException("Hsql Server can only host 10 database instances");
                            }
View Full Code Here

     * @return the data source
     * @throws Exception if an error occurs
     */
    private DataSource setUpDataSource() throws Exception
    {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(DATABASE_DRIVER);
        ds.setUrl(DATABASE_URL);
        ds.setUsername(DATABASE_USERNAME);
        ds.setPassword(DATABASE_PASSWORD);
        ds.setDefaultAutoCommit(!isAutoCommit());

        // prepare the database
        Connection conn = ds.getConnection();
        IDatabaseConnection connection = new DatabaseConnection(conn);
        IDataSet dataSet = new XmlDataSet(new FileInputStream(
                ConfigurationAssert.getTestFile("dataset.xml")));

        try
View Full Code Here

        return conn;
    }

    private java.sql.Connection getJDBCConnection() throws Exception {
        BasicDataSource dataSource = getMandatoryBean(BasicDataSource.class, "managedDataSourceWithRecovery");
        return dataSource.getConnection();
    }
View Full Code Here

     * Constructor
     * @param params PoolDatasource
     */
    public InternalPoolConnectionStrategy(
            final InternalPoolDatasource params) {
        dataSource = new BasicDataSource();

        dataSource.setDriverClassName(params.getDriverClass());
        dataSource.setUrl(params.getUrl());
        dataSource.setUsername(params.getUsername());
        dataSource.setPassword(params.getPassword());
View Full Code Here

    }

    @Test public void test() throws Exception {
        assertNotNull(bean.datasource());
        assertTrue(bean.datasource() instanceof BasicDataSource);
        BasicDataSource ds = (BasicDataSource) bean.datasource();
        assertEquals("org.hsqldb.jdbcDriver", ds.getDriverClassName());
        assertEquals("not:used:url", ds.getUrl());
        assertEquals("foo", ds.getUsername());
        assertEquals("bar", ds.getPassword());

        assertNotNull(bean.resource());
        assertEquals("ok", bean.resource().attr);
    }
View Full Code Here

            }
        }

        // DataSource is created to connect to user store DB using input parameters given by user

        BasicDataSource ds = new BasicDataSource();
        ds.setUrl(dbURL);
        ds.setDriverClassName(dbDriver);
        ds.setUsername(dbUsername);
        ds.setPassword(dbPassword);

        try {
            RealmConfiguration realmConfig = new RealmConfigXMLProcessor()
                    .buildRealmConfigurationFromFile();
            UserStoreManager userStore = new JDBCUserStoreManager(ds, realmConfig, 0, true);
View Full Code Here

        daoFactory = DAOFactory.getDAOFactory(DAOFactoryType.JPA, doaFactorySettings);
    }

    private void initDataSource() {
        BasicDataSource d = new BasicDataSource();

        d.setDriverClassName("org.h2.Driver");
        d.setUsername("sa");
        d.setPassword("");
        d.setUrl(calculateDBUrl(getWorkingDirectory()));

        this.dataSource = d;
    }
View Full Code Here

    public void setUp() {
        //String connURL = "jdbc:log4jdbc:derby:target/REG1_DB";
        //String connURL = "jdbc:derby:target/REG1_DB";
        String connURL = "jdbc:mysql://localhost:3306/registry1";
        BasicDataSource ds = new BasicDataSource();
        //ds.setUrl(connURL + ";");
        //ds.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl(connURL);
        ds.setUsername("root");
        ds.setPassword("password");



//        ds.setMaxWait(1000*60*2);

        ds.setMaxActive(150);
        ds.setMaxIdle(1000*60*2);
        ds.setMinIdle(5);
        //ds.setDriverClassName("net.sf.log4jdbc.DriverSpy");


        //DerbyDatabaseCreator creator = new DerbyDatabaseCreator(ds);
        DatabaseCreator creator = new DatabaseCreator(ds);
View Full Code Here

TOP

Related Classes of org.apache.commons.dbcp.BasicDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.