Example usage for org.apache.commons.dbcp2 BasicDataSource getUrl

List of usage examples for org.apache.commons.dbcp2 BasicDataSource getUrl

Introduction

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

Prototype

@Override
public synchronized String getUrl() 

Source Link

Document

Returns the JDBC connection #url property.

Usage

From source file:de.micromata.genome.util.runtime.jndi.JndiDumper.java

public static void dumpJndiBinding(InitialContext initialContext, String parentKey, Binding binding,
        StringBuilder sb, String indent) throws NamingException {
    try {/*  w  w w. ja  v  a 2  s.  c om*/
        Object obj = binding.getObject();
        ClassLoader bindClassLoader = obj.getClass().getClassLoader();
        sb.append(indent).append(parentKey + "/" + binding.getName()).append("(")
                .append(System.identityHashCode(binding)).append(", cl: ").append(bindClassLoader).append("): ")
                .append(binding.toString());
        if (obj instanceof Context) {

            sb.append("\n");
            Context ctx = (Context) obj;
            indent += "  ";
            NamingEnumeration<Binding> bindings = ctx.listBindings("");
            while (bindings.hasMore()) {
                Binding cbinding = bindings.next();
                dumpJndiBinding(initialContext, parentKey + "/" + binding.getName(), cbinding, sb, indent);
            }
        } else if (obj instanceof Reference) {
            Reference ref = (Reference) obj;
            //      binding.get
            //      ref.
            sb.append("\n");
        } else if (obj instanceof Session) {
            Session sess = (Session) obj;
            sb.append("\n");
        } else if (obj instanceof DataSource) {
            DataSource ds = (DataSource) obj;
            if (ds instanceof BasicDataSource) {
                BasicDataSource dbds = (BasicDataSource) ds;
                sb.append(" '" + dbds.getUrl() + "'");
            }
            sb.append("\n");
        } else if (obj != null) {
            Class<? extends Object> clazz = obj.getClass();

            sb.append(" unkown type: " + clazz);
            sb.append("\n");
        }
    } catch (NamingException ex) {
        sb.append("Error access binding: " + binding.getName() + ": " + ex.getMessage());
    }
}

From source file:de.micromata.genome.util.runtime.jndi.SimpleNamingContextBuilder.java

/**
 * Jndi object to string./*  w  w w  .  j  av a2  s  .  co m*/
 *
 * @param obj the obj
 * @return the string
 */
public static String jndiObjectToString(Object obj) {
    if (obj instanceof BasicDataSource) {
        BasicDataSource bds = (BasicDataSource) obj;
        return "BasicDataSource: " + bds.getUsername() + "@" + bds.getUrl();
    } else {
        return Objects.toString(obj, StringUtils.EMPTY);
    }
}

From source file:com.bc.fiduceo.TestUtil.java

private static void convertToProperties(Properties properties, BasicDataSource datasource) {
    properties.setProperty("driverClassName", datasource.getDriverClassName());
    properties.setProperty("url", datasource.getUrl());
    properties.setProperty("username", datasource.getUsername());
    properties.setProperty("password", datasource.getPassword());
}

From source file:com.ebay.pulsar.analytics.dao.DBFactory.java

public static void setDs(BasicDataSource datasource) {
    ///*w  w w.ja  v a2  s . co m*/
    // First, we'll create a ConnectionFactory that the
    // pool will use to create Connections.
    // We'll use the DriverManagerConnectionFactory,
    // using the connect string passed in the command line
    // arguments.
    //
    try {
        Class.forName(datasource.getDriverClassName());
    } catch (ClassNotFoundException e) {
    }
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(datasource.getUrl(),
            datasource.getUsername(), datasource.getPassword());

    //
    // Next we'll create the PoolableConnectionFactory, which wraps
    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    //
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
            null);

    //
    // Now we'll need a ObjectPool that serves as the
    // actual pool of connections.
    //
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory);

    // Set the factory's pool property to the owning pool
    poolableConnectionFactory.setPool(connectionPool);

    //
    // Finally, we create the PoolingDriver itself,
    // passing in the object pool we created.
    //
    PoolingDataSource<PoolableConnection> poolingDS = new PoolingDataSource<>(connectionPool);
    ds = poolingDS;
}

