Example usage for java.util Properties Properties

List of usage examples for java.util Properties Properties

Introduction

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

Prototype

public Properties() 

Source Link

Document

Creates an empty property list with no default values.

Usage

From source file:com.fluke.database.DatabaseProperty.java

public static DataSource getDataSource() {
    if (source != null) {
        return source;
    }/*from   w w  w . jav  a 2s  . c om*/
    Properties props = new Properties();
    FileInputStream fis = null;

    BasicDataSource dataSource = new BasicDataSource();
    try {

        props.load(ClassLoader.getSystemResourceAsStream("config/mysql.properties"));
        dataSource.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS"));
        dataSource.setUrl(props.getProperty("MYSQL_DB_URL"));
        dataSource.setUsername(props.getProperty("MYSQL_DB_USERNAME"));
        dataSource.setPassword(props.getProperty("MYSQL_DB_PASSWORD"));

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return source = dataSource;
}

From source file:com.rhino.data.db.DataSourceFactory.java

public static DataSource getDataSource() {
    if (source != null) {
        return source;
    }//from   w w  w  . j av  a 2s . c o  m
    Properties props = new Properties();
    FileInputStream fis = null;

    BasicDataSource dataSource = new BasicDataSource();
    try {

        props.load(ClassLoader.getSystemResourceAsStream("mysql.properties"));
        dataSource.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS"));
        dataSource.setUrl(props.getProperty("MYSQL_DB_URL"));
        dataSource.setUsername(props.getProperty("MYSQL_DB_USERNAME"));
        dataSource.setPassword(props.getProperty("MYSQL_DB_PASSWORD"));

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return source = dataSource;
}

From source file:Main.java

public static Properties toProperties(Iterable<Map.Entry<String, String>> propSrc) {
    Properties props = new Properties();
    for (Map.Entry<String, String> entry : propSrc) {
        String name = entry.getKey();
        String val = entry.getValue();
        props.setProperty(name, val);
    }//  w  w w .j  av a2  s. c o m
    return props;
}

From source file:classes.connectionPool.java

public static void start_BasicDataSourceFactory() {
    Properties propiedades = new Properties();
    /*//from  www . j  a  v  a  2  s . com
    setMaxActive(): N mx de conexiones que se pueden abrir simultneamente.
    setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms.
    setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando.
    */

    propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver");
    propiedades.setProperty("url", "jdbc:mysql://127.0.0.1:3306/bbdd_admin");
    propiedades.setProperty("maxActive", "10");
    propiedades.setProperty("maxIdle", "8");
    propiedades.setProperty("minIdle", "0");
    propiedades.setProperty("maxWait", "500");
    propiedades.setProperty("initialSize", "5");
    propiedades.setProperty("defaultAutoCommit", "true");
    propiedades.setProperty("username", "root");
    propiedades.setProperty("password", "");
    propiedades.setProperty("validationQuery", "select 1");
    propiedades.setProperty("validationQueryTimeout", "100");
    propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2");
    propiedades.setProperty("poolPreparedStatements", "true");
    propiedades.setProperty("maxOpenPreparedStatements", "10");

    try {
        dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:framework.classes.PoolConexion.java

/**
 * CONFIGURE CONNECTION/*ww  w.j av a  2  s . co m*/
 */
public static void iniciar_BasicDataSourceFactory() {
    Properties propiedades = new Properties();
    /*
    setMaxActive(): N mx de conexiones que se pueden abrir simultneamente.
    setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms.
    setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando.
    */
    propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver");
    propiedades.setProperty("url", "jdbc:mysql://127.0.0.1:3306/SQL_BD");
    propiedades.setProperty("maxActive", "10");
    propiedades.setProperty("maxIdle", "8");
    propiedades.setProperty("minIdle", "0");
    propiedades.setProperty("maxWait", "500");
    propiedades.setProperty("initialSize", "5");
    propiedades.setProperty("defaultAutoCommit", "true");
    propiedades.setProperty("username", "root");
    propiedades.setProperty("password", "root");
    propiedades.setProperty("validationQuery", "select 1");
    propiedades.setProperty("validationQueryTimeout", "100");
    propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2");
    propiedades.setProperty("poolPreparedStatements", "true");
    propiedades.setProperty("maxOpenPreparedStatements", "10");

    try {
        //propiedades.load(new FileInputStream("src/config/datasource_config.properties"));
        dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}

From source file:com.mgmtp.jfunk.core.JFunk.java

/**
 * Starts jFunk./*from ww w.j  a v  a  2 s.  co  m*/
 * 
 * <pre>
 * -threadcount=&lt;count&gt;    Optional    Number of threads to be used. Allows for parallel
 *                                     execution of test scripts.
 * -parallel               Optional    Allows a single script to be executed in parallel
 *                                     depending on the number of threads specified. The
 *                                     argument is ignored if multiple scripts are specified.
 * &lt;script parameters&gt     Optional    Similar to Java system properties they can be provided
 *                                     as key-value-pairs preceded by -S, e.g. -Skey=value.
 *                                     These parameters are then available in the script as
 *                                     Groovy variables.
 * &lt;script(s)&gt;             Required    At least one test script must be specified.
 *
 * Example:
 * java -cp &lt;jFunkClasspath&gt; com.mgmtp.jfunk.core.JFunk -Skey=value -threadcount=4 -parallel mytest.script
 * </pre>
 * 
 * @param args
 *            The program arguments.
 */
public static void main(final String[] args) {
    SLF4JBridgeHandler.install();

    boolean exitWithError = true;
    StopWatch stopWatch = new StopWatch();

    try {
        RESULT_LOG.info("jFunk started");
        stopWatch.start();

        int threadCount = 1;
        boolean parallel = false;
        Properties scriptProperties = new Properties();
        List<File> scripts = Lists.newArrayList();

        for (String arg : args) {
            if (arg.startsWith("-threadcount")) {
                String[] split = arg.split("=");
                Preconditions.checkArgument(split.length == 2,
                        "The number of threads must be specified as follows: -threadcount=<value>");
                threadCount = Integer.parseInt(split[1]);
                RESULT_LOG.info("Using " + threadCount + (threadCount == 1 ? " thread" : " threads"));
            } else if (arg.startsWith("-S")) {
                arg = arg.substring(2);
                String[] split = arg.split("=");
                Preconditions.checkArgument(split.length == 2,
                        "Script parameters must be given in the form -S<name>=<value>");
                scriptProperties.setProperty(split[0], normalizeScriptParameterValue(split[1]));
                RESULT_LOG.info("Using script parameter " + split[0] + " with value " + split[1]);
            } else if (arg.equals("-parallel")) {
                parallel = true;
                RESULT_LOG.info("Using parallel mode");
            } else {
                scripts.add(new File(arg));
            }
        }

        if (scripts.isEmpty()) {
            scripts.addAll(requestScriptsViaGui());

            if (scripts.isEmpty()) {
                RESULT_LOG.info("Execution finished (took " + stopWatch + " H:mm:ss.SSS)");
                System.exit(0);
            }
        }

        String propsFileName = System.getProperty("jfunk.props.file", "jfunk.properties");
        Module module = ModulesLoader.loadModulesFromProperties(new JFunkDefaultModule(), propsFileName);
        Injector injector = Guice.createInjector(module);

        JFunkFactory factory = injector.getInstance(JFunkFactory.class);
        JFunkBase jFunk = factory.create(threadCount, parallel, scripts, scriptProperties);
        jFunk.execute();

        exitWithError = false;
    } catch (JFunkExecutionException ex) {
        // no logging necessary
    } catch (Exception ex) {
        Logger.getLogger(JFunk.class).error("jFunk terminated unexpectedly.", ex);
    } finally {
        stopWatch.stop();
        RESULT_LOG.info("Execution finished (took " + stopWatch + " H:mm:ss.SSS)");
    }

    System.exit(exitWithError ? -1 : 0);
}

From source file:Main.java

public static Properties paramsToProperties(Map<String, String> params) {
    Properties props = new Properties();
    props.putAll(params);//from  w w w .j a  v  a2  s .c  o  m
    return props;
}

From source file:Main.java

/**
 * Very similar to {@link System#getProperties()} except that the
 * {@link SecurityException} is absorbed.
 *
 * @return the system properties/*from w  ww.  jav  a  2s.c o  m*/
 */
public static Properties getSystemProperties() {
    try {
        return System.getProperties();
    } catch (SecurityException e) {
        return new Properties();
    }
}

From source file:Main.java

public static Connection connectToDatabase(String propertiesFileName) throws Exception {
    Properties dbProps = new Properties();
    Properties dumpProps = new Properties();
    dbProps.load(new FileInputStream(propertiesFileName));
    dumpProps.load(new FileInputStream(propertiesFileName));
    System.out.println("Database Properties");
    dumpProps.remove("password");
    dumpProps.list(System.out);/*from  w  ww.j a v a 2 s.co m*/
    System.out.println("Loading Driver");
    Class.forName(dbProps.getProperty("dbDriver"));

    System.out.println("Connecting to Database...");
    Connection con = DriverManager.getConnection(dbProps.getProperty("dbURL"), dbProps);
    System.out.println("Connected");
    return con;
}

From source file:application.bbdd.pool.java

public static void inicializa_BasicDataSourceFactory() {
    Properties propiedades = new Properties();
    /*/*from   w  w  w . j a  v a  2s. c o  m*/
    setMaxActive(): N mx de conexiones que se pueden abrir simultneamente.
    setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms.
    setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando.
    */
    propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver");
    propiedades.setProperty("url", "jdbc:mysql://127.0.0.1:3306/application");
    propiedades.setProperty("maxActive", "10");
    propiedades.setProperty("maxIdle", "8");
    propiedades.setProperty("minIdle", "0");
    propiedades.setProperty("maxWait", "500");
    propiedades.setProperty("initialSize", "5");
    propiedades.setProperty("defaultAutoCommit", "true");
    propiedades.setProperty("username", "root");
    propiedades.setProperty("password", "1234");
    propiedades.setProperty("validationQuery", "select 1");
    propiedades.setProperty("validationQueryTimeout", "100");
    propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2");
    propiedades.setProperty("poolPreparedStatements", "true");
    propiedades.setProperty("maxOpenPreparedStatements", "10");

    try {
        //propiedades.load(new FileInputStream("src/config/datasource_config.properties"));
        dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.toString());
    }
}