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

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

Introduction

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

Prototype

public synchronized void setUrl(String url) 

Source Link

Document

Sets the #url .

Note: this method currently has no effect once the pool has been initialized.

Usage

From source file:com.dangdang.ddframe.job.event.rdb.JobEventRdbSearchTest.java

@BeforeClass
public static void setUpClass() throws SQLException {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(org.h2.Driver.class.getName());
    dataSource.setUrl("jdbc:h2:mem:");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    storage = new JobEventRdbStorage(dataSource);
    repository = new JobEventRdbSearch(dataSource);
    initStorage();/*from www  .  ja  va  2s.c o  m*/
}

From source file:mx.com.pixup.portal.db.DBConecta.java

public static BasicDataSource getDataSource() {
    DBConecta db = DBConecta.getInstance();

    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(db.dbProp.getProperty("dataSource.className"));
    dataSource.setUsername(db.dbProp.getProperty("dataSource.username"));
    dataSource.setPassword(db.dbProp.getProperty("dataSource.password"));
    dataSource.setUrl(db.dbProp.getProperty("dataSource.url"));

    return dataSource;
}

From source file:com.ianzepp.logging.jms.service.BasicDaoTest.java

/**
 * TODO Method description for <code>setUpBeforeClass()</code>
 * //from ww w.  ja v a2  s  . c  o  m
 * @throws SQLException
 */
@BeforeClass
public static void setUpBeforeClass() throws SQLException {
    // Create the dao mapping
    namedQueries = new HashMap<String, String>();
    namedQueries.put("FindEventById", "src/main/resources/com.ianzepp.logging.jms.service.FindEventById.sql");
    namedQueries.put("InsertEvent", "src/main/resources/com.ianzepp.logging.jms.service.InsertEvent.sql");
    namedQueries.put("InsertException",
            "src/main/resources/com.ianzepp.logging.jms.service.InsertEventException.sql");
    namedQueries.put("InsertLocation",
            "src/main/resources/com.ianzepp.logging.jms.service.InsertEventLocation.sql");
    namedQueries.put("InsertUserRequest",
            "src/main/resources/com.ianzepp.logging.jms.service.InsertEventUserRequest.sql");

    // Create and save the datasource
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(DB_DRIVER);
    basicDataSource.setUrl(DB_URI);
    basicDataSource.setUsername(DB_USERNAME);
    basicDataSource.setPassword(DB_PASSWORD);
    dataSource = 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  a  v a2  s  .  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:ReaderManagerImplTest.java

private static DataSource prepareDataSource() throws SQLException {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl("jdbc:derby:memory:libraryProject;create=true");
    return dataSource;
}

From source file:io.apiman.manager.test.server.ManagerApiTestServer.java

/**
 * Creates an in-memory datasource./*from   w  ww. j av  a 2  s.  com*/
 * @throws SQLException
 */
private static BasicDataSource createInMemoryDatasource() throws SQLException {
    System.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); //$NON-NLS-1$ //$NON-NLS-2$
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(Driver.class.getName());
    ds.setUsername("sa"); //$NON-NLS-1$
    ds.setPassword(""); //$NON-NLS-1$
    ds.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"); //$NON-NLS-1$
    Connection connection = ds.getConnection();
    connection.close();
    System.out.println("DataSource created and bound to JNDI."); //$NON-NLS-1$
    return ds;
}

From source file:cz.muni.fi.pv168.CarManagerTest.java

private static DataSource prepareDataSource() throws SQLException {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl("jdbc:derby:memory:CarRentalDB;create=true");
    return ds;//w  w w .j av a2 s .co  m
}

From source file:io.apiman.gateway.engine.jdbc.JdbcMetricsTest.java

/**
 * Creates an in-memory datasource.//w w w.j a va  2 s  .  c  o m
 * @throws SQLException
 */
private static BasicDataSource createInMemoryDatasource() throws Exception {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(Driver.class.getName());
    ds.setUsername("sa");
    ds.setPassword("");
    ds.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    Connection connection = ds.getConnection();
    connection.setAutoCommit(true);
    initDB(connection);
    connection.close();
    return ds;
}

From source file:com.cws.esolutions.core.listeners.CoreServiceInitializer.java

/**
 * Initializes the core service in a standalone mode - used for applications outside of a container or when
 * run as a standalone jar./* w  w  w  . ja  va  2 s .com*/
 *
 * @param configFile - The service configuration file to utilize
 * @param logConfig - The logging configuration file to utilize
 * @param loadSecurity - Flag to start security
 * @param startConnections - Flag to start connections
 * @throws CoreServiceException @{link com.cws.esolutions.core.exception.CoreServiceException}
 * if an exception occurs during initialization
 */
