org.avaje.dbmigration.runner.ScriptTransform Maven / Gradle / Ivy
package org.avaje.dbmigration.runner;
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.
*/
public static String table(String tableName, String script) {
return script.replace("${table}", tableName);
}
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+"}";
}
/**
* Return true if this contains no placeholders.
*/
boolean isEmpty() {
return placeholders.isEmpty();
}
/**
* 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;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy