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:net.certifi.audittablegen.HsqldbDMR.java
/** * Generate a Hsqldb DataSource from Properties * * @param props//from www.j ava 2s. c o m * @return BasicDataSource as DataSource */ static DataSource getRunTimeDataSource(Properties props) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setUsername(props.getProperty("username")); dataSource.setPassword(props.getProperty("password")); dataSource.setUrl(props.getProperty("url")); dataSource.setMaxActive(10); dataSource.setMaxIdle(5); dataSource.setInitialSize(5); dataSource.setAccessToUnderlyingConnectionAllowed(true); dataSource.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS"); return dataSource; }
From source file:io.apiman.gateway.engine.policies.BasicAuthJDBCTest.java
/** * Creates an in-memory datasource.//from w w w. ja v a 2 s. com * @throws SQLException */ private static BasicDataSource createInMemoryDatasource() throws SQLException { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(Driver.class.getName()); ds.setUsername("sa"); //$NON-NLS-1$ ds.setPassword(""); //$NON-NLS-1$ ds.setUrl("jdbc:h2:mem:BasicAuthJDBCTest;DB_CLOSE_DELAY=-1"); //$NON-NLS-1$ Connection connection = ds.getConnection(); connection.prepareStatement( "CREATE TABLE users ( username varchar(255) NOT NULL, password varchar(255) NOT NULL, PRIMARY KEY (username))") .executeUpdate(); connection.prepareStatement( "INSERT INTO users (username, password) VALUES ('bwayne', 'ae2efd698aefdf366736a4eda1bc5241f9fbfec7')") .executeUpdate(); connection.prepareStatement( "INSERT INTO users (username, password) VALUES ('ckent', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')") .executeUpdate(); connection.prepareStatement( "INSERT INTO users (username, password) VALUES ('ballen', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')") .executeUpdate(); connection .prepareStatement( "CREATE TABLE roles (rolename varchar(255) NOT NULL, username varchar(255) NOT NULL)") .executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('user', 'bwayne')") .executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('admin', 'bwayne')") .executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('ckent', 'user')") .executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('ballen', 'user')") .executeUpdate(); connection.close(); return ds; }
From source file:gsn.storage.DataSources.java
public static BasicDataSource getDataSource(DBConnectionInfo dci) { BasicDataSource ds = null; try {//from w w w.j a v a2 s .com ds = (BasicDataSource) GSNContext.getMainContext().lookup(Integer.toString(dci.hashCode())); if (ds == null) { ds = new BasicDataSource(); ds.setDriverClassName(dci.getDriverClass()); ds.setUsername(dci.getUserName()); ds.setPassword(dci.getPassword()); ds.setUrl(dci.getUrl()); //ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); //ds.setAccessToUnderlyingConnectionAllowed(true); GSNContext.getMainContext().bind(Integer.toString(dci.hashCode()), ds); logger.warn("Created a DataSource to: " + ds.getUrl()); } } catch (NamingException e) { logger.error(e.getMessage(), e); } return ds; }
From source file:com.cws.esolutions.security.listeners.SecurityServiceInitializer.java
/** * Initializes the security service in a standalone mode - used for applications outside of a container or when * run as a standalone jar.//from www . j a va2 s. co m * * @param configFile - The security configuration file to utilize * @param logConfig - The logging configuration file to utilize * @param startConnections - Configure, load and start repository connections * @throws SecurityServiceException @{link com.cws.esolutions.security.exception.SecurityServiceException} * if an exception occurs during initialization */ public static void initializeService(final String configFile, final String logConfig, final boolean startConnections) throws SecurityServiceException { URL xmlURL = null; JAXBContext context = null; Unmarshaller marshaller = null; SecurityConfigurationData configData = null; final ClassLoader classLoader = SecurityServiceInitializer.class.getClassLoader(); final String serviceConfig = (StringUtils.isBlank(configFile)) ? System.getProperty("configFileFile") : configFile; final String loggingConfig = (StringUtils.isBlank(logConfig)) ? System.getProperty("secLogConfig") : logConfig; try { try { DOMConfigurator.configure(Loader.getResource(loggingConfig)); } catch (NullPointerException npx) { try { DOMConfigurator.configure(FileUtils.getFile(loggingConfig).toURI().toURL()); } catch (NullPointerException npx1) { System.err.println("Unable to load logging configuration. No logging enabled!"); System.err.println(""); npx1.printStackTrace(); } } xmlURL = classLoader.getResource(serviceConfig); if (xmlURL == null) { // try loading from the filesystem xmlURL = FileUtils.getFile(serviceConfig).toURI().toURL(); } context = JAXBContext.newInstance(SecurityConfigurationData.class); marshaller = context.createUnmarshaller(); configData = (SecurityConfigurationData) marshaller.unmarshal(xmlURL); SecurityServiceInitializer.svcBean.setConfigData(configData); if (startConnections) { DAOInitializer.configureAndCreateAuthConnection( new FileInputStream(FileUtils.getFile(configData.getSecurityConfig().getAuthConfig())), false, SecurityServiceInitializer.svcBean); Map<String, DataSource> dsMap = SecurityServiceInitializer.svcBean.getDataSources(); if (DEBUG) { DEBUGGER.debug("dsMap: {}", dsMap); } if (configData.getResourceConfig() != null) { if (dsMap == null) { dsMap = new HashMap<String, DataSource>(); } for (DataSourceManager mgr : configData.getResourceConfig().getDsManager()) { if (!(dsMap.containsKey(mgr.getDsName()))) { StringBuilder sBuilder = new StringBuilder() .append("connectTimeout=" + mgr.getConnectTimeout() + ";") .append("socketTimeout=" + mgr.getConnectTimeout() + ";") .append("autoReconnect=" + mgr.getAutoReconnect() + ";") .append("zeroDateTimeBehavior=convertToNull"); if (DEBUG) { DEBUGGER.debug("StringBuilder: {}", sBuilder); } BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(mgr.getDriver()); dataSource.setUrl(mgr.getDataSource()); dataSource.setUsername(mgr.getDsUser()); dataSource.setConnectionProperties(sBuilder.toString()); dataSource.setPassword(PasswordUtils.decryptText(mgr.getDsPass(), mgr.getDsSalt(), configData.getSecurityConfig().getSecretAlgorithm(), configData.getSecurityConfig().getIterations(), configData.getSecurityConfig().getKeyBits(), configData.getSecurityConfig().getEncryptionAlgorithm(), configData.getSecurityConfig().getEncryptionInstance(), configData.getSystemConfig().getEncoding())); if (DEBUG) { DEBUGGER.debug("BasicDataSource: {}", dataSource); } dsMap.put(mgr.getDsName(), dataSource); } } if (DEBUG) { DEBUGGER.debug("dsMap: {}", dsMap); } SecurityServiceInitializer.svcBean.setDataSources(dsMap); } } } catch (JAXBException jx) { jx.printStackTrace(); throw new SecurityServiceException(jx.getMessage(), jx); } catch (FileNotFoundException fnfx) { fnfx.printStackTrace(); throw new SecurityServiceException(fnfx.getMessage(), fnfx); } catch (MalformedURLException mux) { mux.printStackTrace(); throw new SecurityServiceException(mux.getMessage(), mux); } catch (SecurityException sx) { sx.printStackTrace(); throw new SecurityServiceException(sx.getMessage(), sx); } }
From source file:io.apiman.gateway.engine.policies.BasicAuthenticationPolicyTest.java
/** * Creates an in-memory datasource.//from w w w . j a va 2s. c o m * @throws SQLException */ private static BasicDataSource createInMemoryDatasource() throws SQLException { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(Driver.class.getName()); ds.setUsername("sa"); //$NON-NLS-1$ ds.setPassword(""); //$NON-NLS-1$ ds.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"); //$NON-NLS-1$ Connection connection = ds.getConnection(); connection.prepareStatement( "CREATE TABLE users ( username varchar(255) NOT NULL, password varchar(255) NOT NULL, PRIMARY KEY (username) )") .executeUpdate(); connection.prepareStatement( "INSERT INTO users (username, password) VALUES ('bwayne', 'ae2efd698aefdf366736a4eda1bc5241f9fbfec7')") .executeUpdate(); connection.prepareStatement( "INSERT INTO users (username, password) VALUES ('ckent', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')") .executeUpdate(); connection.close(); return ds; }
From source file:com.weibo.datasys.common.db.DBManager.java
/** * /*from w w w.jav a2 s . com*/ * ????? * * @param configData */ private static void initDataSource(CommonData configData) { String dsname = configData.getBaseField("dsname"); BasicDataSource dataSource = new BasicDataSource(); // ?? dataSource.setDriverClassName(configData.getBaseField("driverClassName")); // ?? dataSource.setUrl(configData.getBaseField("connectURL")); // ??? dataSource.setUsername(configData.getBaseField("username")); dataSource.setPassword(configData.getBaseField("password")); // ? dataSource.setInitialSize(StringUtils.parseInt(configData.getBaseField("initialSize"), 1)); // ? dataSource.setMinIdle(StringUtils.parseInt(configData.getBaseField("minIdle"), 1)); // dataSource.setMaxIdle(StringUtils.parseInt(configData.getBaseField("maxIdle"), 1)); // dataSource.setMaxActive(StringUtils.parseInt(configData.getBaseField("maxActive"), 1)); // ?,?(ms) dataSource.setMaxWait(StringUtils.parseInt(configData.getBaseField("maxWait"), 1000)); // ?? dataSource.setTestWhileIdle(true); // ?sql? dataSource.setValidationQuery("select 'test'"); // ? dataSource.setValidationQueryTimeout(5000); // dataSource.setTimeBetweenEvictionRunsMillis(3600000); // ?? dataSource.setMinEvictableIdleTimeMillis(3600000); dsMap.put(dsname, dataSource); logger.info("[InitDataSourceOK] - dsname={}", dsname); }
From source file:com.wso2.raspberrypi.Util.java
private static BasicDataSource getBasicDataSource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setUrl("jdbc:mysql://rss1.stratoslive.wso2.com/rpi_azeez_org"); ds.setUsername("rpi_FHdBOhR3"); ds.setPassword("wso2"); ds.setValidationQuery("SELECT 1"); return ds;//from w ww. j ava 2s .c o m }
From source file:com.aurel.track.dbase.DatabaseHandler.java
private static void checkForDatabase() { try {// ww w. ja v a 2s. co m BasicDataSource ds = new BasicDataSource(); ds.setUsername(user); ds.setPassword(password); ds.setDriverClassName(getJdbcDriver()); ds.setUrl(getJdbcUrl()); testConnection(); // createDatabaseInt(ds, fileNameSchema); System.out.println("Can access database"); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } }
From source file:hotelmanagertests.GuestManagerImplTest.java
private static DataSource prepareDataSource() throws SQLException { BasicDataSource ds = new BasicDataSource(); ds.setUrl("jdbc:derby:memory:HotelManagerDatabaseTest;create=true"); return ds;//w w w.j a va2 s .c o m }
From source file:com.alibaba.cobar.manager.qa.modle.CobarFactory.java
public static CobarAdapter getCobarAdapter(String cobarNodeName) throws IOException { CobarAdapter cAdapter = new CobarAdapter(); Properties prop = new Properties(); prop.load(CobarFactory.class.getClassLoader().getResourceAsStream("cobarNode.properties")); BasicDataSource ds = new BasicDataSource(); String user = prop.getProperty(cobarNodeName + ".user").trim(); String password = prop.getProperty(cobarNodeName + ".password").trim(); String ip = prop.getProperty(cobarNodeName + ".ip").trim(); int managerPort = Integer.parseInt(prop.getProperty(cobarNodeName + ".manager.port").trim()); int maxActive = -1; int minIdle = 0; long timeBetweenEvictionRunsMillis = 10 * 60 * 1000; int numTestsPerEvictionRun = Integer.MAX_VALUE; long minEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS; ds.setUsername(user);// ww w . ja va 2s. c o m ds.setPassword(password); ds.setUrl(new StringBuilder().append("jdbc:mysql://").append(ip).append(":").append(managerPort).append("/") .toString()); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setMaxActive(maxActive); ds.setMinIdle(minIdle); ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); ds.setNumTestsPerEvictionRun(numTestsPerEvictionRun); ds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); cAdapter.setDataSource(ds); return cAdapter; }