List of usage examples for java.util Properties list
public void list(PrintWriter out)
From source file:de.innovationgate.webgate.api.jdbc.pool.DBCPConnectionProvider.java
public void configure(Map propsMap) throws HibernateException { try {//from w w w. ja v a2s . c o m log.debug("Configure DBCPConnectionProvider"); Properties props = new Properties(); props.putAll(propsMap); String jdbcUrl = (String) props.getProperty(Environment.URL); // DBCP properties used to create the BasicDataSource Properties dbcpProperties = new Properties(); // DriverClass & url String jdbcDriverClass = props.getProperty(Environment.DRIVER); // Try to determine driver by jdbc-URL if (jdbcDriverClass == null) { Driver driver = DriverManager.getDriver(jdbcUrl); if (driver != null) { jdbcDriverClass = driver.getClass().getName(); } else { throw new HibernateException("Driver class not available"); } } dbcpProperties.put("driverClassName", jdbcDriverClass); dbcpProperties.put("url", jdbcUrl); // Username / 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 = ConnectionProviderInitiator.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)); } if (props.getProperty(DBCP_MAXACTIVE) != null) { dbcpProperties.put("maxTotal", props.getProperty(DBCP_MAXACTIVE)); } if (props.getProperty(DBCP_MAXWAIT) != null) { dbcpProperties.put("maxWaitMillis", props.getProperty(DBCP_MAXWAIT)); } // 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()); } String dbKey = (String) props.get("hibernate.dbcp.dbkey"); String databaseServerId = (String) props.get("hibernate.dbcp.dbserver.id"); // Enable DBCP2 JMX monitoring information if (dbKey != null) { dbcpProperties.put("jmxName", JMX_DBCP2_DBPOOLS_ADDRESS + ",pool=" + JmxManager.normalizeJmxKey(dbKey)); } else if (databaseServerId != null) { String entityTitle = props.getProperty("hibernate.dbcp.dbserver.title"); dbcpProperties.put("jmxName", JMX_DBCP2_SERVERPOOLS_ADDRESS + ",pool=" + JmxManager.normalizeJmxKey(entityTitle)); } // Let the factory create the pool _ds = BasicDataSourceFactory.createDataSource(dbcpProperties); _ds.setLogExpiredConnections(false); // 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(); // Create Legacy JMX monitoring information, provided by WGA if ("true".equals(props.getProperty("hibernate.dbcp.legacyJMX"))) { try { if (dbKey != null) { _entityKey = dbKey; _entityTitle = dbKey; _jmxManager = new JmxManager(new DBCPPoolInformation(this), new ObjectName(JMX_DBPOOLS_ADDRESS + ",pool=" + JmxManager.normalizeJmxKey(dbKey))); } else if (databaseServerId != null) { _server = true; _entityKey = databaseServerId; _entityTitle = (String) props.get("hibernate.dbcp.dbserver.title"); _jmxManager = new JmxManager(new DBCPPoolInformation(this), new ObjectName( JMX_SERVERPOOLS_ADDRESS + ",pool=" + JmxManager.normalizeJmxKey(_entityTitle))); } } catch (Throwable e) { log.error("Error enabling JMX metrics for connection pool", e); } } } catch (Exception e) { String message = "Could not create a DBCP pool"; 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.eurocarbdb.application.glycoworkbench.plugin.s3.Cockpit.java
/** * Event handler for this application, handles all menu items. */// w ww . j a v a 2 s . c o m public void actionPerformed(ActionEvent event) { // Service Menu Events if ("LoginEvent".equals(event.getActionCommand())) { loginEvent(null); } else if ("LogoutEvent".equals(event.getActionCommand())) { logoutEvent(); } else if (event.getActionCommand() != null && event.getActionCommand().startsWith("LoginSwitch")) { String loginName = event.getActionCommand().substring("LoginSwitch:".length()); AWSCredentials awsCredentials = (AWSCredentials) loginAwsCredentialsMap.get(loginName); loginEvent(awsCredentials); } else if ("QuitEvent".equals(event.getActionCommand())) { System.exit(0); } // Bucket Events. else if ("ViewBucketProperties".equals(event.getActionCommand())) { listBucketProperties(); } else if ("RefreshBuckets".equals(event.getActionCommand())) { listAllBuckets(); } else if ("CreateBucket".equals(event.getActionCommand())) { createBucketAction(); } else if ("DeleteBucket".equals(event.getActionCommand())) { deleteSelectedBucket(); } else if ("ManageDistributions".equals(event.getActionCommand())) { S3Bucket[] buckets = bucketTableModel.getBuckets(); String[] bucketNames = new String[buckets.length]; for (int i = 0; i < buckets.length; i++) { bucketNames[i] = buckets[i].getName(); } ManageDistributionsDialog.showDialog(ownerFrame, cloudFrontService, bucketNames, this); } else if ("AddThirdPartyBucket".equals(event.getActionCommand())) { addThirdPartyBucket(); } else if ("UpdateBucketACL".equals(event.getActionCommand())) { updateBucketAccessControlList(); } else if ("UpdateBucketRequesterPaysStatus".equals(event.getActionCommand())) { updateBucketRequesterPaysSetting(); } // Object Events else if ("ViewOrModifyObjectAttributes".equals(event.getActionCommand())) { displayObjectsAttributesDialog(); } else if ("CopyObjects".equals(event.getActionCommand())) { copyObjects(); } else if ("RefreshObjects".equals(event.getActionCommand())) { listObjects(); } else if ("UpdateObjectACL".equals(event.getActionCommand())) { displayAclModificationDialog(); } else if ("GeneratePublicGetURLs".equals(event.getActionCommand())) { generatePublicGetUrls(); } else if ("GenerateTorrentURL".equals(event.getActionCommand())) { generateTorrentUrl(); } else if ("DeleteObjects".equals(event.getActionCommand())) { deleteSelectedObjects(); } else if ("DownloadObjects".equals(event.getActionCommand())) { downloadSelectedObjects(); } else if ("UploadFiles".equals(event.getActionCommand())) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); fileChooser.setDialogTitle("Choose files to upload"); fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); fileChooser.setApproveButtonText("Upload files"); fileChooser.setCurrentDirectory(fileChoosersLastUploadDirectory); int returnVal = fileChooser.showOpenDialog(ownerFrame); if (returnVal != JFileChooser.APPROVE_OPTION) { return; } final File[] uploadFiles = fileChooser.getSelectedFiles(); if (uploadFiles.length == 0) { return; } // Save the chosen directory location for next time. fileChoosersLastUploadDirectory = uploadFiles[0].getParentFile(); uploadFiles(uploadFiles); } else if (event.getSource().equals(filterObjectsCheckBox)) { if (filterObjectsCheckBox.isSelected()) { filterObjectsPanel.setVisible(true); } else { filterObjectsPanel.setVisible(false); filterObjectsPrefix.setText(""); if (filterObjectsDelimiter.getSelectedIndex() != 0) { filterObjectsDelimiter.setSelectedIndex(0); } } } // Tools events else if ("BucketLogging".equals(event.getActionCommand())) { S3Bucket[] buckets = bucketTableModel.getBuckets(); BucketLoggingDialog.showDialog(ownerFrame, s3ServiceMulti.getS3Service(), buckets, this); } // Preference Events else if ("PreferencesDialog".equals(event.getActionCommand())) { PreferencesDialog.showDialog(cockpitPreferences, ownerFrame, this); // Save a user's preferences if requested, otherwise wipe any existing preferences file. File cockpitPreferencesPropertiesFile = new File(cockpitHomeDirectory, Constants.COCKPIT_PROPERTIES_FILENAME); if (cockpitPreferences.isRememberPreferences()) { try { Properties properties = cockpitPreferences.toProperties(); if (!cockpitHomeDirectory.exists()) { cockpitHomeDirectory.mkdir(); } properties.list(new PrintStream(new FileOutputStream(cockpitPreferencesPropertiesFile))); } catch (IOException e) { String message = "Unable to save your preferences"; log.error(message, e); ErrorDialog.showDialog(ownerFrame, this, message, e); } } else if (cockpitPreferencesPropertiesFile.exists()) { // User elected not to store preferences, delete the existing preferences file. cockpitPreferencesPropertiesFile.delete(); } if (cockpitPreferences.isEncryptionPasswordSet()) { try { encryptionUtil = new EncryptionUtil(cockpitPreferences.getEncryptionPassword(), cockpitPreferences.getEncryptionAlgorithm(), EncryptionUtil.DEFAULT_VERSION); } catch (Exception e) { String message = "Unable to start encryption utility"; log.error(message, e); ErrorDialog.showDialog(ownerFrame, this, message, e); } } else { encryptionUtil = null; } } // Ooops... else { log.debug("Unrecognised ActionEvent command '" + event.getActionCommand() + "' in " + event); } }
From source file:org.gbif.occurrence.download.oozie.ArchiveBuilder.java
/** * Entry point for assembling the dwc archive. * The thrown exception is the only way of telling Oozie that this job has failed. * * @throws IOException if any read/write operation failed *///w w w. j a v a2 s .co m public static void main(String[] args) throws IOException { final String nameNode = args[0]; // same as namenode, like hdfs://c1n2.gbif.org:8020 final String hdfsHivePath = args[1]; // path on hdfs to hive results final String interpretedDataTable = args[2]; // hive occurrence results table final String verbatimDataTable = args[3]; // hive occurrence results table final String multimediaDataTable = args[4]; // hive multimedia results table final String citationTable = args[5]; // hive citation results table final String downloadDir = args[6]; // locally mounted download dir // for example 0000020-130108132303336 final String downloadId = DownloadUtils.workflowToDownloadId(args[7]); final String username = args[8]; // download user final String query = args[9]; // download query filter final String downloadLink = args[10]; // download link to the final zip archive final String registryWs = args[11]; // registry ws url final String isSmallDownload = args[12]; // isSmallDownload // download link needs to be constructed final String downloadLinkWithId = downloadLink.replace(DownloadUtils.DOWNLOAD_ID_PLACEHOLDER, downloadId); // create temporary, local, download specific directory File archiveDir = new File(downloadDir, downloadId); RegistryClientUtil registryClientUtil = new RegistryClientUtil(); // create registry client and services DatasetService datasetService = registryClientUtil.setupDatasetService(registryWs); DatasetOccurrenceDownloadUsageService datasetUsageService = registryClientUtil .setupDatasetUsageService(registryWs); OccurrenceDownloadService occurrenceDownloadService = registryClientUtil .setupOccurrenceDownloadService(registryWs); // create drupal mybatis service Properties p = PropertiesUtil.loadProperties(RegistryClientUtil.OCC_PROPERTIES); // debug used properties in oozie logs StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); p.list(pw); LOG.info("ArchiveBuilder uses properties:\n{}", sw); Injector inj = Guice.createInjector(new DrupalMyBatisModule(p), new TitleLookupModule(true, p.getProperty("api.url"))); UserService userService = inj.getInstance(UserService.class); User user = Preconditions.checkNotNull(userService.get(username), "Unknown user " + username); TitleLookup titleLookup = inj.getInstance(TitleLookup.class); // filesystem configs Configuration conf = new Configuration(); conf.set(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY, nameNode); FileSystem hdfs = FileSystem.get(conf); FileSystem localfs = FileSystem.getLocal(conf); // build archive ArchiveBuilder generator = new ArchiveBuilder(downloadId, user, query, datasetService, datasetUsageService, occurrenceDownloadService, conf, hdfs, localfs, archiveDir, interpretedDataTable, verbatimDataTable, multimediaDataTable, citationTable, hdfsHivePath, downloadLinkWithId, titleLookup, Boolean.parseBoolean(isSmallDownload)); LOG.info("ArchiveBuilder instance created with parameters:{}", Joiner.on(" ").skipNulls().join(args)); generator.buildArchive(new File(downloadDir, downloadId + ".zip")); // SUCCESS! }
From source file:org.hibernate.connection.DBCPConnectionProvider.java
public void configure(Properties props) throws HibernateException { try {/*w ww . j a va 2 s . c o 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.infoglue.common.dbcp.DBCPConnectionProvider.java
public void configure(Properties props) throws HibernateException { try {/*from w w 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:org.mili.ant.PropertiesReplacerImplTest.java
@Test public void testReplace_OneFilePropertyNotDefinedAndNotFoundButDefault() throws Exception { StringBuilder s = new StringBuilder(); s.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); s.append("<properties-description>\n"); s.append(" <property name=\"null\" type=\"string\">\n"); s.append(" <default>lala</default>\n"); s.append(" </property>\n"); s.append(/*from ww w. j a v a 2 s. c o m*/ " <replace-file name=\"./tmp/test_properties_description/xy.properties\" halt-on-error=\"true\">\n"); s.append(" <replace property=\"null\">\n"); s.append(" <what><![CDATA[x0.y0=1098]]></what>\n"); s.append(" <to><![CDATA[x0.y0=$1]]></to>\n"); s.append(" </replace>\n"); s.append(" </replace-file>\n"); s.append("</properties-description>\n"); FileUtils.writeStringToFile(xmlFile, s.toString()); PropertiesReplacerImpl pr = new PropertiesReplacerImpl(); try { pr.replace(propFile, xmlFile); } catch (IllegalStateException e) { fail("exception occured!"); } Properties p = new Properties(); InputStream is = new FileInputStream(xyFile); p.load(is); p.list(System.out); assertEquals("lala", p.getProperty("x0.y0")); }
From source file:org.mili.ant.PropertiesReplacerImplTest.java
@Test public void shouldReplacePropertyWithConverterClass() throws Exception { StringBuilder s = new StringBuilder(); s.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); s.append("<properties-description>\n"); s.append(" <property name=\"aaa\" type=\"string\">\n"); s.append(" <default>lala</default>\n"); s.append(" </property>\n"); s.append(//from w w w . j a v a 2s . c o m " <replace-file name=\"./tmp/test_properties_description/xy.properties\" halt-on-error=\"true\">\n"); s.append(" <replace property=\"aaa\" converter-class=\"org.mili.ant.UpperCaseConverter\">\n"); s.append(" <what><![CDATA[x0.y0=1098]]></what>\n"); s.append(" <to><![CDATA[x0.y0=$1]]></to>\n"); s.append(" </replace>\n"); s.append(" </replace-file>\n"); s.append("</properties-description>\n"); FileUtils.writeStringToFile(xmlFile, s.toString()); PropertiesReplacerImpl pr = new PropertiesReplacerImpl(); pr.replace(propFile, xmlFile); Properties p = new Properties(); InputStream is = new FileInputStream(xyFile); p.load(is); p.list(System.out); assertEquals("LALA", p.getProperty("x0.y0")); }
From source file:org.openflamingo.engine.handler.PigHandler.java
private String getPropertyFile(Pig pig) { Properties props = new Properties(); props.put("fs.default.name", hadoopCluster.getHdfsUrl()); props.put("mapred.job.tracker", hadoopCluster.getJobTrackerIP() + ":" + hadoopCluster.getJobTrackerPort()); if (pig.getVariables() != null && pig.getVariables().getVariable().size() > 0) { List<Variable> vars = pig.getVariables().getVariable(); for (Variable variable : vars) { props.put(variable.getName(), get(variable.getValue())); }//from w ww . ja v a2s .c om } if (pig.getConfiguration() != null && pig.getConfiguration().getVariable() != null) { List<Variable> vars = pig.getConfiguration().getVariable(); for (Variable var : vars) { props.put(var.getName(), get(var.getValue())); } } StringWriter writer = new StringWriter(); props.list(new PrintWriter(writer)); String properties = writer.getBuffer().toString(); logger.debug("Properties ?? ? ? .\n{}", properties); return properties; }
From source file:org.talend.mdm.webapp.general.server.util.GxtFactory.java
private Properties loadProperties(String location) throws IOException { Enumeration<URL> resourceUrls = getClass().getClassLoader().getResources(location); Properties props = new Properties(); URL url;//from ww w. j a va 2 s . c o m while (resourceUrls.hasMoreElements()) { url = resourceUrls.nextElement(); if (LOG.isDebugEnabled()) { LOG.debug("Loading properties from " + url.getFile()); //$NON-NLS-1$ } InputStream is = null; try { is = url.openStream(); props.load(is); } finally { try { if (is != null) { is.close(); } } catch (Exception e) { LOG.error(e.getMessage(), e); } } } if (LOG.isDebugEnabled()) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); props.list(pw); LOG.debug("-- " + location + " --"); //$NON-NLS-1$ //$NON-NLS-2$ LOG.debug(sw.toString()); } return props; }
From source file:persistence.utils.CustomDBCPConnectionProvider.java
/** * Configuracion de DBCP.//w w w. j av a 2 s . c om * * @param props * @exception HibernateException */ @SuppressWarnings("unchecked") public void configure(Properties props) throws HibernateException { try { if (logger.isDebugEnabled()) { logger.debug("Configure CustomDBCPConnectionProvider"); } // DBCP properties used to create the BasicDataSource Properties dbcpProperties = new Properties(); // si estan seteadas estas propiedades cambio el Properties parametro // por el que me retorna el EncryptManager // TODO reveer // Username / password String username = props.getProperty(Environment.USER); String password = props.getProperty(Environment.PASS); dbcpProperties.put("username", username); dbcpProperties.put("password", password); // DriverClass & url String jdbcDriverClass = props.getProperty(Environment.DRIVER); String jdbcUrl = props.getProperty(Environment.URL); dbcpProperties.put("driverClassName", jdbcDriverClass); dbcpProperties.put("url", jdbcUrl); // 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 setDs((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 = getDs().getConnection(); conn.close(); // Log pool statistics before continuing. logStatistics(); } catch (Exception e) { String message = "Could not create a DBCP pool"; logger.fatal(message, e); if (getDs() != null) { try { getDs().close(); } catch (Exception e2) { if (logger.isDebugEnabled()) { logger.debug("Cannot close DBCP pool (not initialized)"); } } setDs(null); } throw new HibernateException(message, e); } if (logger.isDebugEnabled()) { logger.debug("Configure CustomDBCPConnectionProvider complete"); } }