// 替换所有条件parameterType中的pojoExample
List<Element> list = document.getRootElement().getElements();
logger.info(list.size() + "");
for (int i = 0; i < list.size(); i++) {
XmlElement xml = (XmlElement) list.get(i);
String content = xml.getFormattedContent(0);
if (content.contains(introspectedTable.getExampleType())) {
List<Attribute> attrs = xml.getAttributes();
for (int j = 0; j < attrs.size(); j++) {
if (attrs.get(j).getName().equals("parameterType")) {
attrs.get(j).setValue(criteria.getFullyQualifiedName());
}
}
} else if (content.contains("Update_By_Example_Where_Clause") && isAllInOne) {
if (xml.getElements().size() == 3) {
xml = (XmlElement) xml.getElements().get(2);
xml = (XmlElement) xml.getElements().get(0);
xml.getAttributes().get(0).setValue("Example_Where_Clause");
} else {
for (int j = 0; j < xml.getElements().size(); j++) {
Element xmls = xml.getElements().get(j);
if (xmls.getFormattedContent(0).contains("Update_By_Example_Where_Clause")) {
xml = (XmlElement) xmls;
xml = (XmlElement) xml.getElements().get(0);
xml.getAttributes().get(0).setValue("Example_Where_Clause");
}
}
}
}
}
// Example_Where_Clause
XmlElement Where_Clause = (XmlElement) document.getRootElement().getElements().get(1);
// 移除第一个
Where_Clause.removeElement(0);
StringBuilder sb = new StringBuilder();
XmlElement dynamicElement = new XmlElement("trim"); //$NON-NLS-1$
dynamicElement.addAttribute(new Attribute("prefix", "where")); //$NON-NLS-1$ //$NON-NLS-2$
dynamicElement.addAttribute(new Attribute("prefixOverrides", "and|or")); //$NON-NLS-1$ //$NON-NLS-2$
Where_Clause.addElement(dynamicElement);
for (IntrospectedColumn introspectedColumn : introspectedTable.getNonPrimaryKeyColumns()) {
XmlElement isNotNullElement = new XmlElement("if"); //$NON-NLS-1$
if (isAllInOne) {
String va = introspectedColumn.getJavaProperty("example.condition.") + " != null";
isNotNullElement.addAttribute(new Attribute("test", va)); //$NON-NLS-1$ //$NON-NLS-2$
} else {
String va = introspectedColumn.getJavaProperty("condition.") + " != null";
isNotNullElement.addAttribute(new Attribute("test", va)); //$NON-NLS-1$ //$NON-NLS-2$
}
dynamicElement.addElement(isNotNullElement);
sb.setLength(0);
sb.append(" and "); //$NON-NLS-1$
sb.append(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn));
sb.append(" = "); //$NON-NLS-1$
if (isAllInOne) {
sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "example.condition."));
} else {
sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "condition."));
}
isNotNullElement.addElement(new TextElement(sb.toString()));
}
if (!isAllInOne) {
// Example_Where_Clause
Where_Clause = (XmlElement) document.getRootElement().getElements().get(2);
// 移除第一个
Where_Clause.removeElement(0);
sb = new StringBuilder();
dynamicElement = new XmlElement("trim"); //$NON-NLS-1$
dynamicElement.addAttribute(new Attribute("prefix", "where")); //$NON-NLS-1$ //$NON-NLS-2$
dynamicElement.addAttribute(new Attribute("prefixOverrides", "and|or")); //$NON-NLS-1$ //$NON-NLS-2$
Where_Clause.addElement(dynamicElement);
for (IntrospectedColumn introspectedColumn : introspectedTable.getNonPrimaryKeyColumns()) {
XmlElement isNotNullElement = new XmlElement("if"); //$NON-NLS-1$
String va = introspectedColumn.getJavaProperty("example.condition.") + " != null";
isNotNullElement.addAttribute(new Attribute("test", va)); //$NON-NLS-1$ //$NON-NLS-2$
dynamicElement.addElement(isNotNullElement);
sb.setLength(0);
sb.append(" and "); //$NON-NLS-1$
sb.append(Ibatis2FormattingUtilities.getEscapedColumnName(introspectedColumn));
sb.append(" = "); //$NON-NLS-1$
sb.append(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, "example.condition."));
isNotNullElement.addElement(new TextElement(sb.toString()));
}
} else {
document.getRootElement().getElements().remove(2);
}
return true;