List of usage examples for org.apache.commons.dbcp2 BasicDataSource getDriverClassName
@Override public synchronized String getDriverClassName()
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 . com // 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 ww. j av a 2 s.c om 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 {// ww w .ja 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:org.siphon.jssql.SqlExecutor.java
public SqlExecutor(DataSource dataSource, ScriptEngine jsEngine, org.siphon.common.js.JSON json) throws ScriptException { this.dataSource = dataSource; this.jsEngine = jsEngine; jsTypeUtil = new JsTypeUtil(jsEngine); this.JSON = json; if (this.dataSource instanceof org.apache.commons.dbcp2.BasicDataSource) { BasicDataSource bds = (BasicDataSource) this.dataSource; this.driverClass = bds.getDriverClassName(); if ("org.postgresql.Driver".equals(this.driverClass)) { this.postgreSQL = true; } else if ("oracle.jdbc.driver.OracleDriver".equals(this.driverClass)) { this.oracle = true; } else if (this.driverClass.contains("mysql")) { this.mySql = true; }//w w w . j av a2 s. com } }