use of org.jumpmind.util.LinkedCaseInsensitiveMap in project symmetric-ds by JumpMind.
the class LookupColumnTransform method transform.
public String transform(IDatabasePlatform platform, DataContext context, TransformColumn column, TransformedData data, Map<String, String> sourceValues, String newValue, String oldValue) throws IgnoreColumnException, IgnoreRowException {
String sql = doTokenReplacementOnSql(context, column.getTransformExpression());
String lookupValue = null;
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, namedParams);
} else {
values = platform.getSqlTemplate().query(sql, lookupColumnRowMapper, namedParams);
}
int rowCount = values.size();
if (rowCount == 1) {
lookupValue = values.get(0);
} else if (rowCount > 1) {
lookupValue = values.get(0);
log.warn("Expected a single row, but returned multiple rows from lookup for target column {} on transform {} ", column.getTargetColumnName(), column.getTransformId());
} else if (values.size() == 0) {
log.info("Expected a single row, but returned no rows from lookup for target column {} on transform {}", column.getTargetColumnName(), column.getTransformId());
}
} else {
log.warn("Expected SQL expression for lookup transform, but no expression was found for target column {} on transform {}", column.getTargetColumnName(), column.getTransformId());
}
return lookupValue;
}
Aggregations