Transform extra-ddl.xml files when running in ddl mode (no migration) (#1531)

This commit is contained in:
Manuel Danisch
2018-11-13 20:20:01 +13:00
committed by Rob Bygrave
parent acd6ba0a42
commit 2806972032
3 changed files with 108 additions and 1 deletions
@@ -0,0 +1,40 @@
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<String,String> placeholders = new HashMap<>();
ScriptTransform(Map<String,String> map) {
for (Map.Entry<String, String> 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 <code>${key}</code> with <code>value</code>.
*/
String transform(String source) {
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
source = source.replace(entry.getKey(), entry.getValue());
}
return source;
}
}