Skip to content

Commit

Permalink
0002756: Allow BSH transforms to control if old data is sent to target
Browse files Browse the repository at this point in the history
  • Loading branch information
jumpmind-josh committed Aug 29, 2016
1 parent e2ba686 commit 5207e65
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
16 changes: 13 additions & 3 deletions symmetric-assemble/src/asciidoc/configuration/transforms/types.ad
Expand Up @@ -233,7 +233,8 @@ column. The query can reference source column names by prefixing them with a co
===== BeanShell Script Transform

This transformation allows you to provide a http://www.beanshell.org/[BeanShell] script in the transform expression and executes the script
at the time of transformation. Some variables are provided to the script:
at the time of transformation. Beanshell transforms can return either a String value or an instance of NewAndOldValue.
Some variables are provided to the script:

.Variables
|===
Expand All @@ -248,7 +249,7 @@ at the time of transformation. Some variables are provided to the script:

|===

.Tranform Expression Example
.Tranform Expression Example Returning a String
====
----
if (currentValue > oldValue) {
Expand All @@ -259,7 +260,16 @@ if (currentValue > oldValue) {
----
====


.Tranform Expression Example Returning a NewAndOldValue object
====
----
if (currentValue != null && currentValue.length() == 0) {
return org.jumpmind.symmetric.io.data.transform.NewAndOldValue(null, oldValue);
} else {
return currentValue;
}
----
====
ifndef::pro[]
[source, SQL]
----
Expand Down
Expand Up @@ -48,7 +48,7 @@
import bsh.Interpreter;
import bsh.TargetError;

public class BshColumnTransform implements ISingleValueColumnTransform, IBuiltInExtensionPoint {
public class BshColumnTransform implements ISingleNewAndOldValueColumnTransform, IBuiltInExtensionPoint {

protected final Logger log = LoggerFactory.getLogger(getClass());

Expand Down Expand Up @@ -79,7 +79,7 @@ public boolean isLoadColumnTransform() {
return true;
}

public String transform(IDatabasePlatform platform,
public NewAndOldValue transform(IDatabasePlatform platform,
DataContext context,
TransformColumn column, TransformedData data, Map<String, String> sourceValues,
String newValue, String oldValue) throws IgnoreColumnException, IgnoreRowException {
Expand Down Expand Up @@ -143,10 +143,13 @@ public String transform(IDatabasePlatform platform,
interpreter.unset(columnName);
}

if (result != null) {
return result.toString();
if (result == null) {
return null;
}
else if (result instanceof String) {
return new NewAndOldValue((String) result, null);
} else {
return null;
return (NewAndOldValue) result;
}
} catch (TargetError evalEx) {
Throwable ex = evalEx.getTarget();
Expand Down

0 comments on commit 5207e65

Please sign in to comment.