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

The following examples show how to use java.util.Properties#clone() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void setProperties(IoTDBDataSource ds, Properties prop){
    Properties properties = (Properties)prop.clone();
    String url = (String)properties.remove(DataSourceFactory.JDBC_URL);
    if(url!=null){
        ds.setUrl(url);
        logger.info("URL set {}",url);
    }

    String user = (String) properties.remove(DataSourceFactory.JDBC_USER);
    ds.setUser(user);
    logger.info("User set {}",user);


    String password = (String) properties.remove(DataSourceFactory.JDBC_PASSWORD);
    ds.setPassword(password);
    logger.info("Password set {}",password);


    logger.info("Remaining properties {}", properties.size());

    if (!properties.isEmpty()) {
        BeanConfig.configure(ds, properties);
    }
}
 
Example 2
Source Project: pxf   File: PoolDescriptor.java    License: Apache License 2.0 6 votes vote down vote up
public PoolDescriptor(String server, String jdbcUrl, Properties connectionConfig, Properties poolConfig, String qualifier) {
    this.server = server;
    this.jdbcUrl = jdbcUrl;

    if (connectionConfig != null) {
        this.connectionConfig = (Properties) connectionConfig.clone();
        // extract credentials to treat them explicitly, remove from connection properties
        this.user = (String) this.connectionConfig.remove(USER_PROPERTY_NAME);
        this.password = (String) this.connectionConfig.remove(PASSWORD_PROPERTY_NAME);
    }

    this.poolConfig = (Properties) poolConfig.clone();
    this.qualifier = qualifier;

    // validate pool configuration
    PROHIBITED_PROPERTIES.forEach(p -> ensurePoolPropertyNotPresent(p));
}
 
Example 3
Source Project: r-course   File: MultiHostConnectionProxy.java    License: MIT License 6 votes vote down vote up
/**
 * 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
Source Project: fabric-sdk-java   File: Orderer.java    License: Apache License 2.0 6 votes vote down vote up
Orderer(String name, String url, Properties properties) throws InvalidArgumentException {

        if (StringUtil.isNullOrEmpty(name)) {
            throw new InvalidArgumentException("Invalid name for orderer");
        }
        Exception e = checkGrpcUrl(url);
        if (e != null) {
            throw new InvalidArgumentException(e);
        }

        this.name = name;
        this.url = url;
        this.properties = properties == null ? new Properties() : (Properties) properties.clone(); //keep our own copy.
        logger.trace("Created " + toString());

    }
 
Example 5
Source Project: fabric-sdk-java   File: Peer.java    License: Apache License 2.0 6 votes vote down vote up
Peer(String name, String grpcURL, Properties properties) throws InvalidArgumentException {
    reconnectCount = new AtomicLong(0L);
    id = config.getNextID();

    Exception e = checkGrpcUrl(grpcURL);
    if (e != null) {
        throw new InvalidArgumentException("Bad peer url.", e);

    }

    if (StringUtil.isNullOrEmpty(name)) {
        throw new InvalidArgumentException("Invalid name for peer");
    }

    this.url = grpcURL;
    this.name = name;
    this.properties = properties == null ? new Properties() : (Properties) properties.clone(); //keep our own copy.

    logger.debug("Created " + toString());
}
 
Example 6
private QuasarTokenFilter(Properties props, KeyStore keystore, String tokenAesKeyName) {
  this.properties = (Properties) props.clone();
  if( keystore == null ) {
    throw new RuntimeException("keystore is null");
  }

  ByteBuffer bb = ByteBuffer.wrap(getKey(keystore, KeyStore.SIPHASH_TOKEN));
  bb.order(ByteOrder.BIG_ENDIAN);
  tokenSipHashKeyK0 = bb.getLong();
  tokenSipHashKeyK1 = bb.getLong();

  byte[] appSipHashKey = getKey(keystore,KeyStore.SIPHASH_APPID);
  byte[] tokenAESKey = getKey(keystore, tokenAesKeyName);

  this.quasarTokenDecoder = new QuasarTokenDecoder(tokenSipHashKeyK0, tokenSipHashKeyK1, tokenAESKey);
  this.quasarTokenRevoked = new QuasarTokensRevoked(properties, appSipHashKey);
}
 
Example 7
/**
    * @param props
    */
private void afterLoad(Properties props) {
	final Object[] keys = props.keySet().toArray(new Object[0]);
	for (Object key : keys) {
		String cleanKey = key.toString();
		// AES decrypt if have `.aes` suffix
		if (cleanKey.endsWith(".aes")) {
			String val = props.getProperty(cleanKey);
			val = AES.decryptQuietly(val);

			props.remove(cleanKey);
			cleanKey = cleanKey.replace(".aes", "");
			props.put(cleanKey, val);
		}
		
		// Overrides by command-line
		String viaCL = System.getProperty(cleanKey);
		if (StringUtils.isNotBlank(viaCL)) {
			props.put(cleanKey, viaCL);
		}
	}

	// SPEC MYSQL PORT
	String mysqlPort = System.getProperty("mysql.port");
	String dbUrl = props.getProperty("db.url");
	if (StringUtils.isNotBlank(mysqlPort) && StringUtils.isNotBlank(dbUrl)) {
		dbUrl = dbUrl.replace("3306", mysqlPort);
		props.put("db.url", dbUrl);
	}

	// MUST NOT BE NULL
       setIfEmpty(props, ConfigurableItem.CacheHost, "127.0.0.1");
       setIfEmpty(props, ConfigurableItem.CachePort, "6379");

	propsHold = (Properties) props.clone();
}
 
Example 8
/**
 * 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;
}
 
Example 9
public DriverManagerDataSource( final String jdbcConnectString,
                                final Properties properties ) {
  if ( jdbcConnectString == null ) {
    throw new NullPointerException();
  }
  if ( properties == null ) {
    throw new NullPointerException();
  }
  this.jdbcConnectString = jdbcConnectString;
  this.jdbcProperties = (Properties) properties.clone();
}
 
Example 10
Source Project: tajo   File: CliClientParamsFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static Properties get(@Nullable Properties connParam) {
  Properties copy = connParam == null ? new Properties() : (Properties) connParam.clone();
  for (Map.Entry<String, String> entry : DEFAULT_PARAMS.entrySet()) {
    if (!copy.contains(entry.getKey())) {
      copy.setProperty(entry.getKey(), entry.getValue());
    }
  }
  return copy;
}
 
Example 11
/**
 * 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
/**
 * Intended to be called the very first time we connect to a newly initialized database.  This
 * method appears to be responsible for setting the initial password for our 'splice' user.
 */
public Connection createFirstNew(SConfiguration configuration,Properties dbProperties) throws SQLException {
    Properties properties = (Properties)dbProperties.clone();
    String auth = configuration.getAuthentication();
    if (!"LDAP".equalsIgnoreCase(auth)){
        properties.remove(EmbedConnection.INTERNAL_CONNECTION);
    }
    final String SPLICE_DEFAULT_PASSWORD = "admin";
    return driver.connect(JDBC_URL + ";create=true;password=" + SPLICE_DEFAULT_PASSWORD, properties);
}
 
Example 13
Source Project: ignite   File: ConnectionPropertiesImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param url URL connection.
 * @param props Environment properties.
 * @throws SQLException On error.
 */
public void init(String url, Properties props) throws SQLException {
    Properties props0 = (Properties)props.clone();

    if (!F.isEmpty(url))
        parseUrl(url, props0);

    for (ConnectionProperty aPropsArray : propsArray)
        aPropsArray.init(props0);

    if (!F.isEmpty(props.getProperty("user"))) {
        setUsername(props.getProperty("user"));
        setPassword(props.getProperty("password"));
    }
}
 
Example 14
Source Project: vividus   File: PropertyParser.java    License: Apache License 2.0 4 votes vote down vote up
public void setProperties(Properties properties)
{
    this.properties = (Properties) properties.clone();
}
 
Example 15
Source Project: javamelody   File: JdbcDriver.java    License: Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public Connection connect(String url, Properties info) throws SQLException {
	if ("false".equals(info.get("javamelody"))) {
		// if property javamelody=false then it's not for us
		// (we pass here from the DriverManager.getConnection below)
		return null;
	}
	String myUrl = url;
	// we load first the driver class from the info or the url, to be sure that it will be found
	String proxiedDriver = info.getProperty("driver");
	if (proxiedDriver == null && myUrl != null) {
		// if not in the info, the driver class could also be passed at the end of the url, for example ...?driver=org.h2.Driver
		final int index = myUrl.indexOf("driver=");
		if (index != -1) {
			proxiedDriver = myUrl.substring(index + "driver=".length());
			myUrl = myUrl.substring(0, index - 1);
		}
	}
	if (proxiedDriver == null) {
		// if the driver is not defined in the info or in the url
		// it could still be found automatically if the driver is in the classpath
		// or (in WEB-INF/lib and if the jdbc drivers are not loaded by the JDK before this webapp)
		// but we don't want to create proxies and increment counts for the connections inside datasources
		// so we only accept and go further if driver is defined in the info or in the url
		return null;
	}
	try {
		// on utilise Thread.currentThread().getContextClassLoader() car le driver peut ne pas être
		// dans le même classLoader que les classes de javamelody
		// Class driverClass =
		Class.forName(proxiedDriver, true, Thread.currentThread().getContextClassLoader());
		// et non Class.forName(proxiedDriver);
	} catch (final ClassNotFoundException e) {
		throw new SQLException(e.getMessage(), e);
	}

	final Properties myInfo = (Properties) info.clone();
	myInfo.remove("driver");
	myInfo.put("javamelody", "false");
	Parameters.initJdbcDriverParameters(myUrl, myInfo);
	// we could call driverClass.newInstance().connect(myUrl, myInfo)
	// possibly by looking the driver which accepts the url in DriverManager.getDrivers()
	// but we prefer calling the standard DriverManager.getConnection(myUrl, myInfo)
	return JdbcWrapper.SINGLETON
			.createConnectionProxy(DriverManager.getConnection(myUrl, myInfo));
}
 
