List of usage examples for org.apache.commons.dbcp2 BasicDataSource getUsername
@Override
public String getUsername()
From source file:de.micromata.genome.util.runtime.jndi.SimpleNamingContextBuilder.java
/** * Jndi object to string.// w w w . ja va 2s. 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) { ///*from ww w.j ava 2 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 w w .j a va 2s . c om*/ 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.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 w w .ja va2 s.co 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.AbstractDriver.java
@Override public void open(BasicDataSource dataSource) throws SQLException { try {/*from www .j a v a2 s . co m*/ final java.sql.Driver driverClass = (java.sql.Driver) Class.forName(dataSource.getDriverClassName()) .newInstance(); DriverManager.registerDriver(driverClass); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new SQLException(e.getMessage()); } connection = DriverManager.getConnection(dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword()); }
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 {/* w w w. j ava2 s. c om*/ mongoClient = new MongoClient(serverAddress); } database = mongoClient.getDatabase(DATABASE_NAME); }
From source file:psiprobe.beans.Dbcp2DatasourceAccessor.java
@Override public DataSourceInfo getInfo(Object resource) throws Exception { DataSourceInfo dataSourceInfo = null; if (canMap(resource)) { BasicDataSource source = (BasicDataSource) resource; dataSourceInfo = new DataSourceInfo(); dataSourceInfo.setBusyConnections(source.getNumActive()); dataSourceInfo.setEstablishedConnections(source.getNumIdle() + source.getNumActive()); dataSourceInfo.setMaxConnections(source.getMaxTotal()); dataSourceInfo.setJdbcUrl(source.getUrl()); dataSourceInfo.setUsername(source.getUsername()); dataSourceInfo.setResettable(false); dataSourceInfo.setType("commons-dbcp2"); }/*from w w w.j a v a 2 s .com*/ return dataSourceInfo; }