List of usage examples for org.apache.commons.dbcp2 BasicDataSource getPassword
@Override
public String getPassword()
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 w w w. j a va 2 s . c om*/ // 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: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();/* w w w. jav a 2s. 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 w w w .j a v a2 s. c o 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 {/*from www . j a v a2s.com*/ mongoClient = new MongoClient(serverAddress); } database = mongoClient.getDatabase(DATABASE_NAME); }