List of usage examples for org.apache.commons.dbcp BasicDataSource getUrl
public synchronized String getUrl()
From source file:org.apache.ddlutils.task.CreateDatabaseCommand.java
/** * {@inheritDoc}/*from w w w . j ava 2 s. c om*/ */ public void execute(DatabaseTaskBase task, Database model) throws BuildException { BasicDataSource dataSource = getDataSource(); if (dataSource == null) { throw new BuildException("No database specified."); } Platform platform = getPlatform(); try { platform.createDatabase(dataSource.getDriverClassName(), dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword(), getFilteredParameters(platform.getName())); _log.info("Created database"); } catch (UnsupportedOperationException ex) { _log.error("Database platform " + platform.getName() + " does not support database creation " + "via JDBC or there was an error while creating it.", ex); } catch (Exception ex) { handleException(ex, ex.getMessage()); } }
From source file:org.apache.ddlutils.task.DropDatabaseCommand.java
/** * {@inheritDoc}//from w w w .j a va 2 s .com */ public void execute(DatabaseTaskBase task, Database model) throws BuildException { BasicDataSource dataSource = getDataSource(); if (dataSource == null) { throw new BuildException("No database specified."); } Platform platform = getPlatform(); try { platform.dropDatabase(dataSource.getDriverClassName(), dataSource.getUrl(), dataSource.getUsername(), dataSource.getPassword()); _log.info("Dropped database"); } catch (UnsupportedOperationException ex) { _log.error("Database platform " + platform.getName() + " does not support database dropping via JDBC", ex); } catch (Exception ex) { handleException(ex, ex.getMessage()); } }
From source file:org.apache.kylin.query.QueryDataSourceTest.java
@Test public void testCreateDataSourceWithProps() { KylinConfig config = KylinConfig.getInstanceFromEnv(); Properties props = new Properties(); props.setProperty("username", "ADMIN"); props.setProperty("password", "KYLIN"); BasicDataSource ds = (BasicDataSource) QueryDataSource.create("default", config, props); Assert.assertNotNull(ds);//from w w w. ja va2s.c o m Assert.assertTrue(ds instanceof BasicDataSource); Assert.assertTrue(ds.getUrl().startsWith("jdbc:calcite:model=")); Assert.assertEquals(ds.getDriverClassName(), Driver.class.getName()); Assert.assertEquals(ds.getUsername(), "ADMIN"); Assert.assertEquals(ds.getPassword(), "KYLIN"); }
From source file:org.apache.openejb.arquillian.openejb.BindingInJavaGlobalTest.java
@Test public void checkSimpleBiding() throws NamingException { final BasicDataSource ds = (BasicDataSource) new InitialContext().lookup("java:global/db"); assertEquals("jdbc:hsqldb:mem:global", ds.getUrl()); }
From source file:org.apache.openejb.assembler.classic.OpenEJBXmlByModuleTest.java
@Test public void test() throws Exception { assertNotNull(bean.datasource());//ww w . j a v a2s.co m assertTrue(bean.datasource() instanceof BasicDataSource); final BasicDataSource ds = (BasicDataSource) bean.datasource(); assertEquals("org.hsqldb.jdbcDriver", ds.getDriverClassName()); assertEquals("not:used:url", ds.getUrl()); assertEquals("foo", ds.getUsername()); assertEquals("bar", ds.getPassword()); assertNotNull(bean.resource()); assertEquals("ok", bean.resource().attr); }
From source file:org.apache.openejb.resource.jdbc.HsqldbDataSourcePlugin.java
public void configure(BasicDataSource dataSource) { String url = dataSource.getUrl(); url = toAbsolutePath(url); dataSource.setUrl(url); }
From source file:org.apache.openejb.resource.jdbc.InstantdbDataSourcePlugin.java
public void configure(BasicDataSource dataSource) { String jdbcUrl = dataSource.getUrl(); // jdbc:idb:conf/instantdb.properties String prefix = "jdbc:idb:"; int index = jdbcUrl.indexOf(prefix); if (index == -1) { return;/* ww w .j a v a 2 s . c o m*/ } String confFile = jdbcUrl.substring(index + prefix.length()); File base = SystemInstance.get().getBase().getDirectory(); File file = new File(base, confFile); if (file.exists()) { // The instantdb properties file is there, we're good return; } if (!file.getParentFile().exists()) { // The directory the instantdb properties file should live in // doesn't exist, don't bother return; } FileOutputStream out = null; try { ResourceFinder finder = new ResourceFinder(""); String defaultProperties = finder.findString("default.instantdb.properties"); out = new FileOutputStream(file); out.write(defaultProperties.getBytes()); out.flush(); } catch (IOException e) { // TODO; Handle this e.printStackTrace(); } finally { try { out.close(); } catch (IOException e) { } } }
From source file:org.geotools.data.h2.H2DataStoreFactoryTest.java
public void testCreateDataStoreMVCC() throws Exception { Map clonedParams = new HashMap(params); clonedParams.put(H2DataStoreFactory.MVCC.key, true); JDBCDataStore ds = factory.createDataStore(clonedParams); assertNotNull(ds);/*ww w . ja v a2s . c o m*/ final DataSource source = ds.getDataSource(); assertNotNull(source); final DataSource wrapped = source.unwrap(DataSource.class); assertNotNull(wrapped); if (wrapped instanceof BasicDataSource) { final BasicDataSource basicSource = (BasicDataSource) wrapped; final String url = basicSource.getUrl(); assertTrue(url.contains("MVCC=true")); } }
From source file:org.jsconf.core.sample.Sample00.java
@Test public void test() { BasicDataSource basic = (BasicDataSource) this.datasource; Assert.assertEquals("jdbc:mysql://localhost:3306/test", basic.getUrl()); Assert.assertEquals("com.mysql.jdbc.Driver", basic.getDriverClassName()); }
From source file:org.jumpmind.symmetric.DbSqlCommand.java
@Override protected boolean executeWithOptions(CommandLine line) throws Exception { BasicDataSource basicDataSource = getDatabasePlatform(false).getDataSource(); String url = basicDataSource.getUrl(); String user = basicDataSource.getUsername(); String password = basicDataSource.getPassword(); String driver = basicDataSource.getDriverClassName(); Shell shell = new Shell(); if (line.hasOption(OPTION_SQL)) { String sql = line.getOptionValue(OPTION_SQL); shell.runTool("-url", url, "-user", user, "-password", password, "-driver", driver, "-sql", sql); } else {/*from w w w. j a v a 2 s . com*/ shell.runTool("-url", url, "-user", user, "-password", password, "-driver", driver); } return true; }