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:org.wso2.carbon.user.core.jdbc.AdvancedJDBCRealmTest.java
public void initRealmStuff() throws Exception { String dbFolder = "target/advjdbctest"; if ((new File(dbFolder)).exists()) { deleteDir(new File(dbFolder)); }/* www. ja va 2s . c o m*/ BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(UserCoreTestConstants.DB_DRIVER); ds.setUrl(TEST_URL); DatabaseCreator creator = new DatabaseCreator(ds); creator.createRegistryDatabase(); realm = new DefaultRealm(); InputStream inStream = this.getClass().getClassLoader().getResource(JDBCRealmTest.JDBC_TEST_USERMGT_XML) .openStream(); RealmConfiguration realmConfig = TestRealmConfigBuilder.buildRealmConfigWithJDBCConnectionUrl(inStream, TEST_URL); realm.init(realmConfig, ClaimTestUtil.getClaimTestData(), ClaimTestUtil.getProfileTestData(), MultitenantConstants.SUPER_TENANT_ID); }
From source file:org.wso2.carbon.user.core.jdbc.AdvancedReadOnlyJDBCRealmTest.java
public void initRealmStuff() throws Exception { String dbFolder = "target/advjdbcrotest"; if ((new File(dbFolder)).exists()) { deleteDir(new File(dbFolder)); }//ww w .java 2 s . c o m BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(UserCoreTestConstants.DB_DRIVER); ds.setUrl("jdbc:h2:target/advjdbcrotest/CARBON_TEST"); DatabaseCreator creator = new DatabaseCreator(ds); creator.createRegistryDatabase(); this.addIntialData(ds); RealmConfigXMLProcessor builder = new RealmConfigXMLProcessor(); InputStream inStream = this.getClass().getClassLoader().getResource("adv-jdbc-readonly-test.xml") .openStream(); RealmConfiguration realmConfig = builder.buildRealmConfiguration(inStream); inStream.close(); realm = new DefaultRealm(); realm.init(realmConfig, ClaimTestUtil.getClaimTestData(), ClaimTestUtil.getProfileTestData(), 0); assertTrue(realm.getUserStoreManager().isExistingRole("adminx")); }
From source file:org.wso2.carbon.user.core.jdbc.JDBCRealmTest.java
public void initRealmStuff(String dbUrl) throws Exception { String dbFolder = "target/BasicJDBCDatabaseTest"; if ((new File(dbFolder)).exists()) { deleteDir(new File(dbFolder)); }// ww w.ja va2 s . c o m BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(UserCoreTestConstants.DB_DRIVER); ds.setUrl(dbUrl); DatabaseCreator creator = new DatabaseCreator(ds); creator.createRegistryDatabase(); realm = new DefaultRealm(); InputStream inStream = this.getClass().getClassLoader().getResource(JDBCRealmTest.JDBC_TEST_USERMGT_XML) .openStream(); RealmConfiguration realmConfig = TestRealmConfigBuilder.buildRealmConfigWithJDBCConnectionUrl(inStream, TEST_URL); realm.init(realmConfig, ClaimTestUtil.getClaimTestData(), ClaimTestUtil.getProfileTestData(), MultitenantConstants.SUPER_TENANT_ID); ds.close(); }
From source file:org.wso2.carbon.user.core.jdbc.JDBCRealmTest.java
public void testAuthorizationClearence() throws Exception { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(UserCoreTestConstants.DB_DRIVER); ds.setUrl("jdbc:h2:target/clear-resources/WSO2CARBON_DB_CLEAR"); ds.setUsername("wso2carbon"); ds.setPassword("wso2carbon"); realm = new DefaultRealm(); Map<String, Object> properties = new HashMap<String, Object>(); properties.put(UserCoreConstants.DATA_SOURCE, ds); RealmConfigXMLProcessor xmlProcessor = new RealmConfigXMLProcessor(); InputStream stream = new FileInputStream("target/clear-resources/user-mgt-clear.xml"); RealmConfiguration configuration = xmlProcessor.buildRealmConfiguration(stream); JDBCAuthorizationManager jdbcAuthnManager = new JDBCAuthorizationManager(configuration, properties, null, null, realm, 0);/*from ww w . j av a 2s .c o m*/ String[] roles = jdbcAuthnManager.getAllowedRolesForResource("/permission/admin", "ui.execute"); assertEquals(roles.length, 1); jdbcAuthnManager.clearPermissionTree(); //the tree should automatically be loaded on next call roles = jdbcAuthnManager.getAllowedRolesForResource("/permission/admin", "ui.execute"); assertEquals(roles.length, 1); }
From source file:org.wso2.carbon.user.core.jdbc.PermissionTest.java
public void initRealmStuff() throws Exception { String dbFolder = "target/PermissionTest"; if ((new File(dbFolder)).exists()) { deleteDir(new File(dbFolder)); }/*from w w w . j ava2 s . c o m*/ BasicDataSource ds = new BasicDataSource(); // ds.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver"); // ds.setUrl("jdbc:derby:target/databasetest/CARBON_TEST;create=true"); ds.setDriverClassName(UserCoreTestConstants.DB_DRIVER); ds.setUrl(TEST_URL); DatabaseCreator creator = new DatabaseCreator(ds); creator.createRegistryDatabase(); realm = new DefaultRealm(); InputStream inStream = this.getClass().getClassLoader().getResource(JDBCRealmTest.JDBC_TEST_USERMGT_XML) .openStream(); RealmConfiguration realmConfig = TestRealmConfigBuilder.buildRealmConfigWithJDBCConnectionUrl(inStream, TEST_URL); realm.init(realmConfig, ClaimTestUtil.getClaimTestData(), ClaimTestUtil.getProfileTestData(), 0); }
From source file:org.wso2.carbon.user.core.jdbc.ReadOnlyJDBCRealmTest.java
public void initRealmStuff() throws Exception { String dbFolder = "target/ReadOnlyTest"; if ((new File(dbFolder)).exists()) { deleteDir(new File(dbFolder)); }/* ww w . j av a2 s . c om*/ BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(UserCoreTestConstants.DB_DRIVER); ds.setUrl("jdbc:h2:target/ReadOnlyTest/CARBON_TEST"); DatabaseCreator creator = new DatabaseCreator(ds); creator.createRegistryDatabase(); this.addIntialData(ds); RealmConfigXMLProcessor builder = new RealmConfigXMLProcessor(); InputStream inStream = this.getClass().getClassLoader().getResource("jdbc-readonly-test.xml").openStream(); RealmConfiguration realmConfig = builder.buildRealmConfiguration(inStream); inStream.close(); realm = new DefaultRealm(); realm.init(realmConfig, ClaimTestUtil.getClaimTestData(), ClaimTestUtil.getProfileTestData(), 0); assertTrue(realm.getUserStoreManager().isExistingRole("adminx")); }
From source file:org.wso2.carbon.user.core.tenant.TestTenantManager.java
public void tenantDbStuff() throws Exception { String dbFolder = "target/Tenanttest"; if ((new File(dbFolder)).exists()) { deleteDir(new File(dbFolder)); }//from w ww . ja v a2s.c om BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(UserCoreTestConstants.DB_DRIVER); ds.setUrl("jdbc:h2:target/Tenanttest/TEN_TEST"); DatabaseCreator creator = new DatabaseCreator(ds); creator.createRegistryDatabase(); tenantMan = new JDBCTenantManager(ds, "super.com"); }
From source file:org.wso2.throttle.core.Throttler.java
/** * Copies physical ThrottleTable to this instance's in-memory ThrottleTable. *//*from www. j ava 2 s. com*/ private void populateThrottleTable() { BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName("com.mysql.jdbc.Driver"); basicDataSource.setUrl("jdbc:mysql://localhost/org_wso2_throttle_DataSource"); basicDataSource.setUsername("root"); basicDataSource.setPassword("root"); Connection connection = null; try { connection = basicDataSource.getConnection(); DatabaseMetaData dbm = connection.getMetaData(); // check if "ThrottleTable" table is there ResultSet tables = dbm.getTables(null, null, RDBMS_THROTTLE_TABLE_NAME, null); if (tables.next()) { // Table exists PreparedStatement stmt = connection.prepareStatement("SELECT * FROM " + RDBMS_THROTTLE_TABLE_NAME); ResultSet resultSet = stmt.executeQuery(); while (resultSet.next()) { String key = resultSet.getString(RDBMS_THROTTLE_TABLE_COLUMN_KEY); Boolean isThrottled = resultSet.getBoolean(RDBMS_THROTTLE_TABLE_COLUMN_ISTHROTTLED); try { getGlobalThrottleStreamInputHandler().send(new Object[] { key, isThrottled }); } catch (InterruptedException e) { log.error("Error occurred while sending an event.", e); } } } else { // Table does not exist log.warn("RDBMS ThrottleTable does not exist. Make sure global throttler server is started."); } } catch (SQLException e) { log.error("Error occurred while copying throttle data from global throttler server.", e); } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { log.error("Error occurred while closing database connection.", e); } } } }
From source file:org.xbib.io.jdbc.SQLConnectionFactory.java
/** * Get connection/*from w w w .j a va2 s .c om*/ * * @param uri * * @return an SQL connection * * @throws java.io.IOException */ @Override public Connection<SQLSession> getConnection(final URI uri) throws IOException { this.properties = URIUtil.getPropertiesFromURI(uri); Context context = null; DataSource ds = null; for (String name : new String[] { "jdbc/" + properties.getProperty("host"), "java:comp/env/" + properties.getProperty("scheme") + ":" + properties.getProperty("host") + ":" + properties.getProperty("port") }) { this.jndiName = name; try { context = new InitialContext(); Object o = context.lookup(jndiName); if (o instanceof DataSource) { logger.info("DataSource ''{}'' found in naming context", jndiName); ds = (DataSource) o; break; } else { logger.warn("JNDI object {} not a DataSource class: {} - ignored", jndiName, o.getClass()); } } catch (NameNotFoundException e) { logger.warn("DataSource ''{}'' not found in context", jndiName); } catch (NamingException e) { logger.warn(e.getMessage(), e); } } try { if (ds == null) { BasicDataSource bsource = new BasicDataSource(); bsource.setDriverClassName(properties.getProperty("driverClassName")); String url = properties.getProperty("jdbcScheme") + properties.getProperty("host") + ":" + properties.getProperty("port") + ("jdbc:oracle:thin:@".equals(properties.getProperty("jdbcScheme")) ? ":" : "/") + properties.getProperty("cluster"); bsource.setUrl(url); if (properties.containsKey("username")) { bsource.setUsername(properties.getProperty("username")); } if (properties.containsKey("password")) { bsource.setPassword(properties.getProperty("password")); } if (properties.containsKey("n")) { bsource.setInitialSize(Integer.parseInt(properties.getProperty("n"))); bsource.setMaxActive(Integer.parseInt(properties.getProperty("n"))); } // Other BasicDataSource settings, not used yet: // setAccessToUnderlyingConnectionAllowed(boolean allow) // setDefaultAutoCommit(boolean defaultAutoCommit) // setDefaultCatalog(String defaultCatalog) // setDefaultReadOnly(boolean defaultReadOnly) // setDefaultTransactionIsolation(int defaultTransactionIsolation) // setLogAbandoned(boolean logAbandoned) // setLoginTimeout(int loginTimeout) // setLogWriter(PrintWriter logWriter) // setMaxIdle(int maxIdle) // setMaxOpenPreparedStatements(int maxOpenStatements) // setMaxWait(long maxWait) // setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) // setMinIdle(int minIdle) // setNumTestsPerEvictionRun(int numTestsPerEvictionRun) // setPoolPreparedStatements(boolean poolingStatements) // setTestOnBorrow(boolean testOnBorrow) // setTestOnReturn(boolean testOnReturn) // setTestWhileIdle(boolean testWhileIdle) // setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) // setValidationQuery(String validationQuery) context.bind(jndiName, bsource); ds = (DataSource) bsource; } } catch (NamingException e) { throw new IOException(e.getMessage()); } try { ds.getConnection().setAutoCommit("false".equals(properties.getProperty("autoCommit")) ? false : true); } catch (SQLException e) { throw new IOException(e.getMessage()); } return new SQLConnection(ds); }
From source file:pcconfigurator.ComponentManagerImplTest.java
private DataSource setDataSource() { BasicDataSource ds = new BasicDataSource(); if (name != null && password != null && dbURL != null) { ds.setUrl(dbURL); ds.setUsername(name);//from ww w.j a v a 2 s . c o m ds.setPassword(password); } else throw new InternalFailureException("cannot create DataSource, properties are empty"); return ds; }