Skip to content

Commit

Permalink
0004668: Extensions global BSH functions
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Nov 27, 2020
1 parent e17a149 commit 1ff17e6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Expand Up @@ -407,6 +407,7 @@ private ParameterConstants() {
public final static String BSH_LOAD_FILTER_HANDLES_MISSING_TABLES = "bsh.load.filter.handles.missing.tables";

public final static String BSH_TRANSFORM_GLOBAL_SCRIPT = "bsh.transform.global.script";
public final static String BSH_EXTENSION_GLOBAL_SCRIPT = "bsh.extension.global.script";

public final static String MSSQL_ROW_LEVEL_LOCKS_ONLY = "mssql.allow.only.row.level.locks.on.runtime.tables";
public final static String MSSQL_USE_NTYPES_FOR_SYNC = "mssql.use.ntypes.for.sync";
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;

import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.jumpmind.db.sql.ISqlRowMapper;
import org.jumpmind.db.sql.Row;
import org.jumpmind.extension.IBuiltInExtensionPoint;
Expand Down Expand Up @@ -114,10 +115,14 @@ protected void registerExtension(Extension extension) {
} else if (extension.getExtensionType().equalsIgnoreCase(Extension.EXTENSION_TYPE_BSH)) {
try {
Interpreter interpreter = new Interpreter();
interpreter.eval(extension.getExtensionText());
interpreter.set("engine", engine);
interpreter.set("sqlTemplate", engine.getDatabasePlatform().getSqlTemplate());
interpreter.set("log", log);
String globalScript = parameterService.getString(ParameterConstants.BSH_EXTENSION_GLOBAL_SCRIPT);
if (StringUtils.isNotBlank(globalScript)) {
interpreter.eval(globalScript);
}
interpreter.eval(extension.getExtensionText());
Object ext = interpreter.getInterface(Class.forName(extension.getInterfaceName()));
registerExtension(extension.getExtensionId(), (IExtensionPoint) ext);
} catch (EvalError e) {
Expand Down
Expand Up @@ -2218,6 +2218,13 @@ bsh.load.filter.handles.missing.tables=false
# Type: code
bsh.transform.global.script=

# BeanShell script to include at the beginning of all scripts used in extensions
#
# DatabaseOverridable: true
# Tags: other
# Type: code
bsh.extension.global.script=

# Maximum number of rows to write to file before running with 'LOAD DATA INFILE' to MySQL
#
# DatabaseOverridable: false
Expand Down

0 comments on commit 1ff17e6

Please sign in to comment.