List of usage examples for java.util Properties size
@Override public int size()
From source file:com.cloud.utils.db.TransactionLegacy.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void initDataSource(Properties dbProps) { try {//from w w w .j a v a 2 s.c o m if (dbProps.size() == 0) return; s_dbHAEnabled = Boolean.valueOf(dbProps.getProperty("db.ha.enabled")); s_logger.info("Is Data Base High Availiability enabled? Ans : " + s_dbHAEnabled); String loadBalanceStrategy = dbProps.getProperty("db.ha.loadBalanceStrategy"); // FIXME: If params are missing...default them???? final int cloudMaxActive = Integer.parseInt(dbProps.getProperty("db.cloud.maxActive")); final int cloudMaxIdle = Integer.parseInt(dbProps.getProperty("db.cloud.maxIdle")); final long cloudMaxWait = Long.parseLong(dbProps.getProperty("db.cloud.maxWait")); final String cloudUsername = dbProps.getProperty("db.cloud.username"); final String cloudPassword = dbProps.getProperty("db.cloud.password"); final String cloudHost = dbProps.getProperty("db.cloud.host"); final String cloudDriver = dbProps.getProperty("db.cloud.driver"); final int cloudPort = Integer.parseInt(dbProps.getProperty("db.cloud.port")); final String cloudDbName = dbProps.getProperty("db.cloud.name"); final boolean cloudAutoReconnect = Boolean.parseBoolean(dbProps.getProperty("db.cloud.autoReconnect")); final String cloudValidationQuery = dbProps.getProperty("db.cloud.validationQuery"); final String cloudIsolationLevel = dbProps.getProperty("db.cloud.isolation.level"); int isolationLevel = Connection.TRANSACTION_READ_COMMITTED; if (cloudIsolationLevel == null) { isolationLevel = Connection.TRANSACTION_READ_COMMITTED; } else if (cloudIsolationLevel.equalsIgnoreCase("readcommitted")) { isolationLevel = Connection.TRANSACTION_READ_COMMITTED; } else if (cloudIsolationLevel.equalsIgnoreCase("repeatableread")) { isolationLevel = Connection.TRANSACTION_REPEATABLE_READ; } else if (cloudIsolationLevel.equalsIgnoreCase("serializable")) { isolationLevel = Connection.TRANSACTION_SERIALIZABLE; } else if (cloudIsolationLevel.equalsIgnoreCase("readuncommitted")) { isolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED; } else { s_logger.warn("Unknown isolation level " + cloudIsolationLevel + ". Using read uncommitted"); } final boolean cloudTestOnBorrow = Boolean.parseBoolean(dbProps.getProperty("db.cloud.testOnBorrow")); final boolean cloudTestWhileIdle = Boolean.parseBoolean(dbProps.getProperty("db.cloud.testWhileIdle")); final long cloudTimeBtwEvictionRunsMillis = Long .parseLong(dbProps.getProperty("db.cloud.timeBetweenEvictionRunsMillis")); final long cloudMinEvcitableIdleTimeMillis = Long .parseLong(dbProps.getProperty("db.cloud.minEvictableIdleTimeMillis")); final boolean cloudPoolPreparedStatements = Boolean .parseBoolean(dbProps.getProperty("db.cloud.poolPreparedStatements")); final String url = dbProps.getProperty("db.cloud.url.params"); String cloudDbHAParams = null; String cloudSlaves = null; if (s_dbHAEnabled) { cloudDbHAParams = getDBHAParams("cloud", dbProps); cloudSlaves = dbProps.getProperty("db.cloud.slaves"); s_logger.info("The slaves configured for Cloud Data base is/are : " + cloudSlaves); } final boolean useSSL = Boolean.parseBoolean(dbProps.getProperty("db.cloud.useSSL")); if (useSSL) { System.setProperty("javax.net.ssl.keyStore", dbProps.getProperty("db.cloud.keyStore")); System.setProperty("javax.net.ssl.keyStorePassword", dbProps.getProperty("db.cloud.keyStorePassword")); System.setProperty("javax.net.ssl.trustStore", dbProps.getProperty("db.cloud.trustStore")); System.setProperty("javax.net.ssl.trustStorePassword", dbProps.getProperty("db.cloud.trustStorePassword")); } final GenericObjectPool cloudConnectionPool = new GenericObjectPool(null, cloudMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, cloudMaxWait, cloudMaxIdle, cloudTestOnBorrow, false, cloudTimeBtwEvictionRunsMillis, 1, cloudMinEvcitableIdleTimeMillis, cloudTestWhileIdle); final String cloudConnectionUri = cloudDriver + "://" + cloudHost + (s_dbHAEnabled ? "," + cloudSlaves : "") + ":" + cloudPort + "/" + cloudDbName + "?autoReconnect=" + cloudAutoReconnect + (url != null ? "&" + url : "") + (useSSL ? "&useSSL=true" : "") + (s_dbHAEnabled ? "&" + cloudDbHAParams : "") + (s_dbHAEnabled ? "&loadBalanceStrategy=" + loadBalanceStrategy : ""); DriverLoader.loadDriver(cloudDriver); final ConnectionFactory cloudConnectionFactory = new DriverManagerConnectionFactory(cloudConnectionUri, cloudUsername, cloudPassword); final KeyedObjectPoolFactory poolableObjFactory = (cloudPoolPreparedStatements ? new StackKeyedObjectPoolFactory() : null); final PoolableConnectionFactory cloudPoolableConnectionFactory = new PoolableConnectionFactory( cloudConnectionFactory, cloudConnectionPool, poolableObjFactory, cloudValidationQuery, false, false, isolationLevel); // Default Data Source for CloudStack s_ds = new PoolingDataSource(cloudPoolableConnectionFactory.getPool()); // Configure the usage db final int usageMaxActive = Integer.parseInt(dbProps.getProperty("db.usage.maxActive")); final int usageMaxIdle = Integer.parseInt(dbProps.getProperty("db.usage.maxIdle")); final long usageMaxWait = Long.parseLong(dbProps.getProperty("db.usage.maxWait")); final String usageUsername = dbProps.getProperty("db.usage.username"); final String usagePassword = dbProps.getProperty("db.usage.password"); final String usageHost = dbProps.getProperty("db.usage.host"); final String usageDriver = dbProps.getProperty("db.usage.driver"); final int usagePort = Integer.parseInt(dbProps.getProperty("db.usage.port")); final String usageDbName = dbProps.getProperty("db.usage.name"); final boolean usageAutoReconnect = Boolean.parseBoolean(dbProps.getProperty("db.usage.autoReconnect")); final String usageUrl = dbProps.getProperty("db.usage.url.params"); final GenericObjectPool usageConnectionPool = new GenericObjectPool(null, usageMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, usageMaxWait, usageMaxIdle); final String usageConnectionUri = usageDriver + "://" + usageHost + (s_dbHAEnabled ? "," + dbProps.getProperty("db.cloud.slaves") : "") + ":" + usagePort + "/" + usageDbName + "?autoReconnect=" + usageAutoReconnect + (usageUrl != null ? "&" + usageUrl : "") + (s_dbHAEnabled ? "&" + getDBHAParams("usage", dbProps) : "") + (s_dbHAEnabled ? "&loadBalanceStrategy=" + loadBalanceStrategy : ""); DriverLoader.loadDriver(usageDriver); final ConnectionFactory usageConnectionFactory = new DriverManagerConnectionFactory(usageConnectionUri, usageUsername, usagePassword); final PoolableConnectionFactory usagePoolableConnectionFactory = new PoolableConnectionFactory( usageConnectionFactory, usageConnectionPool, new StackKeyedObjectPoolFactory(), null, false, false); // Data Source for usage server s_usageDS = new PoolingDataSource(usagePoolableConnectionFactory.getPool()); try { // Configure the simulator db final int simulatorMaxActive = Integer.parseInt(dbProps.getProperty("db.simulator.maxActive")); final int simulatorMaxIdle = Integer.parseInt(dbProps.getProperty("db.simulator.maxIdle")); final long simulatorMaxWait = Long.parseLong(dbProps.getProperty("db.simulator.maxWait")); final String simulatorUsername = dbProps.getProperty("db.simulator.username"); final String simulatorPassword = dbProps.getProperty("db.simulator.password"); final String simulatorHost = dbProps.getProperty("db.simulator.host"); final String simulatorDriver = dbProps.getProperty("db.simulator.driver"); final int simulatorPort = Integer.parseInt(dbProps.getProperty("db.simulator.port")); final String simulatorDbName = dbProps.getProperty("db.simulator.name"); final boolean simulatorAutoReconnect = Boolean .parseBoolean(dbProps.getProperty("db.simulator.autoReconnect")); final GenericObjectPool simulatorConnectionPool = new GenericObjectPool(null, simulatorMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, simulatorMaxWait, simulatorMaxIdle); final String simulatorConnectionUri = simulatorDriver + "://" + simulatorHost + ":" + simulatorPort + "/" + simulatorDbName + "?autoReconnect=" + simulatorAutoReconnect; DriverLoader.loadDriver(simulatorDriver); final ConnectionFactory simulatorConnectionFactory = new DriverManagerConnectionFactory( simulatorConnectionUri, simulatorUsername, simulatorPassword); final PoolableConnectionFactory simulatorPoolableConnectionFactory = new PoolableConnectionFactory( simulatorConnectionFactory, simulatorConnectionPool, new StackKeyedObjectPoolFactory(), null, false, false); s_simulatorDS = new PoolingDataSource(simulatorPoolableConnectionFactory.getPool()); } catch (Exception e) { s_logger.debug("Simulator DB properties are not available. Not initializing simulator DS"); } } catch (final Exception e) { s_ds = getDefaultDataSource("cloud"); s_usageDS = getDefaultDataSource("cloud_usage"); s_simulatorDS = getDefaultDataSource("cloud_simulator"); s_logger.warn( "Unable to load db configuration, using defaults with 5 connections. Falling back on assumed datasource on localhost:3306 using username:password=cloud:cloud. Please check your configuration", e); } }
From source file:de.alpharogroup.lang.ClassExtensionsTest.java
/** * Test method for./* w w w .j av a 2 s. c o m*/ * * @throws IOException * Signals that an I/O exception has occurred. * {@link de.alpharogroup.lang.ClassExtensions#getResourceAsStream(java.lang.String)} * . */ @Test(enabled = true) public void testGetResourceAsStreamString() throws IOException { final String propertiesFilename = "de/alpharogroup/lang/resources.properties"; final InputStream is = ClassExtensions.getResourceAsStream(propertiesFilename); this.result = is != null; AssertJUnit.assertTrue("", this.result); final Properties prop = new Properties(); prop.load(is); this.result = prop.size() == 3; }
From source file:edu.cornell.med.icb.geo.TestIndexedIdentifier.java
/** * Validates that an empty {@link edu.cornell.med.icb.identifier.IndexedIdentifier} object * is transformed to properties properly. *//*from www . jav a2s .c o m*/ @Test public void emptyObject() { final IndexedIdentifier indexedIdentifier = new IndexedIdentifier(); assertTrue("Initial state should be empty", indexedIdentifier.isEmpty()); assertEquals("Initial state should have no elements", 0, indexedIdentifier.size()); assertEquals("Default value", -1, indexedIdentifier.defaultReturnValue()); final Map<String, Properties> propertyMap = indexedIdentifier.toPropertyMap(); assertNotNull("Property map should never be null", propertyMap); assertFalse("Property map should never be empty", propertyMap.isEmpty()); assertEquals("Property map should have 2 keys", 2, propertyMap.size()); final Properties id2IndexProperties = propertyMap.get("id2Index"); assertNotNull("id2Index map should never be null", id2IndexProperties); assertTrue("id2Index map should be empty", id2IndexProperties.isEmpty()); assertEquals("id2Index map should have no elements", 0, id2IndexProperties.size()); final Properties runningIndexProperties = propertyMap.get("runningIndex"); assertNotNull("runningIndex map should never be null", runningIndexProperties); assertFalse("runningIndex map should not be empty", runningIndexProperties.isEmpty()); assertEquals("runningIndex map should have one element", 1, runningIndexProperties.size()); final String runningIndexProperty = runningIndexProperties.getProperty("runningIndex"); assertNotNull("runningIndex must not be null", runningIndexProperty); assertTrue("runningIndex must not be blank", StringUtils.isNotBlank(runningIndexProperty)); assertEquals("runningIndex should be zero", 0, Integer.parseInt(runningIndexProperty)); }
From source file:de.alpharogroup.lang.ClassExtensionsTest.java
/** * Test method for/*ww w .j ava 2 s.c o m*/ * {@link de.alpharogroup.lang.ClassExtensions#getResourceAsStream(java.lang.Class, java.lang.String)} * . * * @throws IOException * Signals that an I/O exception has occurred. */ @Test(enabled = false) public void testGetRessourceAsStream() throws IOException { final String propertiesFilename = "resources.properties"; final String pathFromObject = PackageExtensions.getPackagePathWithSlash(this); final String path = pathFromObject + propertiesFilename; final ClassExtensionsTest obj = new ClassExtensionsTest(); final InputStream is = ClassExtensions.getResourceAsStream(obj.getClass(), path); this.result = is != null; AssertJUnit.assertTrue("InputStream should not be null", this.result); final Properties prop = new Properties(); prop.load(is); this.result = prop.size() == 3; AssertJUnit.assertTrue("Size of prop should be 3.", this.result); }
From source file:com.toolsverse.etl.connector.FileConnectorParams.java
@Override public void init(Alias alis) { if (!alis.isDbConnection()) { Boolean hasWildcard = FileUtils.hasWildCard(alis.getUrl()); if (hasWildcard != null && !hasWildcard) setFileName(alis.getUrl());//from w w w . j a v a 2 s . co m } Properties props = Utils.getProperties(alis.getParams()); if (props == null || props.size() == 0) return; setDateFormat(props.getProperty(SqlUtils.DATE_FORMAT_PROP)); setTimeFormat(props.getProperty(SqlUtils.TIME_FORMAT_PROP)); setDateTimeFormat(props.getProperty(SqlUtils.DATE_TIME_FORMAT_PROP)); }
From source file:com.xpn.xwiki.store.DBCPConnectionProvider.java
public void configure(Properties props) throws HibernateException { try {//from ww w . j a v a 2 s . c om LOGGER.debug("Configure DBCPConnectionProvider"); // DBCP properties used to create the BasicDataSource Properties dbcpProperties = new Properties(); // DriverClass & url String jdbcDriverClass = props.getProperty(Environment.DRIVER); String jdbcUrl = props.getProperty(Environment.URL); dbcpProperties.put("driverClassName", jdbcDriverClass); dbcpProperties.put("url", jdbcUrl); // Username / password. Only put username and password if they're not null. This allows // external authentication support (OS authenticated). It'll thus work if the hibernate // config does not specify a username and/or password. String username = props.getProperty(Environment.USER); if (username != null) { dbcpProperties.put("username", username); } String password = props.getProperty(Environment.PASS); if (password != null) { dbcpProperties.put("password", password); } // Isolation level String isolationLevel = props.getProperty(Environment.ISOLATION); if ((isolationLevel != null) && (isolationLevel.trim().length() > 0)) { dbcpProperties.put("defaultTransactionIsolation", isolationLevel); } // Turn off autocommit (unless autocommit property is set) String autocommit = props.getProperty(AUTOCOMMIT); if ((autocommit != null) && (autocommit.trim().length() > 0)) { dbcpProperties.put("defaultAutoCommit", autocommit); } else { dbcpProperties.put("defaultAutoCommit", String.valueOf(Boolean.FALSE)); } // Pool size String poolSize = props.getProperty(Environment.POOL_SIZE); if ((poolSize != null) && (poolSize.trim().length() > 0) && (Integer.parseInt(poolSize) > 0)) { dbcpProperties.put("maxActive", poolSize); } // Copy all "driver" properties into "connectionProperties" Properties driverProps = ConnectionProviderFactory.getConnectionProperties(props); if (driverProps.size() > 0) { StringBuffer connectionProperties = new StringBuffer(); for (Iterator iter = driverProps.keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); String value = driverProps.getProperty(key); connectionProperties.append(key).append('=').append(value); if (iter.hasNext()) { connectionProperties.append(';'); } } dbcpProperties.put("connectionProperties", connectionProperties.toString()); } // Copy all DBCP properties removing the prefix for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { String key = String.valueOf(iter.next()); if (key.startsWith(PREFIX)) { String property = key.substring(PREFIX.length()); String value = props.getProperty(key); dbcpProperties.put(property, value); } } // Backward-compatibility if (props.getProperty(DBCP_PS_MAXACTIVE) != null) { dbcpProperties.put("poolPreparedStatements", String.valueOf(Boolean.TRUE)); dbcpProperties.put("maxOpenPreparedStatements", props.getProperty(DBCP_PS_MAXACTIVE)); } // Some debug info if (LOGGER.isDebugEnabled()) { LOGGER.debug("Creating a DBCP BasicDataSource with the following DBCP factory properties:"); StringWriter sw = new StringWriter(); dbcpProperties.list(new PrintWriter(sw, true)); LOGGER.debug(sw.toString()); } // Let the factory create the pool ds = (BasicDataSource) BasicDataSourceFactory.createDataSource(dbcpProperties); // The BasicDataSource has lazy initialization // borrowing a connection will start the DataSource // and make sure it is configured correctly. Connection conn = ds.getConnection(); conn.close(); // Log pool statistics before continuing. logStatistics(); } catch (Exception e) { String message = "Could not create a DBCP pool. " + "There is an error in the hibernate configuration file, please review it."; LOGGER.error(message, e); if (ds != null) { try { ds.close(); } catch (Exception e2) { // ignore } ds = null; } throw new HibernateException(message, e); } LOGGER.debug("Configure DBCPConnectionProvider complete"); }
From source file:it.txt.ens.authorisationService.test.IntegrationTest.java
@Test public void test2() throws Exception { //configure and start the ENS ServiceReference<ConfigurationAdmin> configAdminSR = context.getServiceReference(ConfigurationAdmin.class); assertNotNull("No service reference found for " + ConfigurationAdmin.class.getName(), configAdminSR); ConfigurationAdmin configAdmin = context.getService(configAdminSR); assertNotNull("No instance found for " + ConfigurationAdmin.class.getName(), configAdminSR); File file = new File(System.getProperty(CONFIG_FILE_PROPERTY)); FileInputStream stream = new FileInputStream(file); Properties p = new Properties(); try {//from w ww . j ava 2s . com p.load(stream); } finally { if (stream != null) stream.close(); } Dictionary<String, Object> prop = new Hashtable<String, Object>(p.size()); for (Object key : p.keySet()) { if (key.equals(PropertiesKeys.CONFIGURATION_FILE_PATH_ATTRIBUTE)) prop.put((String) key, p.getProperty((String) key)); else if (key.equals(PropertiesKeys.ENS_GUI_ATTRIBUTE)) prop.put((String) key, Boolean.parseBoolean(p.getProperty((String) key))); else if (key.equals(PropertiesKeys.THREAD_POOL_SIZE_ATTRIBUTE)) prop.put((String) key, Integer.parseInt(p.getProperty((String) key))); else continue; } Configuration config = configAdmin.getConfiguration(ENSAuthorisationServiceMS.SERVICE_PID); config.update(prop); Thread.sleep(60000); //delete the configuration config.delete(); }
From source file:edu.cornell.med.icb.geo.TestIndexedIdentifier.java
/** * Validates that a populated {@link edu.cornell.med.icb.identifier.IndexedIdentifier} object * is transformed to properties properly. *///from w w w. ja v a2 s. co m @Test public void toPropertyMap() { final IndexedIdentifier indexedIdentifier = new IndexedIdentifier(); indexedIdentifier.registerIdentifier(new MutableString("one")); indexedIdentifier.registerIdentifier(new MutableString("two")); indexedIdentifier.registerIdentifier(new MutableString("three")); assertFalse("State should not be empty", indexedIdentifier.isEmpty()); assertEquals("State should have 3 elements", 3, indexedIdentifier.size()); assertEquals("Default value", -1, indexedIdentifier.defaultReturnValue()); final Map<String, Properties> propertyMap = indexedIdentifier.toPropertyMap(); assertNotNull("Property map should never be null", propertyMap); assertFalse("Property map should never be empty", propertyMap.isEmpty()); assertEquals("Property map should have 2 keys", 2, propertyMap.size()); final Properties id2IndexProperties = propertyMap.get("id2Index"); assertNotNull("id2Index map should never be null", id2IndexProperties); assertFalse("id2Index map should not be empty", id2IndexProperties.isEmpty()); assertEquals("id2Index map should have three elements", 3, id2IndexProperties.size()); assertEquals("Element one", "0", id2IndexProperties.getProperty("one")); assertEquals("Element two", "1", id2IndexProperties.getProperty("two")); assertEquals("Element three", "2", id2IndexProperties.getProperty("three")); final Properties runningIndexProperties = propertyMap.get("runningIndex"); assertNotNull("runningIndex map should never be null", runningIndexProperties); assertFalse("runningIndex map should not be empty", runningIndexProperties.isEmpty()); assertEquals("runningIndex map should have one element", 1, runningIndexProperties.size()); final String runningIndexProperty = runningIndexProperties.getProperty("runningIndex"); assertNotNull("runningIndex must not be null", runningIndexProperty); assertTrue("runningIndex must not be blank", StringUtils.isNotBlank(runningIndexProperty)); assertEquals("runningIndex should be three", 3, Integer.parseInt(runningIndexProperty)); }
From source file:org.openmrs.report.impl.ReportServiceImpl.java
/** * @see org.openmrs.api.ReportService#applyReportXmlMacros(java.lang.String) */// w w w .j a v a 2s . co m @Transactional(readOnly = true) public String applyReportXmlMacros(String input) { Properties macros = getReportXmlMacros(); if (macros != null && macros.size() > 0) { log.debug("XML Before macros: " + input); String prefix = macros.getProperty("macroPrefix", ""); String suffix = macros.getProperty("macroSuffix", ""); while (true) { String replacement = input; for (Map.Entry<Object, Object> e : macros.entrySet()) { String key = prefix + e.getKey() + suffix; String value = e.getValue() == null ? "" : e.getValue().toString(); log.debug("Trying to replace " + key + " with " + value); replacement = replacement.replace(key, (String) e.getValue()); } if (input.equals(replacement)) { log.debug("Macro expansion complete."); break; } input = replacement; log.debug("XML Exploded to: " + input); } } return input; }
From source file:com.jive.myco.seyren.core.util.email.SeyrenMailSender.java
@Inject public SeyrenMailSender(SeyrenConfig seyrenConfig) { int port = seyrenConfig.getSmtpPort(); String host = seyrenConfig.getSmtpHost(); String username = seyrenConfig.getSmtpUsername(); String password = seyrenConfig.getSmtpPassword(); String protocol = seyrenConfig.getSmtpProtocol(); setPort(port);// ww w . j a v a2 s .com setHost(host); Properties props = new Properties(); if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) { props.setProperty("mail.smtp.auth", "true"); setUsername(username); setPassword(password); } if (getPort() == 587) { props.put("mail.smtp.starttls.enable", "true"); } if (props.size() > 0) { setJavaMailProperties(props); } setProtocol(protocol); LOGGER.info("{}:{}@{}", username, password, host); }