public static void initializeService(final String configFile, final String logConfig,
        final boolean loadSecurity, final boolean startConnections) throws CoreServiceException {
    URL xmlURL = null;
    JAXBContext context = null;
    Unmarshaller marshaller = null;
    SecurityConfig secConfig = null;
    CoreConfigurationData configData = null;
    SecurityConfigurationData secConfigData = null;

    if (loadSecurity) {
        secConfigData = SecurityServiceBean.getInstance().getConfigData();
        secConfig = secConfigData.getSecurityConfig();
    }

    final String serviceConfig = (StringUtils.isBlank(configFile)) ? System.getProperty("coreConfigFile")
            : configFile;
    final String loggingConfig = (StringUtils.isBlank(logConfig)) ? System.getProperty("coreLogConfig")
            : logConfig;

    try {
        try {
            DOMConfigurator.configure(Loader.getResource(loggingConfig));
        } catch (NullPointerException npx) {
            try {
                DOMConfigurator.configure(FileUtils.getFile(loggingConfig).toURI().toURL());
            } catch (NullPointerException npx1) {
                System.err.println("Unable to load logging configuration. No logging enabled!");
                System.err.println("");
                npx1.printStackTrace();
            }
        }

        xmlURL = CoreServiceInitializer.class.getClassLoader().getResource(serviceConfig);

        if (xmlURL == null) {
            // try loading from the filesystem
            xmlURL = FileUtils.getFile(configFile).toURI().toURL();
        }

        context = JAXBContext.newInstance(CoreConfigurationData.class);
        marshaller = context.createUnmarshaller();
        configData = (CoreConfigurationData) marshaller.unmarshal(xmlURL);

        CoreServiceInitializer.appBean.setConfigData(configData);

        if (startConnections) {
            Map<String, DataSource> dsMap = CoreServiceInitializer.appBean.getDataSources();

            if (DEBUG) {
                DEBUGGER.debug("dsMap: {}", dsMap);
            }

            if (dsMap == null) {
                dsMap = new HashMap<String, DataSource>();
            }

            for (DataSourceManager mgr : configData.getResourceConfig().getDsManager()) {
                if (!(dsMap.containsKey(mgr.getDsName()))) {
                    StringBuilder sBuilder = new StringBuilder()
                            .append("connectTimeout=" + mgr.getConnectTimeout() + ";")
                            .append("socketTimeout=" + mgr.getConnectTimeout() + ";")
                            .append("autoReconnect=" + mgr.getAutoReconnect() + ";")
                            .append("zeroDateTimeBehavior=convertToNull");

                    if (DEBUG) {
                        DEBUGGER.debug("StringBuilder: {}", sBuilder);
                    }

                    BasicDataSource dataSource = new BasicDataSource();
                    dataSource.setDriverClassName(mgr.getDriver());
                    dataSource.setUrl(mgr.getDataSource());
                    dataSource.setUsername(mgr.getDsUser());
                    dataSource.setConnectionProperties(sBuilder.toString());
                    dataSource.setPassword(PasswordUtils.decryptText(mgr.getDsPass(), mgr.getSalt(),
                            secConfig.getSecretAlgorithm(), secConfig.getIterations(), secConfig.getKeyBits(),
                            secConfig.getEncryptionAlgorithm(), secConfig.getEncryptionInstance(),
                            configData.getAppConfig().getEncoding()));
                    if (DEBUG) {
                        DEBUGGER.debug("BasicDataSource: {}", dataSource);
                    }

                    dsMap.put(mgr.getDsName(), dataSource);
                }
            }

            if (DEBUG) {
                DEBUGGER.debug("dsMap: {}", dsMap);
            }

            CoreServiceInitializer.appBean.setDataSources(dsMap);
        }
    } catch (JAXBException jx) {
        jx.printStackTrace();
        throw new CoreServiceException(jx.getMessage(), jx);
    } catch (MalformedURLException mux) {
        mux.printStackTrace();
        throw new CoreServiceException(mux.getMessage(), mux);
    }
}

From source file:contactsdirectory.backend.PersonManagerImplTest.java

private static DataSource prepareDataSource() throws SQLException {
    BasicDataSource ds = new BasicDataSource();
    //we will use in memory database
    ds.setUrl("jdbc:derby:memory:personmgr-test;create=true");
    return ds;//from w  ww  .  j  a v  a2s.c om
}