package io.ebeaninternal.dbmigration; import java.util.HashMap; import java.util.Map; /** * Transforms a SQL script given a map of key/value substitutions. */ class ScriptTransform { /** * Transform just ${table} with the table name. */ static String replace(String key, String value, String script) { return script.replace(key, value); } private final Map placeholders = new HashMap<>(); ScriptTransform(Map map) { for (Map.Entry entry : map.entrySet()) { placeholders.put(wrapKey(entry.getKey()), entry.getValue()); } } private String wrapKey(String key) { return "${"+key+"}"; } /** * Transform the script replacing placeholders in the form ${key} with value. */ String transform(String source) { for (Map.Entry entry : placeholders.entrySet()) { source = source.replace(entry.getKey(), entry.getValue()); } return source; } }