Java Code Examples for java.util.Properties.clone()

The following are Jave code examples for showing how to use clone() of the java.util.Properties class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenDiabetes   File: JDBCCommonDataSource.java   View Source Code Vote up 6 votes
/**
 * Sets connection properties. If user / password / loginTimeout has been
 * set with one of the setXXX() methods it will be added to the Properties
 * object.
 *
 * @param props properties.  If null, then existing properties will be
 *                           cleared/replaced.
 */
public void setProperties(Properties props) {

    connectionProps = (props == null) ? new Properties()
                                      : (Properties) props.clone();

    if (user != null) {
        connectionProps.setProperty("user", user);
    }

    if (password != null) {
        connectionProps.setProperty("password", password);
    }

    if (loginTimeout != 0) {
        connectionProps.setProperty("loginTimeout", Integer.toString(loginTimeout));
    }
}
 
Example 2
Project: the-vigilantes   File: MultiHostConnectionProxy.java   View Source Code Vote up 6 votes
/**
 * Initializes the hosts lists and makes a "clean" local copy of the given connection properties so that it can be later used to create standard
 * connections.
 * 
 * @param hosts
 *            The list of hosts for this multi-host connection.
 * @param props
 *            Connection properties from where to get initial settings and to be used in new connections.
 * @return
 *         The number of hosts found in the hosts list.
 */
int initializeHostsSpecs(List<String> hosts, Properties props) {
    this.autoReconnect = "true".equalsIgnoreCase(props.getProperty("autoReconnect")) || "true".equalsIgnoreCase(props.getProperty("autoReconnectForPools"));

    this.hostList = hosts;
    int numHosts = this.hostList.size();

    this.localProps = (Properties) props.clone();
    this.localProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
    this.localProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);

    for (int i = 0; i < numHosts; i++) {
        this.localProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY + "." + (i + 1));
        this.localProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY + "." + (i + 1));
    }

    this.localProps.remove(NonRegisteringDriver.NUM_HOSTS_PROPERTY_KEY);
    this.localProps.setProperty("useLocalSessionState", "true");

    return numHosts;
}
 
Example 3
Project: OpenVertretung   File: MultiHostConnectionProxy.java   View Source Code Vote up 6 votes
/**
 * Initializes the hosts lists and makes a "clean" local copy of the given connection properties so that it can be later used to create standard
 * connections.
 * 
 * @param hosts
 *            The list of hosts for this multi-host connection.
 * @param props
 *            Connection properties from where to get initial settings and to be used in new connections.
 * @return
 *         The number of hosts found in the hosts list.
 */
int initializeHostsSpecs(List<String> hosts, Properties props) {
    this.autoReconnect = "true".equalsIgnoreCase(props.getProperty("autoReconnect")) || "true".equalsIgnoreCase(props.getProperty("autoReconnectForPools"));

    this.hostList = hosts;
    int numHosts = this.hostList.size();

    this.localProps = (Properties) props.clone();
    this.localProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
    this.localProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);

    for (int i = 0; i < numHosts; i++) {
        this.localProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY + "." + (i + 1));
        this.localProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY + "." + (i + 1));
    }

    this.localProps.remove(NonRegisteringDriver.NUM_HOSTS_PROPERTY_KEY);
    this.localProps.setProperty("useLocalSessionState", "true");

    return numHosts;
}
 
Example 4
Project: lams   File: MultiHostConnectionProxy.java   View Source Code Vote up 6 votes
/**
 * Initializes the hosts lists and makes a "clean" local copy of the given connection properties so that it can be later used to create standard
 * connections.
 * 
 * @param hosts
 *            The list of hosts for this multi-host connection.
 * @param props
 *            Connection properties from where to get initial settings and to be used in new connections.
 * @return
 *         The number of hosts found in the hosts list.
 */
int initializeHostsSpecs(List<String> hosts, Properties props) {
    this.autoReconnect = "true".equalsIgnoreCase(props.getProperty("autoReconnect")) || "true".equalsIgnoreCase(props.getProperty("autoReconnectForPools"));

    this.hostList = hosts;
    int numHosts = this.hostList.size();

    this.localProps = (Properties) props.clone();
    this.localProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
    this.localProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);

    for (int i = 0; i < numHosts; i++) {
        this.localProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY + "." + (i + 1));
        this.localProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY + "." + (i + 1));
    }

    this.localProps.remove(NonRegisteringDriver.NUM_HOSTS_PROPERTY_KEY);
    this.localProps.setProperty("useLocalSessionState", "true");

    return numHosts;
}
 
