本文整理汇总了Java中java.util.Properties.clone方法的典型用法代码示例。如果您正苦于以下问题:Java Properties.clone方法的具体用法?Java Properties.clone怎么用?Java Properties.clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Properties
的用法示例。
在下文中一共展示了Properties.clone方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setProperties
import java.util.Properties; //导入方法依赖的package包/类
/**
* 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));
}
}
示例2: initializeHostsSpecs
import java.util.Properties; //导入方法依赖的package包/类
/**
* 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;
}
示例3: setProperties
import java.util.Properties; //导入方法依赖的package包/类
/**
* 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));
}
}
示例4: initializeProperties
import java.util.Properties; //导入方法依赖的package包/类
/**
* 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();
}
}
示例5: testDriverProperties
import java.util.Properties; //导入方法依赖的package包/类
@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);
}
}
示例6: setProperties
import java.util.Properties; //导入方法依赖的package包/类
/** 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();
}
示例7: connectReplicationConnection
import java.util.Properties; //导入方法依赖的package包/类
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);
}
示例8: a
import java.util.Properties; //导入方法依赖的package包/类
public void a(Properties properties) {
if (properties != null) {
this.a.c = (Properties) properties.clone();
}
}
示例9: maskOut
import java.util.Properties; //导入方法依赖的package包/类
/**
* 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;
}