From source file:au.com.breakpoint.hedron.core.context.JdbcConnectionCachingDataSource.java

@Override
public String toString() {
    String s;/*from   w  ww  .  j  a  va2  s .  co  m*/
    if (m_realDataSource instanceof BasicDataSource) {
        final BasicDataSource bds = (BasicDataSource) m_realDataSource;
        s = String.format("[%s, %s]", bds.getUsername(), bds.getUrl());
    } else {
        s = String.format("[%s]", m_realDataSource.toString());
    }
    return s;
}

From source file:com.bc.fiduceo.db.Storage.java

private Driver createDriver(BasicDataSource dataSource) {
    // ensure all dates are interpreted as UTC
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

    final String dbUrl = dataSource.getUrl().toLowerCase();

    final DriverUtils syDriverUtils = new DriverUtils();
    return syDriverUtils.getDriver(dbUrl);
}

From source file:com.thoughtworks.go.server.database.H2DatabaseTest.java

@Test
void shouldUseMVCCWhenRunning() throws Exception {
    h2Database.startDatabase();/*  w  w  w.  j  ava2  s.c o  m*/
    h2Database.upgrade();

    BasicDataSource dataSource = h2Database.createDataSource();
    assertThat(dataSource.getUrl(), containsString("MVCC=TRUE"));
}

From source file:com.bc.fiduceo.db.DatabaseConfigTest.java

@Test
public void testLoadAndGetDataSource() throws IOException {
    final File databaseConfigFile = TestUtil.createFileInTestDir("database.properties");

    final PrintWriter printWriter = new PrintWriter(databaseConfigFile);
    printWriter.write("driverClassName = driver-class\n");
    printWriter.write("url = database-url\n");
    printWriter.write("username = user-name\n");
    printWriter.write("password = pass-word");
    printWriter.close();/*from   w ww .j  a  v  a 2s . c o m*/

    databaseConfig.loadFrom(testDirectory);

    final BasicDataSource dataSource = databaseConfig.getDataSource();
    assertNotNull(dataSource);
    assertEquals("driver-class", dataSource.getDriverClassName());
    assertEquals("database-url", dataSource.getUrl());
    assertEquals("user-name", dataSource.getUsername());
    assertEquals("pass-word", dataSource.getPassword());
}

From source file:com.bc.fiduceo.db.Storage.java

Storage(BasicDataSource dataSource, GeometryFactory geometryFactory) throws SQLException {
    driver = createDriver(dataSource);/*ww w  .  ja va  2 s  . c o m*/
    if (driver == null) {
        throw new IllegalArgumentException(
                "No database driver registered for URL `" + dataSource.getUrl() + "`");
    }

    driver.setGeometryFactory(geometryFactory);

    driver.open(dataSource);
}

From source file:com.bc.fiduceo.db.MongoDbDriver.java

@Override
public void open(BasicDataSource dataSource) throws SQLException {
    final String address = parseAddress(dataSource.getUrl());
    final String port = parsePort(dataSource.getUrl());
    final ServerAddress serverAddress = new ServerAddress(address, Integer.parseInt(port));

    final String username = dataSource.getUsername();
    final String password = dataSource.getPassword();
    if (StringUtils.isNotNullAndNotEmpty(password) && StringUtils.isNotNullAndNotEmpty(username)) {
        final MongoCredential credential = MongoCredential.createCredential(username, DATABASE_NAME,
                password.toCharArray());
        final List<MongoCredential> credentialsList = new ArrayList<>();
        credentialsList.add(credential);
        mongoClient = new MongoClient(serverAddress, credentialsList);
    } else {//  www .  j a v  a  2  s .  co  m
        mongoClient = new MongoClient(serverAddress);
    }
    database = mongoClient.getDatabase(DATABASE_NAME);
}