Exemplo n.º 1
0
  private void updateForcedParameterIfNeeded(
      String parameterName, SimpleParameterEntry alreadySetParameter) {
    String actualForcedParameterValue =
        propertiesParser.getForcedParameterValue(parameterName, systemProperties);

    String previousForcedParameterValue =
        propertiesParser.getForcedParameterValue(parameterName, oldParameters);

    if (actualForcedParameterValue != null) {
      if (alreadySetParameter != null
          && actualForcedParameterValue.equals(alreadySetParameter.getValue())) {
        return;
      }

      if (!actualForcedParameterValue.equals(previousForcedParameterValue)
          && !isAllowedToOverride(parameterName)) {
        return;
      }

      if (alreadySetParameter != null) {
        alreadySetParameter.setValue(actualForcedParameterValue);
      } else {
        parameters.add(new SimpleParameterEntry(parameterName, actualForcedParameterValue));
      }

      updatedParameterNames.add(parameterName);
      return;
    }
  }
Exemplo n.º 2
0
  public void updateSystemParameters() {
    updatedParameterNames.clear();

    for (String parameterName : propertiesParser.getParameterNames(systemProperties.keySet())) {
      updateParameter(parameterName);
    }
  }
Exemplo n.º 3
0
  private void updateDefaultParameterIfNeeded(
      String parameterName, SimpleParameterEntry alreadySetParameter) {
    String actualDefaultParameterValue =
        propertiesParser.getDefaultParameterValue(parameterName, systemProperties);
    String previousDefaultParameterValue =
        propertiesParser.getDefaultParameterValue(parameterName, oldParameters);

    if (actualDefaultParameterValue != null && alreadySetParameter == null) {
      if (!actualDefaultParameterValue.equals(previousDefaultParameterValue)
          && !isAllowedToOverride(parameterName)) {
        return;
      }

      parameters.add(new SimpleParameterEntry(parameterName, actualDefaultParameterValue));
      updatedParameterNames.add(parameterName);
      return;
    }
  }
Exemplo n.º 4
0
  public String parseUri(String uri, String... paths) throws Exception {
    Properties prop = null;
    if (paths != null) {
      // location may contain JVM system property or OS environment variables
      // so we need to parse those
      String[] locations = parseLocations(paths);

      // check cache first
      CacheKey key = new CacheKey(locations);
      prop = cache ? cacheMap.get(key) : null;
      if (prop == null) {
        prop =
            propertiesResolver.resolveProperties(
                getVramelContext(), ignoreMissingLocation, locations);
        if (cache) {
          cacheMap.put(key, prop);
        }
      }
    }

    // use override properties
    if (prop != null && overrideProperties != null) {
      // make a copy to avoid affecting the original properties
      Properties override = new Properties();
      override.putAll(prop);
      override.putAll(overrideProperties);
      prop = override;
    }

    // enclose tokens if missing
    if (!uri.contains(prefixToken) && !uri.startsWith(prefixToken)) {
      uri = prefixToken + uri;
    }
    if (!uri.contains(suffixToken) && !uri.endsWith(suffixToken)) {
      uri = uri + suffixToken;
    }

    LOG.trace("Parsing uri {} with properties: {}", uri, prop);

    if (propertiesParser instanceof AugmentedPropertyNameAwarePropertiesParser) {
      return ((AugmentedPropertyNameAwarePropertiesParser) propertiesParser)
          .parseUri(
              uri,
              prop,
              prefixToken,
              suffixToken,
              propertyPrefix,
              propertySuffix,
              fallbackToUnaugmentedProperty);
    } else {
      return propertiesParser.parseUri(uri, prop, prefixToken, suffixToken);
    }
  }
Exemplo n.º 5
0
 /**
  * Create a connection pool using the given properties.
  *
  * <p>The properties passed should contain:
  *
  * <UL>
  *   <LI>{@link #DB_DRIVER}- The database driver class name
  *   <LI>{@link #DB_URL}- The database URL
  *   <LI>{@link #DB_USER}- The database user
  *   <LI>{@link #DB_PASSWORD}- The database password
  *   <LI>{@link #DB_MAX_CONNECTIONS}- The maximum # connections in the pool, optional
  *   <LI>{@link #DB_VALIDATION_QUERY}- The sql validation query, optional
  * </UL>
  *
  * @param config configuration properties
  */
 public PoolingConnectionProvider(Properties config) throws SQLException {
   PropertiesParser cfg = new PropertiesParser(config);
   initialize(
       cfg.getStringProperty(DB_DRIVER),
       cfg.getStringProperty(DB_URL),
       cfg.getStringProperty(DB_USER, ""),
       cfg.getStringProperty(DB_PASSWORD, ""),
       cfg.getIntProperty(DB_MAX_CONNECTIONS, DEFAULT_DB_MAX_CONNECTIONS),
       cfg.getStringProperty(DB_VALIDATION_QUERY));
 }
Exemplo n.º 6
0
 public static void main(String[] args) throws IOException {
   String currentPath = System.getProperty("user.dir");
   String filePath = currentPath + "/testData/.properties";
   File newFile = new File(filePath);
   Map<String, String> mapData = PropertiesParser.parse(newFile);
 }