Commit 07c78ddd authored by hewei's avatar hewei

增加SelectiveEnhancedPlugin插件;

parent bfbae5f3
...@@ -87,14 +87,18 @@ public class SelectiveEnhancedPlugin extends PluginAdapter { ...@@ -87,14 +87,18 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
CommentTools.addMethodComment(mIsSelective, introspectedTable); CommentTools.addMethodComment(mIsSelective, introspectedTable);
mIsSelective.setVisibility(JavaVisibility.PUBLIC); mIsSelective.setVisibility(JavaVisibility.PUBLIC);
mIsSelective.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance()); mIsSelective.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
mIsSelective.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "column"));
mIsSelective.addBodyLine("if (column == null) {");
mIsSelective.addBodyLine("return this.selectiveColumns.size() > 0;"); mIsSelective.addBodyLine("return this.selectiveColumns.size() > 0;");
mIsSelective.addBodyLine("} else {");
mIsSelective.addBodyLine("return this.selectiveColumns.get(column) != null;");
mIsSelective.addBodyLine("}");
topLevelClass.addMethod(mIsSelective); topLevelClass.addMethod(mIsSelective);
// Method isSelective
Method mIsSelective1 = new Method("isSelective");
CommentTools.addMethodComment(mIsSelective1, introspectedTable);
mIsSelective1.setVisibility(JavaVisibility.PUBLIC);
mIsSelective1.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
mIsSelective1.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "column"));
mIsSelective1.addBodyLine("return this.selectiveColumns.get(column) != null;");
topLevelClass.addMethod(mIsSelective1);
// Method selective // Method selective
Method mSelective = new Method("selective"); Method mSelective = new Method("selective");
CommentTools.addMethodComment(mSelective, introspectedTable); CommentTools.addMethodComment(mSelective, introspectedTable);
...@@ -137,11 +141,44 @@ public class SelectiveEnhancedPlugin extends PluginAdapter { ...@@ -137,11 +141,44 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
// ====================================== 1. insertSelective ====================================== // ====================================== 1. insertSelective ======================================
if ("insertSelective".equals(id)) { if ("insertSelective".equals(id)) {
List<XmlElement> trimEles = this.findEle(xmlElement, "trim"); List<XmlElement> eles = this.findEle(xmlElement, "trim");
for (XmlElement ele : trimEles) { for (XmlElement ele : eles) {
this.replaceEle(ele, "_parameter.");
}
}
// ====================================== 2. updateByExampleSelective ======================================
if ("updateByExampleSelective".equals(id)) {
List<XmlElement> eles = this.findEle(xmlElement, "set");
for (XmlElement ele : eles) {
this.replaceEle(ele, "_parameter."); this.replaceEle(ele, "_parameter.");
} }
} }
// ====================================== 3. updateByPrimaryKeySelective ======================================
if ("updateByPrimaryKeySelective".equals(id)) {
List<XmlElement> eles = this.findEle(xmlElement, "set");
for (XmlElement ele : eles) {
this.replaceEle(ele, "_parameter.");
}
}
// ====================================== 4. upsertSelective ======================================
if ("upsertSelective".equals(id)) {
List<XmlElement> eles = this.findEle(xmlElement, "trim");
for (XmlElement ele : eles) {
this.replaceEle(ele, "_parameter.");
}
}
// ====================================== 5. upsertByExampleSelective ======================================
if ("upsertByExampleSelective".equals(id)) {
List<XmlElement> eles = this.findEle(xmlElement, "trim");
for (XmlElement ele : eles) {
this.replaceEle(ele, "_parameter.");
}
List<XmlElement> eles1 = this.findEle(xmlElement, "set");
for (XmlElement ele : eles1) {
this.replaceEle(ele, "_parameter.");
}
}
} }
} }
return true; return true;
...@@ -187,7 +224,7 @@ public class SelectiveEnhancedPlugin extends PluginAdapter { ...@@ -187,7 +224,7 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
String text = textElement.getContent().trim(); String text = textElement.getContent().trim();
String field = ""; String field = "";
if (text.matches(".*\\s*=\\s*#\\{.*\\},?")) { if (text.matches(".*\\s*=\\s*#\\{.*\\},?")) {
Pattern pattern = Pattern.compile("(.*)\\s*=\\s*#\\{.*},?"); Pattern pattern = Pattern.compile("(.*?)\\s*=\\s*#\\{.*},?");
Matcher matcher = pattern.matcher(text); Matcher matcher = pattern.matcher(text);
if (matcher.find()){ if (matcher.find()){
field = matcher.group(1); field = matcher.group(1);
...@@ -203,7 +240,7 @@ public class SelectiveEnhancedPlugin extends PluginAdapter { ...@@ -203,7 +240,7 @@ public class SelectiveEnhancedPlugin extends PluginAdapter {
} }
XmlElement ifEle = new XmlElement("if"); XmlElement ifEle = new XmlElement("if");
ifEle.addAttribute(new Attribute("test", prefix + "isSelective(" + field + ")")); ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + field + "\')"));
ifEle.addElement(textElement); ifEle.addElement(textElement);
whenEle.addElement(ifEle); whenEle.addElement(ifEle);
} }
......
...@@ -255,7 +255,7 @@ public class UpsertPlugin extends PluginAdapter { ...@@ -255,7 +255,7 @@ public class UpsertPlugin extends PluginAdapter {
// update // update
eleUpsertByExampleSelective.addElement(new TextElement("update " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime())); eleUpsertByExampleSelective.addElement(new TextElement("update " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));
eleUpsertByExampleSelective.addElement(new TextElement("set")); eleUpsertByExampleSelective.addElement(new TextElement("set"));
eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.generateSets(ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns()), "record.")); eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.generateSetsSelective(ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getAllColumns()), "record."));
// update where // update where
eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.getUpdateByExampleIncludeElement(introspectedTable)); eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.getUpdateByExampleIncludeElement(introspectedTable));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment