1
- package com .github .dcendents .mybatis .generator .plugin .mapper ;
1
+ package com .github .dcendents .mybatis .generator .plugin .client ;
2
2
3
3
import java .util .List ;
4
4
import java .util .regex .Pattern ;
@@ -25,8 +25,10 @@ public class AlterResultMapPlugin extends PluginAdapter {
25
25
26
26
private String tableName ;
27
27
private String resultMapId ;
28
-
29
- private static Pattern annotationPattern = Pattern .compile ("@ResultMap\\ (\" .*\" \\ )" );
28
+
29
+ static final String RESULT_MAP_ATTRIBUTE = "resultMap" ;
30
+ static final Pattern ANNOTATION_PATTERN = Pattern .compile ("@ResultMap\\ (\" .*\" \\ )" );
31
+ static final String ANNOTATION_FORMAT = "@ResultMap(\" %s\" )" ;
30
32
31
33
@ Override
32
34
public boolean validate (List <String > warnings ) {
@@ -48,138 +50,128 @@ private boolean tableMatches(IntrospectedTable introspectedTable) {
48
50
return tableName .equals (introspectedTable .getFullyQualifiedTableNameAtRuntime ());
49
51
}
50
52
51
- private void renameResultMapAttribute (XmlElement element ) {
52
- List <Attribute > attributes = element .getAttributes ();
53
-
54
- for (int i = 0 ; i < attributes .size (); i ++) {
55
- Attribute attribute = attributes .get (i );
56
- if ("resultMap" .equals (attribute .getName ())) {
57
- Attribute newAtt = new Attribute ("resultMap" , resultMapId );
58
- attributes .remove (i );
59
- attributes .add (newAtt );
60
- break ;
53
+ void renameResultMapAttribute (XmlElement element , IntrospectedTable introspectedTable ) {
54
+ if (tableMatches (introspectedTable )) {
55
+ List <Attribute > attributes = element .getAttributes ();
56
+
57
+ for (int i = 0 ; i < attributes .size (); i ++) {
58
+ Attribute attribute = attributes .get (i );
59
+ if (RESULT_MAP_ATTRIBUTE .equals (attribute .getName ())) {
60
+ Attribute newAtt = new Attribute (RESULT_MAP_ATTRIBUTE , resultMapId );
61
+ attributes .remove (i );
62
+ attributes .add (newAtt );
63
+ break ;
64
+ }
61
65
}
62
66
}
63
67
}
64
68
65
- private void renameResultMapAttribute (Method method ) {
66
- List <String > annotations = method .getAnnotations ();
67
-
68
- for (int i = 0 ; i < annotations .size (); i ++) {
69
- String annotation = annotations .get (i );
70
- if (annotationPattern .matcher (annotation ).matches ()) {
71
- String newAnnotation = String .format ("@ResultMap(\" %s\" )" , resultMapId );
72
- annotations .remove (i );
73
- annotations .add (newAnnotation );
74
- break ;
69
+ void renameResultMapAttribute (Method method , IntrospectedTable introspectedTable ) {
70
+ if (tableMatches (introspectedTable )) {
71
+ List <String > annotations = method .getAnnotations ();
72
+
73
+ for (int i = 0 ; i < annotations .size (); i ++) {
74
+ String annotation = annotations .get (i );
75
+ if (ANNOTATION_PATTERN .matcher (annotation ).matches ()) {
76
+ String newAnnotation = String .format (ANNOTATION_FORMAT , resultMapId );
77
+ annotations .remove (i );
78
+ annotations .add (newAnnotation );
79
+ break ;
80
+ }
75
81
}
76
82
}
77
83
}
78
84
79
85
@ Override
80
- public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated (XmlElement element , IntrospectedTable introspectedTable ) {
81
- if (tableMatches (introspectedTable )) {
82
- renameResultMapAttribute (element );
83
- }
86
+ public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated (XmlElement element ,
87
+ IntrospectedTable introspectedTable ) {
88
+ renameResultMapAttribute (element , introspectedTable );
84
89
85
90
return true ;
86
91
}
87
92
88
93
@ Override
89
- public boolean sqlMapSelectByExampleWithBLOBsElementGenerated (XmlElement element , IntrospectedTable introspectedTable ) {
90
- if (tableMatches (introspectedTable )) {
91
- renameResultMapAttribute (element );
92
- }
94
+ public boolean sqlMapSelectByExampleWithBLOBsElementGenerated (XmlElement element ,
95
+ IntrospectedTable introspectedTable ) {
96
+ renameResultMapAttribute (element , introspectedTable );
93
97
94
98
return true ;
95
99
}
96
100
97
101
@ Override
98
102
public boolean sqlMapSelectByPrimaryKeyElementGenerated (XmlElement element , IntrospectedTable introspectedTable ) {
99
- if (tableMatches (introspectedTable )) {
100
- renameResultMapAttribute (element );
101
- }
103
+ renameResultMapAttribute (element , introspectedTable );
102
104
103
105
return true ;
104
106
}
105
107
106
108
@ Override
107
109
public boolean sqlMapSelectAllElementGenerated (XmlElement element , IntrospectedTable introspectedTable ) {
108
- if (tableMatches (introspectedTable )) {
109
- renameResultMapAttribute (element );
110
- }
110
+ renameResultMapAttribute (element , introspectedTable );
111
111
112
112
return true ;
113
113
}
114
114
115
115
@ Override
116
- public boolean clientSelectByExampleWithBLOBsMethodGenerated (Method method , Interface interfaze , IntrospectedTable introspectedTable ) {
117
- if (tableMatches (introspectedTable )) {
118
- renameResultMapAttribute (method );
119
- }
116
+ public boolean clientSelectByExampleWithBLOBsMethodGenerated (Method method , Interface interfaze ,
117
+ IntrospectedTable introspectedTable ) {
118
+ renameResultMapAttribute (method , introspectedTable );
120
119
121
120
return true ;
122
121
}
123
122
124
123
@ Override
125
- public boolean clientSelectByExampleWithBLOBsMethodGenerated (Method method , TopLevelClass topLevelClass , IntrospectedTable introspectedTable ) {
126
- if (tableMatches (introspectedTable )) {
127
- renameResultMapAttribute (method );
128
- }
124
+ public boolean clientSelectByExampleWithBLOBsMethodGenerated (Method method , TopLevelClass topLevelClass ,
125
+ IntrospectedTable introspectedTable ) {
126
+ renameResultMapAttribute (method , introspectedTable );
129
127
130
128
return true ;
131
129
}
132
130
133
131
@ Override
134
- public boolean clientSelectByExampleWithoutBLOBsMethodGenerated (Method method , Interface interfaze , IntrospectedTable introspectedTable ) {
135
- if (tableMatches (introspectedTable )) {
136
- renameResultMapAttribute (method );
137
- }
132
+ public boolean clientSelectByExampleWithoutBLOBsMethodGenerated (Method method , Interface interfaze ,
133
+ IntrospectedTable introspectedTable ) {
134
+ renameResultMapAttribute (method , introspectedTable );
138
135
139
136
return true ;
140
137
}
141
138
142
139
@ Override
143
- public boolean clientSelectByExampleWithoutBLOBsMethodGenerated (Method method , TopLevelClass topLevelClass , IntrospectedTable introspectedTable ) {
144
- if (tableMatches (introspectedTable )) {
145
- renameResultMapAttribute (method );
146
- }
140
+ public boolean clientSelectByExampleWithoutBLOBsMethodGenerated (Method method , TopLevelClass topLevelClass ,
141
+ IntrospectedTable introspectedTable ) {
142
+ renameResultMapAttribute (method , introspectedTable );
147
143
148
144
return true ;
149
145
}
150
146
151
147
@ Override
152
- public boolean clientSelectByPrimaryKeyMethodGenerated (Method method , Interface interfaze , IntrospectedTable introspectedTable ) {
153
- if (tableMatches (introspectedTable )) {
154
- renameResultMapAttribute (method );
155
- }
148
+ public boolean clientSelectByPrimaryKeyMethodGenerated (Method method , Interface interfaze ,
149
+ IntrospectedTable introspectedTable ) {
150
+ renameResultMapAttribute (method , introspectedTable );
156
151
157
152
return true ;
158
153
}
159
154
160
155
@ Override
161
- public boolean clientSelectByPrimaryKeyMethodGenerated (Method method , TopLevelClass topLevelClass , IntrospectedTable introspectedTable ) {
162
- if (tableMatches (introspectedTable )) {
163
- renameResultMapAttribute (method );
164
- }
156
+ public boolean clientSelectByPrimaryKeyMethodGenerated (Method method , TopLevelClass topLevelClass ,
157
+ IntrospectedTable introspectedTable ) {
158
+ renameResultMapAttribute (method , introspectedTable );
165
159
166
160
return true ;
167
161
}
168
162
169
163
@ Override
170
- public boolean clientSelectAllMethodGenerated (Method method , Interface interfaze , IntrospectedTable introspectedTable ) {
171
- if (tableMatches (introspectedTable )) {
172
- renameResultMapAttribute (method );
173
- }
164
+ public boolean clientSelectAllMethodGenerated (Method method , Interface interfaze ,
165
+ IntrospectedTable introspectedTable ) {
166
+ renameResultMapAttribute (method , introspectedTable );
174
167
175
168
return true ;
176
169
}
177
170
178
171
@ Override
179
- public boolean clientSelectAllMethodGenerated (Method method , TopLevelClass topLevelClass , IntrospectedTable introspectedTable ) {
180
- if (tableMatches (introspectedTable )) {
181
- renameResultMapAttribute (method );
182
- }
172
+ public boolean clientSelectAllMethodGenerated (Method method , TopLevelClass topLevelClass ,
173
+ IntrospectedTable introspectedTable ) {
174
+ renameResultMapAttribute (method , introspectedTable );
183
175
184
176
return true ;
185
177
}
0 commit comments