Example 5
Project: ProyectoPacientes   File: MultiHostConnectionProxy.java   View Source Code Vote up 6 votes
/**
 * Initializes the hosts lists and makes a "clean" local copy of the given connection properties so that it can be later used to create standard
 * connections.
 * 
 * @param hosts
 *            The list of hosts for this multi-host connection.
 * @param props
 *            Connection properties from where to get initial settings and to be used in new connections.
 * @return
 *         The number of hosts found in the hosts list.
 */
int initializeHostsSpecs(List<String> hosts, Properties props) {
    this.autoReconnect = "true".equalsIgnoreCase(props.getProperty("autoReconnect")) || "true".equalsIgnoreCase(props.getProperty("autoReconnectForPools"));

    this.hostList = hosts;
    int numHosts = this.hostList.size();

    this.localProps = (Properties) props.clone();
    this.localProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
    this.localProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);

    for (int i = 0; i < numHosts; i++) {
        this.localProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY + "." + (i + 1));
        this.localProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY + "." + (i + 1));
    }

    this.localProps.remove(NonRegisteringDriver.NUM_HOSTS_PROPERTY_KEY);
    this.localProps.setProperty("useLocalSessionState", "true");

    return numHosts;
}
 
Example 6
Project: dev-courses   File: JDBCCommonDataSource.java   View Source Code Vote up 6 votes
/**
 * Sets connection properties. If user / password / logginTimeout has been
 * set with one of the setXXX() methods it will be added to the Properties
 * object.
 *
 * @param props properties.  If null, then existing properties will be
 *                           cleared/replaced.
 */
public void setProperties(Properties props) {

    connectionProps = (props == null) ? new Properties()
                                      : (Properties) props.clone();

    if (user != null) {
        props.setProperty("user", user);
    }

    if (password != null) {
        props.setProperty("password", password);
    }

    if (loginTimeout != 0) {
        props.setProperty("loginTimeout", Integer.toString(loginTimeout));
    }
}
 
Example 7
Project: BibliotecaPS   File: MultiHostConnectionProxy.java   View Source Code Vote up 6 votes
/**
 * Initializes the hosts lists and makes a "clean" local copy of the given connection properties so that it can be later used to create standard
 * connections.
 * 
 * @param hosts
 *            The list of hosts for this multi-host connection.
 * @param props
 *            Connection properties from where to get initial settings and to be used in new connections.
 * @return
 *         The number of hosts found in the hosts list.
 */
int initializeHostsSpecs(List<String> hosts, Properties props) {
    this.autoReconnect = "true".equalsIgnoreCase(props.getProperty("autoReconnect")) || "true".equalsIgnoreCase(props.getProperty("autoReconnectForPools"));

    this.hostList = hosts;
    int numHosts = this.hostList.size();

    this.localProps = (Properties) props.clone();
    this.localProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
    this.localProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);

    for (int i = 0; i < numHosts; i++) {
        this.localProps.remove(NonRegisteringDriver.HOST_PROPERTY_KEY + "." + (i + 1));
        this.localProps.remove(NonRegisteringDriver.PORT_PROPERTY_KEY + "." + (i + 1));
    }

    this.localProps.remove(NonRegisteringDriver.NUM_HOSTS_PROPERTY_KEY);
    this.localProps.setProperty("useLocalSessionState", "true");

    return numHosts;
}
 
Example 8
Project: the-vigilantes   File: ConnectionPropertiesImpl.java   View Source Code Vote up 5 votes
/**
 * Initializes driver properties that come from URL or properties passed to
 * the driver manager.
 * 
 * @param info
 * @throws SQLException
 */
protected void initializeProperties(Properties info) throws SQLException {
    if (info != null) {
        // For backwards-compatibility
        String profileSqlLc = info.getProperty("profileSql");

        if (profileSqlLc != null) {
            info.put("profileSQL", profileSqlLc);
        }

        Properties infoCopy = (Properties) info.clone();

        infoCopy.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.USER_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.DBNAME_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);
        infoCopy.remove("profileSql");

        int numPropertiesToSet = PROPERTY_LIST.size();

        for (int i = 0; i < numPropertiesToSet; i++) {
            java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

            try {
                ConnectionProperty propToSet = (ConnectionProperty) propertyField.get(this);

                propToSet.initializeFrom(infoCopy, getExceptionInterceptor());
            } catch (IllegalAccessException iae) {
                throw SQLError.createSQLException(Messages.getString("ConnectionProperties.unableToInitDriverProperties") + iae.toString(),
                        SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
            }
        }

        postInitialization();
    }
}
 
