use of org.eclipse.scout.rt.platform.util.StringUtility.ITagProcessor in project scout.rt by eclipse.
the class FormDataStatementBuilder method createSqlPart.
/**
* Create sql text, makes bind names unique, and adds all binds to the bind map
* <p>
* To use no operator use {@link DataModelConstants#OPERATOR_NONE} and null for binds and values, stm will be
* decorated and is the result itself
* <p>
* To use no aggregation use {@link DataModelConstants#AGGREGATION_NONE}
*/
@SuppressWarnings("bsiRulesDefinition:htmlInString")
public String createSqlPart(final Integer aggregationType, String sql, final int operation, List<String> bindNames, List<Object> bindValues, final boolean plainBind, Map<String, String> parentAliasMap) {
if (sql == null) {
sql = "";
}
if (bindNames == null) {
bindNames = new ArrayList<String>(0);
}
if (bindValues == null) {
bindValues = new ArrayList<Object>(0);
}
// by default
if (sql.indexOf("<attribute>") < 0) {
sql = "<attribute>" + sql + "</attribute>";
}
// convenience: automatically add missing alias on plain attributes, but only if the parent entity has at most 1 alias mapping
Matcher m = PLAIN_ATTRIBUTE_PATTERN.matcher(sql);
if (m.find()) {
if (parentAliasMap.size() == 0) {
// nop
} else if (parentAliasMap.size() == 1) {
sql = m.replaceAll("$1@parent." + parentAliasMap.keySet().iterator().next() + "@.$2$3");
} else {
throw new ProcessingException("root attribute with " + sql + " uses no @...@ alias prefix, but parent has more than 1 alias: " + parentAliasMap);
}
}
// resolve aliases
sql = m_aliasMapper.replaceMarkersByAliases(sql, parentAliasMap, parentAliasMap);
// generate unique bind names
final ArrayList<String> newBindNames = new ArrayList<String>(2);
for (int i = 0; i < bindNames.size(); i++) {
String o = bindNames.get(i);
String n = localizeBindName(o, "__");
newBindNames.add(n);
sql = localizeStatement(sql, o, n);
}
// part decoration
final List<Object> valuesFinal = bindValues;
ITagProcessor processor = new ITagProcessor() {
@Override
public String processTag(String tagName, String a) {
return createSqlOpValuePart(aggregationType, a, operation, newBindNames, valuesFinal, plainBind);
}
};
return StringUtility.replaceTags(sql, "attribute", processor);
}
Aggregations