|
40 | 40 | * --------------------------------------------------------------------------- |
41 | 41 | */ |
42 | 42 | public class SelectiveEnhancedPlugin extends BasePlugin { |
| 43 | + public static final String METHOD_HAS_SELECTIVE = "hasSelective"; // 方法名 |
43 | 44 |
|
44 | 45 | /** |
45 | 46 | * {@inheritDoc} |
@@ -80,22 +81,22 @@ public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, Intros |
80 | 81 | selectiveColumnsField.setInitializationString("new HashMap<String, Boolean>()"); |
81 | 82 | topLevelClass.addField(selectiveColumnsField); |
82 | 83 |
|
83 | | - // Method isSelective |
84 | | - Method mIsSelective = new Method("isSelective"); |
85 | | - commentGenerator.addGeneralMethodComment(mIsSelective, introspectedTable); |
86 | | - mIsSelective.setVisibility(JavaVisibility.PUBLIC); |
87 | | - mIsSelective.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance()); |
88 | | - mIsSelective.addBodyLine("return this.selectiveColumns.size() > 0;"); |
89 | | - topLevelClass.addMethod(mIsSelective); |
| 84 | + // Method hasSelective |
| 85 | + Method mHasSelective = new Method(METHOD_HAS_SELECTIVE); |
| 86 | + commentGenerator.addGeneralMethodComment(mHasSelective, introspectedTable); |
| 87 | + mHasSelective.setVisibility(JavaVisibility.PUBLIC); |
| 88 | + mHasSelective.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance()); |
| 89 | + mHasSelective.addBodyLine("return this.selectiveColumns.size() > 0;"); |
| 90 | + topLevelClass.addMethod(mHasSelective); |
90 | 91 |
|
91 | | - // Method isSelective |
92 | | - Method mIsSelective1 = new Method("isSelective"); |
93 | | - commentGenerator.addGeneralMethodComment(mIsSelective1, introspectedTable); |
94 | | - mIsSelective1.setVisibility(JavaVisibility.PUBLIC); |
95 | | - mIsSelective1.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance()); |
96 | | - mIsSelective1.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "column")); |
97 | | - mIsSelective1.addBodyLine("return this.selectiveColumns.get(column) != null;"); |
98 | | - topLevelClass.addMethod(mIsSelective1); |
| 92 | + // Method hasSelective |
| 93 | + Method mHasSelective1 = new Method(METHOD_HAS_SELECTIVE); |
| 94 | + commentGenerator.addGeneralMethodComment(mHasSelective1, introspectedTable); |
| 95 | + mHasSelective1.setVisibility(JavaVisibility.PUBLIC); |
| 96 | + mHasSelective1.setReturnType(FullyQualifiedJavaType.getBooleanPrimitiveInstance()); |
| 97 | + mHasSelective1.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "column")); |
| 98 | + mHasSelective1.addBodyLine("return this.selectiveColumns.get(column) != null;"); |
| 99 | + topLevelClass.addMethod(mHasSelective1); |
99 | 100 |
|
100 | 101 | // Method selective |
101 | 102 | Method mSelective = new Method("selective"); |
@@ -195,7 +196,7 @@ private void replaceEle(XmlElement element, String prefix, IntrospectedTable int |
195 | 196 | XmlElement chooseEle = new XmlElement("choose"); |
196 | 197 | // when |
197 | 198 | XmlElement whenEle = new XmlElement("when"); |
198 | | - whenEle.addAttribute(new Attribute("test", prefix + "isSelective()")); |
| 199 | + whenEle.addAttribute(new Attribute("test", prefix + METHOD_HAS_SELECTIVE + "()")); |
199 | 200 | for (Element ele : element.getElements()) { |
200 | 201 | // 对于字符串主键,是没有if判断节点的 |
201 | 202 | if (ele instanceof XmlElement) { |
@@ -232,7 +233,7 @@ private void replaceEle(XmlElement element, String prefix, IntrospectedTable int |
232 | 233 |
|
233 | 234 | XmlElement ifEle = new XmlElement("if"); |
234 | 235 |
|
235 | | - ifEle.addAttribute(new Attribute("test", prefix + "isSelective(\'" + column.getActualColumnName() + "\')")); |
| 236 | + ifEle.addAttribute(new Attribute("test", prefix + METHOD_HAS_SELECTIVE + "(\'" + column.getActualColumnName() + "\')")); |
236 | 237 | for (Element ifChild : xmlElement.getElements()) { |
237 | 238 | ifEle.addElement(ifChild); |
238 | 239 | } |
@@ -269,10 +270,10 @@ private void replaceEleForUpsertByExampleSelective(XmlElement element, String pr |
269 | 270 | XmlElement chooseEle = new XmlElement("choose"); |
270 | 271 | // when |
271 | 272 | XmlElement whenEle = new XmlElement("when"); |
272 | | - whenEle.addAttribute(new Attribute("test", prefix + "isSelective()")); |
| 273 | + whenEle.addAttribute(new Attribute("test", prefix + METHOD_HAS_SELECTIVE + "()")); |
273 | 274 | for (IntrospectedColumn introspectedColumn : (allColumns ? introspectedTable.getAllColumns() : introspectedTable.getNonBLOBColumns())) { |
274 | 275 | XmlElement eleIf = new XmlElement("if"); |
275 | | - eleIf.addAttribute(new Attribute("test", prefix + "isSelective(\'" + introspectedColumn.getActualColumnName() + "\')")); |
| 276 | + eleIf.addAttribute(new Attribute("test", prefix + METHOD_HAS_SELECTIVE + "(\'" + introspectedColumn.getActualColumnName() + "\')")); |
276 | 277 |
|
277 | 278 | eleIf.addElement(new TextElement(MyBatis3FormattingUtilities.getParameterClause(introspectedColumn, prefix) + ",")); |
278 | 279 | whenEle.addElement(eleIf); |
|
0 commit comments