Example 9
Project: calcite-avatica   File: RemoteMetaTest.java   View Source Code Vote up 5 votes
@Test public void testDriverProperties() throws Exception {
  final Properties props = new Properties();
  props.setProperty("foo", "bar");
  final Properties originalProps = (Properties) props.clone();
  try (final Connection conn = DriverManager.getConnection(url, props)) {
    // The contents of the two properties objects should not have changed after connecting.
    assertEquals(props, originalProps);
  }
}
 
Example 10
Project: OpenVertretung   File: ConnectionPropertiesImpl.java   View Source Code Vote up 5 votes
/**
 * Initializes driver properties that come from URL or properties passed to
 * the driver manager.
 * 
 * @param info
 * @throws SQLException
 */
protected void initializeProperties(Properties info) throws SQLException {
    if (info != null) {
        // For backwards-compatibility
        String profileSqlLc = info.getProperty("profileSql");

        if (profileSqlLc != null) {
            info.put("profileSQL", profileSqlLc);
        }

        Properties infoCopy = (Properties) info.clone();

        infoCopy.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.USER_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.DBNAME_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);
        infoCopy.remove("profileSql");

        int numPropertiesToSet = PROPERTY_LIST.size();

        for (int i = 0; i < numPropertiesToSet; i++) {
            java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

            try {
                ConnectionProperty propToSet = (ConnectionProperty) propertyField.get(this);

                propToSet.initializeFrom(infoCopy, getExceptionInterceptor());
            } catch (IllegalAccessException iae) {
                throw SQLError.createSQLException(Messages.getString("ConnectionProperties.unableToInitDriverProperties") + iae.toString(),
                        SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
            }
        }

        postInitialization();
    }
}
 
Example 11
Project: lams   File: ConnectionPropertiesImpl.java   View Source Code Vote up 5 votes
/**
 * Initializes driver properties that come from URL or properties passed to
 * the driver manager.
 * 
 * @param info
 * @throws SQLException
 */
protected void initializeProperties(Properties info) throws SQLException {
    if (info != null) {
        // For backwards-compatibility
        String profileSqlLc = info.getProperty("profileSql");

        if (profileSqlLc != null) {
            info.put("profileSQL", profileSqlLc);
        }

        Properties infoCopy = (Properties) info.clone();

        infoCopy.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.USER_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.DBNAME_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);
        infoCopy.remove("profileSql");

        int numPropertiesToSet = PROPERTY_LIST.size();

        for (int i = 0; i < numPropertiesToSet; i++) {
            java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

            try {
                ConnectionProperty propToSet = (ConnectionProperty) propertyField.get(this);

                propToSet.initializeFrom(infoCopy, getExceptionInterceptor());
            } catch (IllegalAccessException iae) {
                throw SQLError.createSQLException(Messages.getString("ConnectionProperties.unableToInitDriverProperties") + iae.toString(),
                        SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
            }
        }

        postInitialization();
    }
}
 
Example 12
Project: ProyectoPacientes   File: ConnectionPropertiesImpl.java   View Source Code Vote up 5 votes
/**
 * Initializes driver properties that come from URL or properties passed to
 * the driver manager.
 * 
 * @param info
 * @throws SQLException
 */
protected void initializeProperties(Properties info) throws SQLException {
    if (info != null) {
        // For backwards-compatibility
        String profileSqlLc = info.getProperty("profileSql");

        if (profileSqlLc != null) {
            info.put("profileSQL", profileSqlLc);
        }

        Properties infoCopy = (Properties) info.clone();

        infoCopy.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.USER_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.DBNAME_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);
        infoCopy.remove("profileSql");

        int numPropertiesToSet = PROPERTY_LIST.size();

        for (int i = 0; i < numPropertiesToSet; i++) {
            java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

            try {
                ConnectionProperty propToSet = (ConnectionProperty) propertyField.get(this);

                propToSet.initializeFrom(infoCopy, getExceptionInterceptor());
            } catch (IllegalAccessException iae) {
                throw SQLError.createSQLException(Messages.getString("ConnectionProperties.unableToInitDriverProperties") + iae.toString(),
                        SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
            }
        }

        postInitialization();
    }
}
 
