use of com.haulmont.cuba.core.sys.PostUpdateScripts in project cuba by cuba-platform.
the class DbUpdaterImpl method executeGroovyScript.
@Override
protected boolean executeGroovyScript(final ScriptResource file) {
Binding bind = new Binding();
bind.setProperty("ds", getDataSource());
bind.setProperty("log", LoggerFactory.getLogger(String.format("%s$%s", DbUpdaterEngine.class.getName(), StringUtils.removeEndIgnoreCase(file.getName(), ".groovy"))));
if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + UPGRADE_GROOVY_EXTENSION)) {
bind.setProperty("postUpdate", new PostUpdateScripts() {
@Override
public void add(Closure closure) {
postUpdateScripts.put(closure, file);
postUpdate.add(closure);
}
@Override
public List<Closure> getUpdates() {
return postUpdate.getUpdates();
}
});
}
try {
scripting.evaluateGroovy(file.getContent(), bind, ScriptExecutionPolicy.DO_NOT_USE_COMPILE_CACHE);
} catch (Exception e) {
throw new RuntimeException(ERROR + "Error executing Groovy script " + file.name + "\n" + e.getMessage(), e);
}
return !postUpdateScripts.containsValue(file);
}
use of com.haulmont.cuba.core.sys.PostUpdateScripts in project cuba by cuba-platform.
the class DbUpdaterEngine method executeGroovyScript.
protected boolean executeGroovyScript(ScriptResource file) {
try {
ClassLoader classLoader = getClass().getClassLoader();
CompilerConfiguration cc = new CompilerConfiguration();
cc.setRecompileGroovySource(true);
Binding bind = new Binding();
bind.setProperty("ds", getDataSource());
bind.setProperty("log", LoggerFactory.getLogger(String.format("%s$%s", DbUpdaterEngine.class.getName(), StringUtils.removeEndIgnoreCase(file.getName(), ".groovy"))));
if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + UPGRADE_GROOVY_EXTENSION)) {
bind.setProperty("postUpdate", new PostUpdateScripts() {
@Override
public void add(Closure closure) {
super.add(closure);
log.warn("Added post update action will be ignored for data store [{}]", storeNameToString(storeName));
}
});
}
GroovyShell shell = new GroovyShell(classLoader, bind, cc);
Script script = shell.parse(file.getContent());
script.run();
} catch (Exception e) {
throw new RuntimeException(String.format("%sError executing Groovy script %s\n%s", ERROR, file.name, e.getMessage()), e);
}
return true;
}
use of com.haulmont.cuba.core.sys.PostUpdateScripts in project cuba by cuba-platform.
the class DbUpdaterImpl method doUpdate.
@Override
protected void doUpdate() {
postUpdate = new PostUpdateScripts();
try {
super.doUpdate();
} catch (RuntimeException e) {
postUpdateScripts.clear();
throw e;
}
if (!postUpdate.getUpdates().isEmpty()) {
log.info(String.format("Execute '%s' post update actions", postUpdate.getUpdates().size()));
for (Closure closure : postUpdate.getUpdates()) {
ScriptResource groovyFile = postUpdateScripts.remove(closure);
if (groovyFile != null) {
log.info("Execute post update from " + getScriptName(groovyFile));
}
closure.call();
if (groovyFile != null && !postUpdateScripts.containsValue(groovyFile)) {
log.info("All post update actions completed for " + getScriptName(groovyFile));
markScript(getScriptName(groovyFile), false);
}
}
}
}
use of com.haulmont.cuba.core.sys.PostUpdateScripts in project cuba by cuba-platform.
the class ServerDbUpdater method doUpdate.
@Override
protected void doUpdate() {
postUpdate = new PostUpdateScripts();
try {
super.doUpdate();
} catch (RuntimeException e) {
postUpdateScripts.clear();
throw e;
}
if (!postUpdate.getUpdates().isEmpty()) {
log.info(String.format("Execute '%s' post update actions", postUpdate.getUpdates().size()));
for (Closure closure : postUpdate.getUpdates()) {
ScriptResource groovyFile = postUpdateScripts.remove(closure);
if (groovyFile != null) {
log.info("Execute post update from {}", getScriptName(groovyFile));
}
closure.call();
if (groovyFile != null && !postUpdateScripts.containsValue(groovyFile)) {
log.info("All post update actions completed for {}", getScriptName(groovyFile));
markScript(getScriptName(groovyFile), false);
}
}
}
}
use of com.haulmont.cuba.core.sys.PostUpdateScripts in project cuba by cuba-platform.
the class ServerDbUpdater method executeGroovyScript.
@Override
protected boolean executeGroovyScript(final ScriptResource file) {
Binding bind = new Binding();
bind.setProperty("ds", getDataSource());
bind.setProperty("log", LoggerFactory.getLogger(String.format("%s$%s", DbUpdaterEngine.class.getName(), StringUtils.removeEndIgnoreCase(file.getName(), ".groovy"))));
if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + UPGRADE_GROOVY_EXTENSION)) {
bind.setProperty("postUpdate", new PostUpdateScripts() {
@Override
public void add(Closure closure) {
postUpdateScripts.put(closure, file);
postUpdate.add(closure);
}
@Override
public List<Closure> getUpdates() {
return postUpdate.getUpdates();
}
});
}
try {
scripting.evaluateGroovy(file.getContent(), bind, ScriptExecutionPolicy.DO_NOT_USE_COMPILE_CACHE);
} catch (Exception e) {
throw new RuntimeException(ERROR + "Error executing Groovy script " + file.name + "\n" + e.getMessage(), e);
}
return !postUpdateScripts.containsValue(file);
}
Aggregations