Example usage for java.util Properties put

List of usage examples for java.util Properties put

Introduction

In this page you can find the example usage for java.util Properties put.

Prototype

@Override
    public synchronized Object put(Object key, Object value) 

Source Link

Usage

From source file:com.jkoolcloud.tnt4j.streams.inputs.KafkaStream.java

/**
 * Updates provided properties set by setting property value if properties has no such property yet set or property
 * value is empty.//from  ww w.  java 2s .c o m
 *
 * @param props
 *            properties to update
 * @param key
 *            property name
 * @param value
 *            property value to set
 * @return flag indicating whether property was updated - {@code true}, {@code false} if not
 */
protected static boolean putIfAbsent(Properties props, String key, Object value) {
    if (StringUtils.isEmpty(props.getProperty(key))) {
        props.put(key, String.valueOf(value));

        return true;
    }

    return false;
}

From source file:atg.tools.dynunit.test.util.DBUtils.java

/**
 * Returns a Properties object pre-configured to create
 * an HSQLDB in memory database connecting with user "sa"
 * password ""/* ww w .  java 2 s . co m*/
 *
 * @param databaseFileName
 */
@NotNull
public static Properties getHSQLDBFileDBConnection(String databaseFileName) {
    Properties props = new Properties();
    props.put("driver", "org.hsqldb.jdbcDriver");
    props.put("URL", "jdbc:hsqldb:file:" + databaseFileName);
    props.put("user", "sa");
    props.put("password", "");
    return props;
}

From source file:atg.tools.dynunit.test.util.DBUtils.java

/**
 * Returns a Properties object pre-configured to create
 * an HSQLDB in memory database connecting with user "sa"
 * password ""//from w w w  .j  a  v a2  s .  com
 *
 * @param databaseName
 */
@NotNull
public static Properties getHSQLDBRegularDBConnection(String databaseName, String hostName, Object user,
        Object password) {
    Properties props = new Properties();
    props.put("driver", "org.hsqldb.jdbcDriver");
    props.put("URL", "jdbc:hsqldb:hsql://" + hostName + "/" + databaseName);
    props.put("user", user);
    props.put("password", password);
    return props;
}

From source file:atg.tools.dynunit.test.util.DBUtils.java

@NotNull
public static Properties getDB2DBConnection(String hostName, String port, String databaseName, String user,
        String password) {/*from   w w  w  . j  av a  2s  . co  m*/
    Properties props = new Properties();
    props.put("driver", "com.ibm.db2.jcc.DB2Driver");
    //    props.put("driver", "COM.ibm.db2.jdbc.app.DB2Drive");
    props.put("URL", "jdbc:db2://" + hostName + ":" + port + "/" + databaseName);
    props.put("user", user);
    props.put("password", password);
    return props;
}

From source file:atg.tools.dynunit.test.util.DBUtils.java

/**
 * Returns connection properties for MSSQL
 *
 * @param hostName// w ww .  j av  a  2  s .  c o m
 *         host name of db server
 * @param port
 *         port number of db
 * @param databaseName
 *         database name
 * @param user
 *         database username
 * @param password
 *         database user's password
 *
 * @return
 */

@NotNull
public static Properties getMSSQLDBConnection(String hostName, String port, String databaseName, String user,
        String password) {
    Properties props = new Properties();
    props.put("driver", "com.inet.tds.TdsDriver");
    props.put("URL", "jdbc:inetdae:" + hostName + ":" + port + "?database=" + databaseName);
    props.put("user", user);
    props.put("password", password);
    return props;
}

From source file:atg.tools.dynunit.test.util.DBUtils.java

/**
 * Returns a Properties object pre-configured to create
 * an HSQLDB in memory database connecting with user "sa"
 * password ""./*from w  w w .jav a  2s . c  o  m*/
 *
 * @param databaseName name of database or {@code null} to use the default in-memory database.
 * @return connection properties for initializing this database.
 */
@NotNull
public static Properties getHSQLDBInMemoryDBConnection(@Nullable String databaseName) {
    Properties props = new Properties();
    props.put("driver", "org.hsqldb.jdbcDriver");
    if (databaseName != null) {
        props.put("URL", "jdbc:hsqldb:mem:" + databaseName);
    } else {
        props.put("URL", "jdbc:hsqldb:.");
    }
    props.put("user", "sa");
    props.put("password", "");
    return props;
}

From source file:atg.tools.dynunit.test.util.DBUtils.java

/**
 * Returns connection properties for mysql
 *
 * @param hostName/*w  ww  .j  a  v a2s  .c  o  m*/
 *         host name of db server
 * @param port
 *         port number of db (or null to use default of 3306)
 * @param databaseName
 *         database name
 * @param user
 *         database username
 * @param password
 *         database user's password
 *
 * @return
 */

@NotNull
public static Properties getMySQLDBConnection(@NotNull String hostName, @Nullable String port,
        @NotNull String databaseName, @NotNull String user, @NotNull String password) {
    if (port == null) {
        port = "3306";
    }
    Properties props = new Properties();
    props.put("driver", "com.mysql.jdbc.Driver");
    props.put("URL", "jdbc:mysql://" + hostName + ":" + port + "/" + databaseName);
    props.put("user", user);
    props.put("password", password);
    return props;
}

From source file:com.netflix.config.util.ConfigurationUtils.java

/**
 * Utility method to obtain <code>Properties</code> given an instance of <code>AbstractConfiguration</code>.
 * Returns an empty <code>Properties</code> object if the config has no properties or is null.
 * @param config Configuration to get the properties
 * @return properties extracted from the configuration
 *///from   www . ja  va2  s. c  om
public static Properties getProperties(Configuration config) {
    Properties p = new Properties();
    if (config != null) {
        Iterator<String> it = config.getKeys();
        while (it.hasNext()) {
            String key = it.next();
            if (key != null) {
                Object value = config.getProperty(key);
                if (value != null) {
                    p.put(key, value);
                }
            }
        }
    }
    return p;
}

From source file:com.enonic.cms.framework.util.PropertiesUtil.java

/**
 * Interpolate properties names like ${..}.
 *///from w  ww .ja v a 2  s  . co  m
public static Properties interpolate(final Properties props) {
    Properties target = new Properties();

    Properties source = new Properties();
    source.putAll(System.getProperties());
    source.putAll(props);

    StrLookup lookup = StrLookup.mapLookup(source);
    StrSubstitutor substitutor = new StrSubstitutor(lookup);

    for (Object key : props.keySet()) {
        String value = props.getProperty((String) key);

        try {
            value = substitutor.replace(value);
        } catch (IllegalStateException e) {
            // Do nothing
        }

        target.put(key, value);
    }

    return target;
}

From source file:fr.cls.atoll.motu.library.misc.utils.PropertiesUtilities.java

/**
 * Remove from <code>props</code> every properties for which key is not prefixed by the given
 * <code>prefix</code>.//from w w w .ja  va  2  s.  c  o m
 * 
 * @param props Properties to filter.
 * @param prefix Prefix used to filter
 * @param target properties destination
 * @return <code>props</code> eventually altered.
 */
public static Properties filterPropertiesByPrefix(Properties props, String prefix, Properties target) {
    if (props == null) {
        return null;
    }
    boolean modify = (props == target);
    for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
        Map.Entry entry = (Map.Entry) iter.next();
        String key = (String) entry.getKey();
        if (key.startsWith(prefix)) {
            if (!modify) {
                target.put(entry.getKey(), entry.getValue());
            }
        } else {
            if (modify) {
                iter.remove();
            }
        }
    }
    return props;
}