Example 13
Project: BibliotecaPS   File: ConnectionPropertiesImpl.java   View Source Code Vote up 5 votes
/**
 * Initializes driver properties that come from URL or properties passed to
 * the driver manager.
 * 
 * @param info
 * @throws SQLException
 */
protected void initializeProperties(Properties info) throws SQLException {
    if (info != null) {
        // For backwards-compatibility
        String profileSqlLc = info.getProperty("profileSql");

        if (profileSqlLc != null) {
            info.put("profileSQL", profileSqlLc);
        }

        Properties infoCopy = (Properties) info.clone();

        infoCopy.remove(NonRegisteringDriver.HOST_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.USER_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.PASSWORD_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.DBNAME_PROPERTY_KEY);
        infoCopy.remove(NonRegisteringDriver.PORT_PROPERTY_KEY);
        infoCopy.remove("profileSql");

        int numPropertiesToSet = PROPERTY_LIST.size();

        for (int i = 0; i < numPropertiesToSet; i++) {
            java.lang.reflect.Field propertyField = PROPERTY_LIST.get(i);

            try {
                ConnectionProperty propToSet = (ConnectionProperty) propertyField.get(this);

                propToSet.initializeFrom(infoCopy, getExceptionInterceptor());
            } catch (IllegalAccessException iae) {
                throw SQLError.createSQLException(Messages.getString("ConnectionProperties.unableToInitDriverProperties") + iae.toString(),
                        SQLError.SQL_STATE_GENERAL_ERROR, getExceptionInterceptor());
            }
        }

        postInitialization();
    }
}
 
Example 14
Project: incubator-netbeans   File: AntTargetExecutor.java   View Source Code Vote up 4 votes
/** Set properties of Ant script execution.
 * @param p a set of name/value pairs passed to Ant (will be cloned)
 */
public synchronized void setProperties(Properties p) {
    properties = (Properties) p.clone();
}
 
Example 15
Project: OpenVertretung   File: NonRegisteringDriver.java   View Source Code Vote up 4 votes
protected java.sql.Connection connectReplicationConnection(String url, Properties info) throws SQLException {
    Properties parsedProps = parseURL(url, info);

    if (parsedProps == null) {
        return null;
    }

    Properties masterProps = (Properties) parsedProps.clone();
    Properties slavesProps = (Properties) parsedProps.clone();

    // Marker used for further testing later on, also when
    // debugging
    slavesProps.setProperty("com.mysql.jdbc.ReplicationConnection.isSlave", "true");

    int numHosts = Integer.parseInt(parsedProps.getProperty(NUM_HOSTS_PROPERTY_KEY));

    if (numHosts < 2) {
        throw SQLError.createSQLException("Must specify at least one slave host to connect to for master/slave replication load-balancing functionality",
                SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE, null);
    }
    List<String> slaveHostList = new ArrayList<String>();
    List<String> masterHostList = new ArrayList<String>();

    String firstHost = masterProps.getProperty(HOST_PROPERTY_KEY + ".1") + ":" + masterProps.getProperty(PORT_PROPERTY_KEY + ".1");

    boolean usesExplicitServerType = NonRegisteringDriver.isHostPropertiesList(firstHost);

    for (int i = 0; i < numHosts; i++) {
        int index = i + 1;

        masterProps.remove(HOST_PROPERTY_KEY + "." + index);
        masterProps.remove(PORT_PROPERTY_KEY + "." + index);
        slavesProps.remove(HOST_PROPERTY_KEY + "." + index);
        slavesProps.remove(PORT_PROPERTY_KEY + "." + index);

        String host = parsedProps.getProperty(HOST_PROPERTY_KEY + "." + index);
        String port = parsedProps.getProperty(PORT_PROPERTY_KEY + "." + index);
        if (usesExplicitServerType) {
            if (isHostMaster(host)) {
                masterHostList.add(host);
            } else {
                slaveHostList.add(host);
            }
        } else {
            if (i == 0) {
                masterHostList.add(host + ":" + port);
            } else {
                slaveHostList.add(host + ":" + port);
            }
        }
    }

    slavesProps.remove(NUM_HOSTS_PROPERTY_KEY);
    masterProps.remove(NUM_HOSTS_PROPERTY_KEY);
    masterProps.remove(HOST_PROPERTY_KEY);
    masterProps.remove(PORT_PROPERTY_KEY);
    slavesProps.remove(HOST_PROPERTY_KEY);
    slavesProps.remove(PORT_PROPERTY_KEY);

    return ReplicationConnectionProxy.createProxyInstance(masterHostList, masterProps, slaveHostList, slavesProps);
}
 
