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); } }
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())); }
/** * 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)); } } }
/** * 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())); }
private static String getQuery(final Query query) { return expandTemplate(query.getQuery()); }
private static String getQuery(final Query query) { return expandTemplate(query.getQuery()); }
/** * 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)); } } }
/** * Gets the query with parameters substituted. * * @param schemaInclusionRule * Schema inclusion rule * @return Ready-to-execute query */ private static String getQuery(final Query query, final InclusionRule schemaInclusionRule) { final Map<String, String> properties = new HashMap<>(); properties.put("schemas", ".*"); if (schemaInclusionRule != null && schemaInclusionRule instanceof InclusionRuleWithRegularExpression) { final String schemaInclusionPattern = ((InclusionRuleWithRegularExpression) schemaInclusionRule) .getInclusionPattern().pattern(); if (!isBlank(schemaInclusionPattern)) { properties.put("schemas", schemaInclusionPattern); } } String sql = query.getQuery(); sql = expandTemplate(sql, properties); sql = expandTemplate(sql); return sql; }
/** * Gets the query with parameters substituted. * * @param schemaInclusionRule * Schema inclusion rule * @return Ready-to-execute query */ private static String getQuery(final Query query, final InclusionRule schemaInclusionRule) { final Map<String, String> properties = new HashMap<>(); properties.put("schemas", ".*"); if (schemaInclusionRule != null && schemaInclusionRule instanceof InclusionRuleWithRegularExpression) { final String schemaInclusionPattern = ((InclusionRuleWithRegularExpression) schemaInclusionRule) .getInclusionPattern().pattern(); if (!isBlank(schemaInclusionPattern)) { properties.put("schemas", schemaInclusionPattern); } } String sql = query.getQuery(); sql = expandTemplate(sql, properties); sql = expandTemplate(sql); return sql; }
sql = expandTemplate(sql, tableProperties); sql = expandTemplate(sql);
sql = expandTemplate(sql, tableProperties); sql = expandTemplate(sql);
expanded = TemplatingUtility.expandTemplate("No variables", values); assertThat("Incorrect template expansion", expanded, is("No variables")); expanded = TemplatingUtility.expandTemplate("${one} variable", values); assertThat("Incorrect template expansion", expanded, .expandTemplate("Has ${one} variable, and ${another} variable", values); assertThat("Incorrect template expansion", expanded, is("Has one.value variable, and two.value variable")); expanded = TemplatingUtility.expandTemplate("Has $${unusual} variable", values); assertThat("Incorrect template expansion", expanded = TemplatingUtility.expandTemplate("Has ${unusual}} variable", values); assertThat("Incorrect template expansion", expanded = TemplatingUtility.expandTemplate("Has ${bad variable", values); assertThat("Incorrect template expansion", expanded, .expandTemplate("Has ${good} and ${bad variable", values); assertThat("Incorrect template expansion", expanded, .expandTemplate("Has ${bad and ${good} variable", values);
/** * Gets the query SQL. * * @return Query SQL */ public String getQuery() { return TemplatingUtility.expandTemplate(query); }
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())); }
/** * 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())); }
/** * 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())); }
private static String getQuery(final Query query) { return expandTemplate(query.getQuery()); }
private static String getQuery(final Query query) { return expandTemplate(query.getQuery()); }