List of usage examples for java.util Properties size
@Override public int size()
From source file:org.hibernate.connection.DBCPConnectionProvider.java
public void configure(Properties props) throws HibernateException { try {//www . ja va2 s . co m log.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 String username = props.getProperty(Environment.USER); String password = props.getProperty(Environment.PASS); dbcpProperties.put("username", username); 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 (Object o : props.keySet()) { String key = String.valueOf(o); 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 (log.isDebugEnabled()) { log.debug("Creating a DBCP BasicDataSource with the following DBCP factory properties:"); StringWriter sw = new StringWriter(); dbcpProperties.list(new PrintWriter(sw, true)); log.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(); // then we set the whenExhausted flag (the hard way...) Field poolField = BasicDataSource.class.getDeclaredField("connectionPool"); poolField.setAccessible(true); GenericObjectPool connectionPool = (GenericObjectPool) poolField.get(ds); connectionPool.setWhenExhaustedAction((byte) 2); } catch (Exception e) { String message = "Could not create a DBCP pool"; log.fatal(message, e); if (ds != null) { try { ds.close(); } catch (Exception e2) { // ignore } ds = null; } throw new HibernateException(message, e); } log.debug("Configure DBCPConnectionProvider complete"); }
From source file:org.unitime.commons.hibernate.connection.DBCPConnectionProvider.java
public void configure(Properties props) throws HibernateException { try {//from w ww .j ava 2s. c om log.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 String username = props.getProperty(Environment.USER); String password = props.getProperty(Environment.PASS); dbcpProperties.put("username", username); 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(Environment.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 = 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)); } // 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"; log.fatal(message, e); if (ds != null) { try { ds.close(); } catch (Exception e2) { // ignore } ds = null; } throw new HibernateException(message, e); } log.debug("Configure DBCPConnectionProvider complete"); }
From source file:org.lsc.jndi.JndiServices.java
/** * Get the source directory connected service. * @return the source directory connected service *///from www . j ava 2 s . c o m @Deprecated public static JndiServices getSrcInstance() { try { Properties srcProperties = Configuration.getSrcProperties(); if (srcProperties != null && srcProperties.size() > 0) { return getInstance(srcProperties); } return null; } catch (Exception e) { LOGGER.error("Error opening the LDAP connection to the source!"); throw new RuntimeException(e); } }
From source file:org.infoglue.common.dbcp.DBCPConnectionProvider.java
public void configure(Properties props) throws HibernateException { try {//from ww w . j a v a 2s . co m log.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 String username = props.getProperty(Environment.USER); String password = props.getProperty(Environment.PASS); dbcpProperties.put("username", username); 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 (log.isDebugEnabled()) { log.debug("Creating a DBCP BasicDataSource with the following DBCP factory properties:"); StringWriter sw = new StringWriter(); dbcpProperties.list(new PrintWriter(sw, true)); log.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"; log.fatal(message, e); if (ds != null) { try { ds.close(); } catch (Exception e2) { // ignore } ds = null; } throw new HibernateException(message, e); } log.debug("Configure DBCPConnectionProvider complete"); }
From source file:com.sanlq.common.BrandModel.java
private void inita() { if (BRANDMODEL_CONTENT == null) { BRANDMODEL_CONTENT = readHDFSFile("hdfs://hadoopcluster/data/lib/brandmodel/brandmodel.dat"); try {// w ww . j ava 2s .co m // String content = new String(BRANDMODEL_CONTENT, "UTF-8"); // List<ModelBean> list = JSON.parseArray(content, ModelBean.class); // Integer cnt = 0; // for (ModelBean modelBean : list) { // BRANDMODEL.put(modelBean.getTitleOrg(), modelBean); // cnt++; // if (cnt % 1000 == 0) { // log.info("ALREADY IMPORT " + cnt + " MODEL "); // } // } Properties props = new Properties(); BufferedReader bf = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(BRANDMODEL_CONTENT))); props.load(bf); System.out.println("props: " + props.size()); Enumeration enu2 = props.propertyNames(); Integer cnt = 0; while (enu2.hasMoreElements()) { String key = (String) enu2.nextElement(); String d = props.getProperty(key); String[] arrd = d.split("::"); ModelBean mbean = new ModelBean(); if (arrd.length == 6) { mbean.setBrandId(Integer.valueOf(arrd[0])); mbean.setBrandTitleEn(arrd[1]); mbean.setBrandTitleCn(arrd[2]); mbean.setTitleOrg(arrd[3]); mbean.setTitleCn(arrd[4]); mbean.setTitleEn(arrd[5]); if (BRANDMODEL.contains(arrd[3])) { System.out.println("Exist: " + d); } else { BRANDMODEL.put(arrd[3], mbean); } } else { System.out.println("ERR: " + d); } cnt++; } log.info("DONE IMPORT " + cnt + " MODEL " + BRANDMODEL.size()); } catch (UnsupportedEncodingException ex) { Logger.getLogger(BrandModel.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(BrandModel.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:azkaban.jobtype.AzkabanPigListener.java
@SuppressWarnings("deprecation") private void addMapReduceJobState(PigJobDagNode node) { JobClient jobClient = PigStats.get().getJobClient(); try {/*w w w.j a v a2 s.c o m*/ RunningJob runningJob = jobClient.getJob(node.getJobId()); if (runningJob == null) { logger.warn("Couldn't find job status for jobId=" + node.getJobId()); return; } JobID jobID = runningJob.getID(); TaskReport[] mapTaskReport = jobClient.getMapTaskReports(jobID); TaskReport[] reduceTaskReport = jobClient.getReduceTaskReports(jobID); node.setMapReduceJobState(new MapReduceJobState(runningJob, mapTaskReport, reduceTaskReport)); if (node.getJobConfiguration() == null) { Properties jobConfProperties = StatsUtils.getJobConf(runningJob); if (jobConfProperties != null && jobConfProperties.size() > 0) { node.setJobConfiguration(jobConfProperties); } } } catch (IOException e) { logger.error("Error getting job info.", e); } }
From source file:conf.DBCPConnectionProvider.java
public void configure(Properties props) throws HibernateException { try {//from w w w . ja v a2 s. com log.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 String username = props.getProperty(Environment.USER); String password = props.getProperty(Environment.PASS); dbcpProperties.put("username", username); 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 (log.isDebugEnabled()) { log.debug("Creating a DBCP BasicDataSource with the following DBCP factory properties:"); StringWriter sw = new StringWriter(); dbcpProperties.list(new PrintWriter(sw, true)); log.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"; log.fatal(message, e); if (ds != null) { try { ds.close(); } catch (Exception e2) { // ignore } ds = null; } throw new HibernateException(message, e); } log.debug("Configure DBCPConnectionProvider complete"); }
From source file:org.apache.jsieve.ConfigurationManager.java
private ConcurrentMap<String, String> loadConfiguration(final String name) throws IOException { final Properties properties = loadProperties(name); final ConcurrentMap<String, String> result = new ConcurrentHashMap<String, String>(properties.size(), 1.0f, initialConcurrencyLevel);//from w ww . j av a2s . c om for (final Map.Entry<Object, Object> entry : properties.entrySet()) { result.put(entry.getKey().toString(), entry.getValue().toString()); } return result; }
From source file:org.agiso.tempel.Tempel.java
public Tempel() { // Odczytujemy waciwoci systemowe i zapamitujemy je w mapie systemProperties: Properties properties = System.getProperties(); Map<String, Object> map = new HashMap<String, Object>(properties.size()); for (String key : properties.stringPropertyNames()) { map.put(key.replace('.', '_'), properties.getProperty(key)); }/* ww w.j av a 2s.c om*/ systemProperties = Collections.unmodifiableMap(map); }
From source file:org.intermine.web.struts.BagBuildController.java
/** * Set up environment for the buildBag page. * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * @return an ActionForward object defining where control goes next * * @exception Exception if an error occurs *///from w w w .jav a 2s . c o m @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); final InterMineAPI im = SessionMethods.getInterMineAPI(session); Model model = im.getModel(); ObjectStore os = im.getObjectStore(); ObjectStoreSummary oss = im.getObjectStoreSummary(); Collection<String> qualifiedTypes = model.getClassNames(); ArrayList<String> typeList = new ArrayList(); ArrayList<String> preferedTypeList = new ArrayList(); TagManager tagManager = im.getTagManager(); List<Tag> preferredBagTypeTags = tagManager.getTags("im:preferredBagType", null, "class", im.getProfileManager().getSuperuser()); for (Tag tag : preferredBagTypeTags) { preferedTypeList.add(TypeUtil.unqualifiedName(tag.getObjectIdentifier())); } Map<String, List<FieldDescriptor>> classKeys = im.getClassKeys(); for (Iterator<String> iter = qualifiedTypes.iterator(); iter.hasNext();) { String className = iter.next(); String unqualifiedName = TypeUtil.unqualifiedName(className); if (ClassKeyHelper.hasKeyFields(classKeys, unqualifiedName) && oss.getClassCount(className) > 0) { typeList.add(unqualifiedName); } } Collections.sort(preferedTypeList); Collections.sort(typeList); request.setAttribute("typeList", typeList); request.setAttribute("preferredTypeList", preferedTypeList); BagQueryConfig bagQueryConfig = im.getBagQueryConfig(); String extraClassName = bagQueryConfig.getExtraConstraintClassName(); if (extraClassName != null) { request.setAttribute("extraBagQueryClass", TypeUtil.unqualifiedName(extraClassName)); List extraClassFieldValues = getFieldValues(os, oss, extraClassName, bagQueryConfig.getConstrainField()); request.setAttribute("extraClassFieldValues", extraClassFieldValues); // find the types in typeList that contain a field with the name given by // bagQueryConfig.getConnectField() List<String> typesWithConnectingField = new ArrayList<String>(); Iterator<String> allTypesIterator = new IteratorChain(typeList.iterator(), preferedTypeList.iterator()); while (allTypesIterator.hasNext()) { String connectFieldName = bagQueryConfig.getConnectField(); String typeName = allTypesIterator.next(); String qualifiedTypeName = model.getPackageName() + "." + typeName; ClassDescriptor cd = model.getClassDescriptorByName(qualifiedTypeName); FieldDescriptor fd = cd.getFieldDescriptorByName(connectFieldName); if (fd != null && fd instanceof ReferenceDescriptor) { typesWithConnectingField.add(typeName); } } request.setAttribute("typesWithConnectingField", typesWithConnectingField); final String defaultValue = getDefaultValue(request, im); if (StringUtils.isNotEmpty(defaultValue)) { BuildBagForm bbf = (BuildBagForm) form; bbf.setExtraFieldValue(defaultValue); } } // get example bag values String bagExampleIdentifiersPropertiesKey = "bag.example.identifiers"; ServletContext servletContext = session.getServletContext(); Properties properties = SessionMethods.getWebProperties(servletContext); Properties bagExampleIdentifiers = PropertiesUtil .getPropertiesStartingWith(bagExampleIdentifiersPropertiesKey, properties); if (bagExampleIdentifiers.size() != 0) { Map<String, String> bagExampleIdentifiersMap = new HashMap<String, String>(); Enumeration<?> e = bagExampleIdentifiers.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = bagExampleIdentifiers.getProperty(key); if (key.equals(bagExampleIdentifiersPropertiesKey)) { bagExampleIdentifiersMap.put("default", value); } else { bagExampleIdentifiersMap.put(key.replace(bagExampleIdentifiersPropertiesKey + ".", ""), value); } bagExampleIdentifiers.getProperty(key); } request.setAttribute("bagExampleIdentifiers", bagExampleIdentifiersMap); } return null; }