Example 16
Project: lams   File: NonRegisteringDriver.java   View Source Code Vote up 4 votes
protected java.sql.Connection connectReplicationConnection(String url, Properties info) throws SQLException {
    Properties parsedProps = parseURL(url, info);

    if (parsedProps == null) {
        return null;
    }

    Properties masterProps = (Properties) parsedProps.clone();
    Properties slavesProps = (Properties) parsedProps.clone();

    // Marker used for further testing later on, also when
    // debugging
    slavesProps.setProperty("com.mysql.jdbc.ReplicationConnection.isSlave", "true");

    int numHosts = Integer.parseInt(parsedProps.getProperty(NUM_HOSTS_PROPERTY_KEY));

    if (numHosts < 2) {
        throw SQLError.createSQLException("Must specify at least one slave host to connect to for master/slave replication load-balancing functionality",
                SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE, null);
    }
    List<String> slaveHostList = new ArrayList<String>();
    List<String> masterHostList = new ArrayList<String>();

    String firstHost = masterProps.getProperty(HOST_PROPERTY_KEY + ".1") + ":" + masterProps.getProperty(PORT_PROPERTY_KEY + ".1");

    boolean usesExplicitServerType = NonRegisteringDriver.isHostPropertiesList(firstHost);

    for (int i = 0; i < numHosts; i++) {
        int index = i + 1;

        masterProps.remove(HOST_PROPERTY_KEY + "." + index);
        masterProps.remove(PORT_PROPERTY_KEY + "." + index);
        slavesProps.remove(HOST_PROPERTY_KEY + "." + index);
        slavesProps.remove(PORT_PROPERTY_KEY + "." + index);

        String host = parsedProps.getProperty(HOST_PROPERTY_KEY + "." + index);
        String port = parsedProps.getProperty(PORT_PROPERTY_KEY + "." + index);
        if (usesExplicitServerType) {
            if (isHostMaster(host)) {
                masterHostList.add(host);
            } else {
                slaveHostList.add(host);
            }
        } else {
            if (i == 0) {
                masterHostList.add(host + ":" + port);
            } else {
                slaveHostList.add(host + ":" + port);
            }
        }
    }

    slavesProps.remove(NUM_HOSTS_PROPERTY_KEY);
    masterProps.remove(NUM_HOSTS_PROPERTY_KEY);
    masterProps.remove(HOST_PROPERTY_KEY);
    masterProps.remove(PORT_PROPERTY_KEY);
    slavesProps.remove(HOST_PROPERTY_KEY);
    slavesProps.remove(PORT_PROPERTY_KEY);

    return ReplicationConnectionProxy.createProxyInstance(masterHostList, masterProps, slaveHostList, slavesProps);
}
 
Example 17
Project: ProyectoPacientes   File: NonRegisteringDriver.java   View Source Code Vote up 4 votes
protected java.sql.Connection connectReplicationConnection(String url, Properties info) throws SQLException {
    Properties parsedProps = parseURL(url, info);

    if (parsedProps == null) {
        return null;
    }

    Properties masterProps = (Properties) parsedProps.clone();
    Properties slavesProps = (Properties) parsedProps.clone();

    // Marker used for further testing later on, also when
    // debugging
    slavesProps.setProperty("com.mysql.jdbc.ReplicationConnection.isSlave", "true");

    int numHosts = Integer.parseInt(parsedProps.getProperty(NUM_HOSTS_PROPERTY_KEY));

    if (numHosts < 2) {
        throw SQLError.createSQLException("Must specify at least one slave host to connect to for master/slave replication load-balancing functionality",
                SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE, null);
    }
    List<String> slaveHostList = new ArrayList<String>();
    List<String> masterHostList = new ArrayList<String>();

    String firstHost = masterProps.getProperty(HOST_PROPERTY_KEY + ".1") + ":" + masterProps.getProperty(PORT_PROPERTY_KEY + ".1");

    boolean usesExplicitServerType = NonRegisteringDriver.isHostPropertiesList(firstHost);

    for (int i = 0; i < numHosts; i++) {
        int index = i + 1;

        masterProps.remove(HOST_PROPERTY_KEY + "." + index);
        masterProps.remove(PORT_PROPERTY_KEY + "." + index);
        slavesProps.remove(HOST_PROPERTY_KEY + "." + index);
        slavesProps.remove(PORT_PROPERTY_KEY + "." + index);

        String host = parsedProps.getProperty(HOST_PROPERTY_KEY + "." + index);
        String port = parsedProps.getProperty(PORT_PROPERTY_KEY + "." + index);
        if (usesExplicitServerType) {
            if (isHostMaster(host)) {
                masterHostList.add(host);
            } else {
                slaveHostList.add(host);
            }
        } else {
            if (i == 0) {
                masterHostList.add(host + ":" + port);
            } else {
                slaveHostList.add(host + ":" + port);
            }
        }
    }

    slavesProps.remove(NUM_HOSTS_PROPERTY_KEY);
    masterProps.remove(NUM_HOSTS_PROPERTY_KEY);
    masterProps.remove(HOST_PROPERTY_KEY);
    masterProps.remove(PORT_PROPERTY_KEY);
    slavesProps.remove(HOST_PROPERTY_KEY);
    slavesProps.remove(PORT_PROPERTY_KEY);

    return ReplicationConnectionProxy.createProxyInstance(masterHostList, masterProps, slaveHostList, slavesProps);
}
 