Example 16
Source Project: netbeans-mmd-plugin   File: MMapURI.java    License: Apache License 2.0 4 votes vote down vote up
private MMapURI(@Nonnull final URI uri, final boolean isFile, @Nullable final Properties properties) {
  this.uri = uri;
  this.fileUriFlag = isFile;
  this.parameters = properties == null ? new Properties() : (Properties) properties.clone();
}
 
Example 17
Source Project: r-course   File: NonRegisteringDriver.java    License: MIT License 4 votes vote down vote up
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
public void initializeProperties(Properties props) {
    if (props != null) {
        Properties infoCopy = (Properties) props.clone();

        // TODO do we need to remove next properties (as it was before)?
        infoCopy.remove(PropertyKey.HOST.getKeyName());
        infoCopy.remove(PropertyKey.PORT.getKeyName());
        infoCopy.remove(PropertyKey.USER.getKeyName());
        infoCopy.remove(PropertyKey.PASSWORD.getKeyName());
        infoCopy.remove(PropertyKey.DBNAME.getKeyName());

        for (PropertyKey propKey : PropertyDefinitions.PROPERTY_KEY_TO_PROPERTY_DEFINITION.keySet()) {
            try {
                RuntimeProperty<?> propToSet = getProperty(propKey);
                propToSet.initializeFrom(infoCopy, null);

            } catch (CJException e) {
                throw ExceptionFactory.createException(WrongArgumentException.class, e.getMessage(), e);
            }
        }

        // Translate legacy SSL properties if sslMode isn't explicitly set. Default sslMode is PREFERRED.
        RuntimeProperty<SslMode> sslMode = this.<SslMode> getEnumProperty(PropertyKey.sslMode);
        if (!sslMode.isExplicitlySet()) {
            RuntimeProperty<Boolean> useSSL = this.getBooleanProperty(PropertyKey.useSSL);
            RuntimeProperty<Boolean> verifyServerCertificate = this.getBooleanProperty(PropertyKey.verifyServerCertificate);
            RuntimeProperty<Boolean> requireSSL = this.getBooleanProperty(PropertyKey.requireSSL);
            if (useSSL.isExplicitlySet() || verifyServerCertificate.isExplicitlySet() || requireSSL.isExplicitlySet()) {
                if (!useSSL.getValue()) {
                    sslMode.setValue(SslMode.DISABLED);
                } else if (verifyServerCertificate.getValue()) {
                    sslMode.setValue(SslMode.VERIFY_CA);
                } else if (requireSSL.getValue()) {
                    sslMode.setValue(SslMode.REQUIRED);
                }
            }
        }

        // add user-defined properties
        for (Object key : infoCopy.keySet()) {
            String val = infoCopy.getProperty((String) key);
            PropertyDefinition<String> def = new StringPropertyDefinition((String) key, null, val, PropertyDefinitions.RUNTIME_MODIFIABLE,
                    Messages.getString("ConnectionProperties.unknown"), "8.0.10", PropertyDefinitions.CATEGORY_USER_DEFINED, Integer.MIN_VALUE);
            RuntimeProperty<String> p = new StringProperty(def);
            addProperty(p);
        }
        postInitialization();
    }
}
 
Example 19
Source Project: zeppelin   File: JDBCUserConfigurations.java    License: Apache License 2.0 4 votes vote down vote up
public void setPropertyMap(String dbPrefix, Properties properties) {
  Properties p = (Properties) properties.clone();
  propertiesMap.put(dbPrefix, p);
}
 
Example 20
public AbstractTransactionService(final Properties properties) {
    
    this.properties = (Properties) properties.clone();

    {
        
        this.minReleaseAge = LongValidator.GTE_ZERO.parse(
                Options.MIN_RELEASE_AGE, properties.getProperty(
                        Options.MIN_RELEASE_AGE,
                        Options.DEFAULT_MIN_RELEASE_AGE));

        if (log.isInfoEnabled())
            log.info(Options.MIN_RELEASE_AGE + "=" + minReleaseAge);
    
    }
    
    runState = TxServiceRunState.Starting;
    
}