@Override public String getConnectionUrl() { final String oldConnectionUrl = connectionProperties.get(URL); // Substitute parameters TemplatingUtility.substituteVariables(connectionProperties); final String connectionUrl = connectionProperties.get(URL); // Check that all required parameters have been substituted final Set<String> unmatchedVariables = TemplatingUtility .extractTemplateVariables(connectionUrl); if (!unmatchedVariables.isEmpty()) { throw new IllegalArgumentException(String .format("Insufficient parameters for database connection URL: missing %s", unmatchedVariables)); } // Reset old connection URL connectionProperties.put(URL, oldConnectionUrl); return connectionUrl; }
public void substituteAll(final String templateKey, final String templateValue) { final Map<String, String> map = new HashMap<>(); map.put(templateKey, templateValue); for (final Map.Entry<InformationSchemaKey, String> query: informationSchemaQueries .entrySet()) { String sql = query.getValue(); sql = TemplatingUtility.expandTemplate(sql, map); query.setValue(sql); } }
/** * Expands a template using system properties. Variables in the * template are in the form of ${variable}. * * @param template * Template to expand. * @return Expanded template */ public static String expandTemplate(final String template) { return expandTemplate(template, propertiesMap(System.getProperties())); }
/** * Determines if this query has substitutable parameters, and whether * it should be run once for each table. * * @return If the query is to be run over each table */ public boolean isQueryOver() { final Set<String> keys = extractTemplateVariables(query); return keys.contains("table"); }
/** * Determines if this query has substitutable parameters, and whether * it should be run once for each table. * * @return If the query is to be run over each table */ public boolean isQueryOver() { final Set<String> keys = extractTemplateVariables(query); return keys.contains("table"); }
public void substituteAll(final String templateKey, final String templateValue) { final Map<String, String> map = new HashMap<>(); map.put(templateKey, templateValue); for (final Map.Entry<InformationSchemaKey, String> query: informationSchemaQueries .entrySet()) { String sql = query.getValue(); sql = TemplatingUtility.expandTemplate(sql, map); query.setValue(sql); } }
@Override public String getConnectionUrl() { final Map<String, String> properties = new HashMap<>(this.properties); TemplatingUtility.substituteVariables(properties); final String connectionUrl = properties.get(URL); // Check that all required parameters have been substituted final Set<String> unmatchedVariables = TemplatingUtility .extractTemplateVariables(connectionUrl); if (!unmatchedVariables.isEmpty()) { throw new IllegalArgumentException(String.format("Insufficient parameters for database connection URL: missing %s", unmatchedVariables)); } return connectionUrl; }
/** * Expands a template using system properties. Variables in the * template are in the form of ${variable}. * * @param template * Template to expand. * @return Expanded template */ public static String expandTemplate(final String template) { return expandTemplate(template, propertiesMap(System.getProperties())); }
variables = TemplatingUtility.extractTemplateVariables("No variables"); assertThat("Incorrect number of variables found", variables, is(empty())); variables = TemplatingUtility.extractTemplateVariables("${one} variable"); sortedVariables = getSortedVariables(variables); assertThat("Incorrect number of variables found", variables, hasSize(1)); .extractTemplateVariables("Has ${one} variable, and ${another} variable"); sortedVariables = getSortedVariables(variables); assertThat("Incorrect number of variables found", variables, hasSize(2)); .extractTemplateVariables("Has $${unusual} variable"); sortedVariables = getSortedVariables(variables); assertThat("Incorrect number of variables found", variables, hasSize(1)); .extractTemplateVariables("Has ${unusual}} variable"); sortedVariables = getSortedVariables(variables); assertThat("Incorrect number of variables found", variables, hasSize(1)); .extractTemplateVariables("Has ${bad variable"); sortedVariables = getSortedVariables(variables); assertThat("Incorrect number of variables found", variables, is(empty())); .extractTemplateVariables("Has ${good} and ${bad variable"); sortedVariables = getSortedVariables(variables); assertThat("Incorrect number of variables found", variables, hasSize(1)); .extractTemplateVariables("Has ${bad and ${good} variable"); sortedVariables = getSortedVariables(variables);
/** * Does one pass over the values in the map, and expands each as a * template, using the rest of the values in the same map. Variables * in the template are in the form of ${variable}. * * @param variablesMap * Map to expand. */ public static void substituteVariables(final Map<String, String> variablesMap) { if (variablesMap != null && !variablesMap.isEmpty()) { for (final Map.Entry<String, String> entry: variablesMap.entrySet()) { variablesMap.put(entry.getKey(), expandTemplate(entry.getValue(), variablesMap)); } } }
@Override public String getConnectionUrl() { final String oldConnectionUrl = connectionProperties.get(URL); // Substitute parameters TemplatingUtility.substituteVariables(connectionProperties); final String connectionUrl = connectionProperties.get(URL); // Check that all required parameters have been substituted final Set<String> unmatchedVariables = TemplatingUtility .extractTemplateVariables(connectionUrl); if (!unmatchedVariables.isEmpty()) { throw new IllegalArgumentException(String .format("Insufficient parameters for database connection URL: missing %s", unmatchedVariables)); } // Reset old connection URL connectionProperties.put(URL, oldConnectionUrl); return connectionUrl; }
/** * Expands a template using system properties. Variables in the * template are in the form of ${variable}. * * @param template * Template to expand. * @return Expanded template */ public static String expandTemplate(final String template) { return expandTemplate(template, propertiesMap(System.getProperties())); }
/** * Determines if this query has substitutable parameters, and whether * it should be run once for each table. * * @return If the query is to be run over each table */ public boolean isQueryOver() { final Set<String> keys = TemplatingUtility.extractTemplateVariables(query); return keys.contains("table"); }
private static String getQuery(final Query query) { return expandTemplate(query.getQuery()); }
@Override public String getConnectionUrl() { final String oldConnectionUrl = connectionProperties.get(URL); // Substitute parameters TemplatingUtility.substituteVariables(connectionProperties); final String connectionUrl = connectionProperties.get(URL); // Check that all required parameters have been substituted final Set<String> unmatchedVariables = TemplatingUtility .extractTemplateVariables(connectionUrl); if (!unmatchedVariables.isEmpty()) { throw new IllegalArgumentException(String .format("Insufficient parameters for database connection URL: missing %s", unmatchedVariables)); } // Reset old connection URL connectionProperties.put(URL, oldConnectionUrl); return connectionUrl; }
/** * Expands a template using system properties. Variables in the * template are in the form of ${variable}. * * @param template * Template to expand. * @return Expanded template */ public static String expandTemplate(final String template) { return expandTemplate(template, propertiesMap(System.getProperties())); }
/** * Determines if this query has substitutable parameters, and whether * it should be run once for each table. * * @return If the query is to be run over each table */ public boolean isQueryOver() { final Set<String> keys = extractTemplateVariables(query); return keys.contains("table"); }
private static String getQuery(final Query query) { return expandTemplate(query.getQuery()); }
/** * Expands a template using system properties. Variables in the * template are in the form of ${variable}. * * @param template * Template to expand. * @return Expanded template */ public static String expandTemplate(final String template) { return expandTemplate(template, propertiesMap(System.getProperties())); }
/** * Determines if this query has substitutable parameters, and whether * it should be run once for each table. * * @return If the query is to be run over each table */ public boolean isQueryOver() { final Set<String> keys = extractTemplateVariables(query); return keys.contains("table"); }