Class SqlTemplate

java.lang.Object
google.registry.util.SqlTemplate

@Immutable public final class SqlTemplate extends Object
SQL template variable substitution.
  • Method Details

    • create

      public static SqlTemplate create(String template)
      Returns a new immutable SQL template builder object, for query parameter substitution.
    • put

      public SqlTemplate put(String key, String value)
      Adds a key/value that should be substituted an individual variable in the template.

      Your template variables should appear as follows: WHERE foo = '%BAR%' and you would call .put("BAR", "some value" to safely substitute it with a value. Only allow-listed characters (as defined by LEGAL_SUBSTITUTIONS) are allowed in values.

      Parameters:
      key - uppercase string that can have digits and underscores
      value - substitution value, composed of allow-listed characters
      Throws:
      IllegalArgumentException - if key or value has bad chars or duplicate keys were added
    • build

      public String build()
      Returns the freshly substituted SQL code.
      Throws:
      IllegalArgumentException - if any substitution variable is not found in the template, or if there are any variable-like strings (%something%) left after substitution.