Example 18
Project: BibliotecaPS   File: NonRegisteringDriver.java   View Source Code Vote up 4 votes
protected java.sql.Connection connectReplicationConnection(String url, Properties info) throws SQLException {
    Properties parsedProps = parseURL(url, info);

    if (parsedProps == null) {
        return null;
    }

    Properties masterProps = (Properties) parsedProps.clone();
    Properties slavesProps = (Properties) parsedProps.clone();

    // Marker used for further testing later on, also when
    // debugging
    slavesProps.setProperty("com.mysql.jdbc.ReplicationConnection.isSlave", "true");

    int numHosts = Integer.parseInt(parsedProps.getProperty(NUM_HOSTS_PROPERTY_KEY));

    if (numHosts < 2) {
        throw SQLError.createSQLException("Must specify at least one slave host to connect to for master/slave replication load-balancing functionality",
                SQLError.SQL_STATE_INVALID_CONNECTION_ATTRIBUTE, null);
    }
    List<String> slaveHostList = new ArrayList<String>();
    List<String> masterHostList = new ArrayList<String>();

    String firstHost = masterProps.getProperty(HOST_PROPERTY_KEY + ".1") + ":" + masterProps.getProperty(PORT_PROPERTY_KEY + ".1");

    boolean usesExplicitServerType = NonRegisteringDriver.isHostPropertiesList(firstHost);

    for (int i = 0; i < numHosts; i++) {
        int index = i + 1;

        masterProps.remove(HOST_PROPERTY_KEY + "." + index);
        masterProps.remove(PORT_PROPERTY_KEY + "." + index);
        slavesProps.remove(HOST_PROPERTY_KEY + "." + index);
        slavesProps.remove(PORT_PROPERTY_KEY + "." + index);

        String host = parsedProps.getProperty(HOST_PROPERTY_KEY + "." + index);
        String port = parsedProps.getProperty(PORT_PROPERTY_KEY + "." + index);
        if (usesExplicitServerType) {
            if (isHostMaster(host)) {
                masterHostList.add(host);
            } else {
                slaveHostList.add(host);
            }
        } else {
            if (i == 0) {
                masterHostList.add(host + ":" + port);
            } else {
                slaveHostList.add(host + ":" + port);
            }
        }
    }

    slavesProps.remove(NUM_HOSTS_PROPERTY_KEY);
    masterProps.remove(NUM_HOSTS_PROPERTY_KEY);
    masterProps.remove(HOST_PROPERTY_KEY);
    masterProps.remove(PORT_PROPERTY_KEY);
    slavesProps.remove(HOST_PROPERTY_KEY);
    slavesProps.remove(PORT_PROPERTY_KEY);

    return ReplicationConnectionProxy.createProxyInstance(masterHostList, masterProps, slaveHostList, slavesProps);
}
 
Example 19
Project: boohee_v5.6   File: b.java   View Source Code Vote up 4 votes
public void a(Properties properties) {
    if (properties != null) {
        this.a.c = (Properties) properties.clone();
    }
}
 
Example 20
Project: lams   File: ConfigurationHelper.java   View Source Code Vote up 3 votes
/**
 * replace a property by a starred version
 *
 * @param props properties to check
 * @param key proeprty to mask
 *
 * @return cloned and masked properties
 */
public static Properties maskOut(Properties props, String key) {
	Properties clone = ( Properties ) props.clone();
	if ( clone.get( key ) != null ) {
		clone.setProperty( key, "****" );
	}
	return clone;
}