String[] contents = StringUtils.split(StringUtils.replace(patternContent, " and ", "$"), "$");
StringBuilder singleConBuf = new StringBuilder("(");
for (int i = 0; i < contents.length; i++) {
String content = contents[i];
Condition c = new Condition(content);
List<String> params = c.getParamNames();
for (final String paramName : params) {
RestrictField param = pattern.getEntity().getField(paramName);
String value = restriction.getItem(param);
if (StringUtils.isNotEmpty(value)) {
if (value.equals(Restriction.ALL)) {
content = "";
} else {
content = StringUtils.replace(content, ":" + param.getName(),
":" + param.getName() + index);
paramValues.add(getFieldValue(param, restriction));
}
} else {
throw new RuntimeException(paramName + " had not been initialized");
}
}
if (singleConBuf.length() > 1 && content.length() > 0) {
singleConBuf.append(" and ");
}
singleConBuf.append(content);
}
if (singleConBuf.length() > 1) {
singleConBuf.append(')');
if (conBuffer.length() > 0) {
conBuffer.append(" or ");
}
conBuffer.append(singleConBuf.toString());
}
index++;
}
if (conBuffer.length() > 0) {
Condition con = new Condition(conBuffer.toString());
con.params(paramValues);
query.where(con);
}
}