Skip to content

Commit

Permalink
0002372: allow SQL-LookupColumnTransform access to OLD-Column values …
Browse files Browse the repository at this point in the history
…and previously transformed columns values (TRM_COLUMN_NAME)
  • Loading branch information
NiasSt90 committed Aug 25, 2015
1 parent f5d0525 commit 6f4aaf8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Expand Up @@ -198,6 +198,8 @@ This transform copies the left most number of bytes specified.
This transformation determines the target column value by using a query, contained in transform expression
to lookup the value in another table. The query must return a single row, and the first column of the query
is used as the value. Your query references source column names by prefixing with a colon (e.g., :MY_COLUMN).
Additional you can reference old values with :OLD_COLUMN and previously transformed columns (see transform order) with
:TRM_COLUMN.

ifndef::pro[]
[source, SQL]
Expand Down
Expand Up @@ -69,12 +69,21 @@ public String transform(IDatabasePlatform platform, DataContext context,
if (StringUtils.isNotBlank(sql)) {
ISqlTransaction transaction = context.findTransaction();
List<String> values = null;
LinkedCaseInsensitiveMap<Object> namedParams = new LinkedCaseInsensitiveMap<Object>(sourceValues);
if (data.getOldSourceValues() != null && sql.contains(":OLD_")) {
for (Map.Entry<String, String> oldColumn : data.getOldSourceValues().entrySet()) {
namedParams.put("OLD_" + oldColumn.getKey().toUpperCase(), oldColumn.getValue());
}
}
if (data.getTargetValues() != null && sql.contains(":TRM_")) {
for (Map.Entry<String, String> transformedCol : data.getTargetValues().entrySet()) {
namedParams.put("TRM_" + transformedCol.getKey().toUpperCase(), transformedCol.getValue());
}
}
if (transaction != null) {
values = transaction.query(sql, lookupColumnRowMapper, new LinkedCaseInsensitiveMap<Object>(
sourceValues));
values = transaction.query(sql, lookupColumnRowMapper, namedParams);
} else {
values = platform.getSqlTemplate().query(sql, lookupColumnRowMapper,
new LinkedCaseInsensitiveMap<Object>(sourceValues));
values = platform.getSqlTemplate().query(sql, lookupColumnRowMapper, namedParams);
}

int rowCount = values.size();
Expand Down

0 comments on commit 6f4aaf8

Please sign in to comment.