List of usage examples for org.apache.commons.dbcp BasicDataSource setUrl
public synchronized void setUrl(String url)
Sets the #url .
Note: this method currently has no effect once the pool has been initialized.
From source file:io.syndesis.connector.sql.stored.SqlStoredConnectorComponentTest.java
@Test public void camelConnectorTest() throws Exception { BasicDataSource ds = new BasicDataSource(); ds.setUsername(properties.getProperty("sql-stored-connector.user")); ds.setPassword(properties.getProperty("sql-stored-connector.password")); ds.setUrl(properties.getProperty("sql-stored-connector.url")); SimpleRegistry registry = new SimpleRegistry(); registry.put("dataSource", ds); CamelContext context = new DefaultCamelContext(registry); String jsonBody = "{\"a\":20,\"b\":30}"; CountDownLatch latch = new CountDownLatch(1); final Result result = new Result(); try {//from w w w. ja va2 s. c o m context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("timer://myTimer?period=2000").setBody().constant(jsonBody).to( "sql-stored-connector:DEMO_ADD( INTEGER ${body[a]}, INTEGER ${body[b]}, OUT INTEGER c)") .process(new Processor() { @Override public void process(Exchange exchange) throws Exception { String jsonBean = (String) exchange.getIn().getBody(); result.setResult(jsonBean); latch.countDown(); } }); } }); context.start(); latch.await(5l, TimeUnit.SECONDS); Assert.assertEquals("{\"c\":50}", result.getJsonBean()); } finally { context.stop(); } }
From source file:com.dangdang.ddframe.job.statistics.rdb.StatisticRdbRepositoryTest.java
@Before public void setup() throws SQLException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(org.h2.Driver.class.getName()); dataSource.setUrl("jdbc:h2:mem:"); dataSource.setUsername("sa"); dataSource.setPassword(""); repository = new StatisticRdbRepository(dataSource); }
From source file:mx.com.pixup.portal.dao.ArchivoBaseGenerateDaoJdbc.java
public ArchivoBaseGenerateDaoJdbc() throws IOException { BasicDataSource dataSource = new BasicDataSource(); //seccion de la DB dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUsername("root"); dataSource.setPassword("admin"); //dataSource.setPassword("mysqlroot"); dataSource.setUrl("jdbc:mysql://localhost:3306/pixup"); this.dataSource = dataSource; //seccion XML }
From source file:mx.com.pixup.portal.dao.ArchivoBaseParserDaoJdbc.java
public ArchivoBaseParserDaoJdbc() throws IOException { BasicDataSource dataSource = new BasicDataSource(); //seccion de la DB dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUsername("root"); dataSource.setPassword("admin"); //dataSource.setPassword("mysqlroot"); dataSource.setUrl("jdbc:mysql://localhost:3306/pixup"); this.dataSource = dataSource; //seccion generate XML }
From source file:com.googlesource.gerrit.plugins.verifystatus.server.schema.CiDataSourceProvider.java
private DataSource open(Context context, CiDataSourceType dst) { // ConfigSection dbs = new ConfigSection(cfg, "database"); String driver = config.getString("driver"); if (Strings.isNullOrEmpty(driver)) { driver = dst.getDriver();//from ww w . j ava 2s.c om } String url = config.getString("dbUrl"); if (Strings.isNullOrEmpty(url)) { url = dst.getUrl(); } String username = config.getString("username"); String password = config.getString("password"); String interceptor = config.getString("dataSourceInterceptorClass"); boolean usePool; if (context == Context.SINGLE_USER) { usePool = false; } else { usePool = config.getBoolean("connectionpool", dst.usePool()); } if (usePool) { final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUrl(url); if (username != null && !username.isEmpty()) { ds.setUsername(username); } if (password != null && !password.isEmpty()) { ds.setPassword(password); } ds.setMaxActive(config.getInt("poollimit", DEFAULT_POOL_LIMIT)); ds.setMinIdle(config.getInt("poolminidle", 4)); ds.setMaxIdle(config.getInt("poolmaxidle", 4)); String valueString = config.getString("poolmaxwait"); if (Strings.isNullOrEmpty(valueString)) { ds.setMaxWait(MILLISECONDS.convert(30, SECONDS)); } else { ds.setMaxWait(ConfigUtil.getTimeUnit(valueString, MILLISECONDS.convert(30, SECONDS), MILLISECONDS)); } ds.setInitialSize(ds.getMinIdle()); exportPoolMetrics(ds); return intercept(interceptor, ds); } // Don't use the connection pool. try { Properties p = new Properties(); p.setProperty("driver", driver); p.setProperty("url", url); if (username != null) { p.setProperty("user", username); } if (password != null) { p.setProperty("password", password); } return intercept(interceptor, new SimpleDataSource(p)); } catch (SQLException se) { throw new ProvisionException("Database unavailable", se); } }
From source file:io.syndesis.connector.sql.stored.SqlStoredStartConnectorComponentTest.java
@Test public void camelConnectorTest() throws Exception { BasicDataSource ds = new BasicDataSource(); ds.setUsername(properties.getProperty("sql-stored-start-connector.user")); ds.setPassword(properties.getProperty("sql-stored-start-connector.password")); ds.setUrl(properties.getProperty("sql-stored-start-connector.url")); SimpleRegistry registry = new SimpleRegistry(); registry.put("dataSource", ds); CamelContext context = new DefaultCamelContext(registry); CountDownLatch latch = new CountDownLatch(1); final Result result = new Result(); try {// w ww .j a v a 2 s. c o m context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("sql-stored-start-connector:DEMO_OUT( OUT INTEGER c)").process(new Processor() { @Override public void process(Exchange exchange) throws Exception { String jsonBean = (String) exchange.getIn().getBody(); result.setResult(jsonBean); latch.countDown(); } }).to("stream:out"); } }); context.start(); latch.await(5l, TimeUnit.SECONDS); Assert.assertEquals("{\"c\":60}", result.getJsonBean()); } finally { context.stop(); } }
From source file:cn.edu.seu.cose.jellyjolly.model.dao.jdbc.mysql.MysqlConnectionFactory.java
private void initDataSource() throws IOException { BasicDataSource ds = new BasicDataSource(); Properties cfgpp = new Properties(); cfgpp.load(MysqlConnectionFactory.class.getResourceAsStream("dbcp.jdbc.properties")); ds.setDriverClassName(cfgpp.getProperty("jdbc.driverClassName")); ds.setUrl(cfgpp.getProperty("jdbc.url")); ds.setUsername(cfgpp.getProperty("jdbc.username")); ds.setPassword(cfgpp.getProperty("jdbc.password")); dataSource = ds;//from www.ja va2 s. co m }
From source file:com.googlesource.gerrit.plugins.ci.server.schema.CiDataSourceProvider.java
private DataSource open(Context context, CiDataSourceType dst) { //ConfigSection dbs = new ConfigSection(cfg, "database"); String driver = config.getString("driver"); if (Strings.isNullOrEmpty(driver)) { driver = dst.getDriver();/*from w w w . j a v a 2 s. c o m*/ } String url = config.getString("dbUrl"); if (Strings.isNullOrEmpty(url)) { url = dst.getUrl(); } String username = config.getString("username"); String password = config.getString("password"); String interceptor = config.getString("dataSourceInterceptorClass"); boolean usePool; if (context == Context.SINGLE_USER) { usePool = false; } else { usePool = config.getBoolean("connectionpool", dst.usePool()); } if (usePool) { final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUrl(url); if (username != null && !username.isEmpty()) { ds.setUsername(username); } if (password != null && !password.isEmpty()) { ds.setPassword(password); } ds.setMaxActive(config.getInt("poollimit", DEFAULT_POOL_LIMIT)); ds.setMinIdle(config.getInt("poolminidle", 4)); ds.setMaxIdle(config.getInt("poolmaxidle", 4)); String valueString = config.getString("poolmaxwait"); if (Strings.isNullOrEmpty(valueString)) { ds.setMaxWait(MILLISECONDS.convert(30, SECONDS)); } else { ds.setMaxWait(ConfigUtil.getTimeUnit(valueString, MILLISECONDS.convert(30, SECONDS), MILLISECONDS)); } ds.setInitialSize(ds.getMinIdle()); exportPoolMetrics(ds); return intercept(interceptor, ds); } else { // Don't use the connection pool. // try { Properties p = new Properties(); p.setProperty("driver", driver); p.setProperty("url", url); if (username != null) { p.setProperty("user", username); } if (password != null) { p.setProperty("password", password); } return intercept(interceptor, new SimpleDataSource(p)); } catch (SQLException se) { throw new ProvisionException("Database unavailable", se); } } }
From source file:calculus.backend.JpaConfig.java
@Bean public DataSource dataSource() { loadProperties();/* w w w .j a v a 2s . c o m*/ BasicDataSource driver = new BasicDataSource(); driver.setDriverClassName(this.driver); driver.setUrl(this.url); driver.setUsername(this.user); driver.setPassword(this.pass); driver.setMaxIdle(poolSize); driver.setMaxActive(poolSize); return driver; }
From source file:de.langmi.spring.batch.examples.readers.support.CompositeCursorItemReaderTest.java
/** * Create a HSQLDB in-memory based datasource. * * @param url/* w w w . ja v a2 s. c om*/ * @return */ private DataSource createDataSource(final String url) { // DataSource Setup with apache commons BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setUrl(url); dataSource.setUsername("sa"); dataSource.setPassword(""); return dataSource; }