Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mybatis-generator-plugin
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
mybatis-generator-plugin
Commits
4f142907
Commit
4f142907
authored
May 17, 2017
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
对于Model生成WithBLOBs类时,upsert插件实现行为和官方插件保持一致
parent
2b88b81d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
20 deletions
+23
-20
src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
...sw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
+4
-4
src/main/java/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
...ava/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
+19
-16
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
View file @
4f142907
...
...
@@ -169,7 +169,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
List
<
XmlElement
>
eles
=
this
.
findEle
(
xmlElement
,
"trim"
);
this
.
replaceEle
(
eles
.
get
(
0
),
"record."
);
// upsertByExampleSelective的第二个trim比较特殊,需另行处理
this
.
replaceEleForUpsertByExampleSelective
(
eles
.
get
(
1
),
"record."
,
introspectedTable
,
false
);
this
.
replaceEleForUpsertByExampleSelective
(
eles
.
get
(
1
),
"record."
,
introspectedTable
,
!
introspectedTable
.
getRules
().
generateRecordWithBLOBsClass
()
);
List
<
XmlElement
>
eles1
=
this
.
findEle
(
xmlElement
,
"set"
);
for
(
XmlElement
ele
:
eles1
)
{
...
...
@@ -280,15 +280,15 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
* @param element
* @param prefix
* @param introspectedTable
* @param
withBLOB
s
* @param
allColumn
s
*/
private
void
replaceEleForUpsertByExampleSelective
(
XmlElement
element
,
String
prefix
,
IntrospectedTable
introspectedTable
,
boolean
withBLOB
s
)
{
private
void
replaceEleForUpsertByExampleSelective
(
XmlElement
element
,
String
prefix
,
IntrospectedTable
introspectedTable
,
boolean
allColumn
s
)
{
// choose
XmlElement
chooseEle
=
new
XmlElement
(
"choose"
);
// when
XmlElement
whenEle
=
new
XmlElement
(
"when"
);
whenEle
.
addAttribute
(
new
Attribute
(
"test"
,
prefix
+
"isSelective()"
));
for
(
IntrospectedColumn
introspectedColumn
:
withBLOBs
?
introspectedTable
.
getAllColumns
()
:
introspectedTable
.
getNonBLOBColumns
(
))
{
for
(
IntrospectedColumn
introspectedColumn
:
(
allColumns
?
introspectedTable
.
getAllColumns
()
:
introspectedTable
.
getNonBLOBColumns
()
))
{
XmlElement
eleIf
=
new
XmlElement
(
"if"
);
eleIf
.
addAttribute
(
new
Attribute
(
"test"
,
prefix
+
"isSelective(\'"
+
MyBatis3FormattingUtilities
.
getEscapedColumnName
(
introspectedColumn
)
+
"\')"
));
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/UpsertPlugin.java
View file @
4f142907
...
...
@@ -340,6 +340,10 @@ public class UpsertPlugin extends BasePlugin {
* @param introspectedTable
*/
private
void
generateXmlElementWithoutBLOBs
(
Document
document
,
IntrospectedTable
introspectedTable
){
// WithoutBLOBs也会存在只有一个时,不生成WithBLOBs对象的情况
boolean
flag
=
!
introspectedTable
.
getRules
().
generateRecordWithBLOBsClass
();
List
<
IntrospectedColumn
>
columns
=
flag
?
introspectedTable
.
getAllColumns
()
:
introspectedTable
.
getNonBLOBColumns
();
// ====================================== 1. upsert ======================================
XmlElement
eleUpsert
=
new
XmlElement
(
"insert"
);
eleUpsert
.
addAttribute
(
new
Attribute
(
"id"
,
METHOD_UPSERT
));
...
...
@@ -354,11 +358,11 @@ public class UpsertPlugin extends BasePlugin {
// insert
eleUpsert
.
addElement
(
new
TextElement
(
"insert into "
+
introspectedTable
.
getFullyQualifiedTableNameAtRuntime
()));
eleUpsert
.
addElement
(
XmlElementGeneratorTools
.
generateKeys
(
introspectedTable
.
getNonBLOBColumns
()
));
eleUpsert
.
addElement
(
XmlElementGeneratorTools
.
generateKeys
(
columns
));
eleUpsert
.
addElement
(
new
TextElement
(
"values"
));
eleUpsert
.
addElement
(
XmlElementGeneratorTools
.
generateValues
(
introspectedTable
.
getNonBLOBColumns
()
));
eleUpsert
.
addElement
(
XmlElementGeneratorTools
.
generateValues
(
columns
));
eleUpsert
.
addElement
(
new
TextElement
(
"on duplicate key update "
));
eleUpsert
.
addElement
(
XmlElementGeneratorTools
.
generateSets
(
introspectedTable
.
getNonBLOBColumns
()
));
eleUpsert
.
addElement
(
XmlElementGeneratorTools
.
generateSets
(
columns
));
document
.
getRootElement
().
addElement
(
eleUpsert
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()
+
"增加upsert实现方法。"
);
...
...
@@ -377,11 +381,11 @@ public class UpsertPlugin extends BasePlugin {
// insert
eleUpsertSelective
.
addElement
(
new
TextElement
(
"insert into "
+
introspectedTable
.
getFullyQualifiedTableNameAtRuntime
()));
eleUpsertSelective
.
addElement
(
XmlElementGeneratorTools
.
generateKeysSelective
(
introspectedTable
.
getNonBLOBColumns
()
));
eleUpsertSelective
.
addElement
(
XmlElementGeneratorTools
.
generateKeysSelective
(
columns
));
eleUpsertSelective
.
addElement
(
new
TextElement
(
"values"
));
eleUpsertSelective
.
addElement
(
XmlElementGeneratorTools
.
generateValuesSelective
(
introspectedTable
.
getNonBLOBColumns
()
));
eleUpsertSelective
.
addElement
(
XmlElementGeneratorTools
.
generateValuesSelective
(
columns
));
eleUpsertSelective
.
addElement
(
new
TextElement
(
"on duplicate key update "
));
eleUpsertSelective
.
addElement
(
XmlElementGeneratorTools
.
generateSetsSelective
(
introspectedTable
.
getNonBLOBColumns
()
,
null
,
false
));
eleUpsertSelective
.
addElement
(
XmlElementGeneratorTools
.
generateSetsSelective
(
columns
,
null
,
false
));
document
.
getRootElement
().
addElement
(
eleUpsertSelective
);
logger
.
debug
(
"itfsw(存在即更新插件):"
+
introspectedTable
.
getMyBatis3XmlMapperFileName
()
+
"增加upsertSelective实现方法。"
);
...
...
@@ -400,8 +404,8 @@ public class UpsertPlugin extends BasePlugin {
// insert
eleUpsertByExample
.
addElement
(
new
TextElement
(
"insert into "
+
introspectedTable
.
getFullyQualifiedTableNameAtRuntime
()));
eleUpsertByExample
.
addElement
(
XmlElementGeneratorTools
.
generateKeys
(
introspectedTable
.
getNonBLOBColumns
()
));
this
.
generateExistsClause
(
introspectedTable
,
eleUpsertByExample
,
false
,
f
alse
);
eleUpsertByExample
.
addElement
(
XmlElementGeneratorTools
.
generateKeys
(
columns
));
this
.
generateExistsClause
(
introspectedTable
,
eleUpsertByExample
,
false
,
f
lag
);
// multiQueries
eleUpsertByExample
.
addElement
(
new
TextElement
(
";"
));
...
...
@@ -409,7 +413,7 @@ public class UpsertPlugin extends BasePlugin {
// update
eleUpsertByExample
.
addElement
(
new
TextElement
(
"update "
+
introspectedTable
.
getAliasedFullyQualifiedTableNameAtRuntime
()));
eleUpsertByExample
.
addElement
(
new
TextElement
(
"set"
));
eleUpsertByExample
.
addElement
(
XmlElementGeneratorTools
.
generateSets
(
ListUtilities
.
removeIdentityAndGeneratedAlwaysColumns
(
introspectedTable
.
getNonBLOBColumns
()
),
"record."
));
eleUpsertByExample
.
addElement
(
XmlElementGeneratorTools
.
generateSets
(
ListUtilities
.
removeIdentityAndGeneratedAlwaysColumns
(
columns
),
"record."
));
// update where
eleUpsertByExample
.
addElement
(
XmlElementGeneratorTools
.
getUpdateByExampleIncludeElement
(
introspectedTable
));
...
...
@@ -429,8 +433,8 @@ public class UpsertPlugin extends BasePlugin {
// insert
eleUpsertByExampleSelective
.
addElement
(
new
TextElement
(
"insert into "
+
introspectedTable
.
getFullyQualifiedTableNameAtRuntime
()));
eleUpsertByExampleSelective
.
addElement
(
XmlElementGeneratorTools
.
generateKeysSelective
(
introspectedTable
.
getNonBLOBColumns
()
,
"record."
));
this
.
generateExistsClause
(
introspectedTable
,
eleUpsertByExampleSelective
,
true
,
f
alse
);
eleUpsertByExampleSelective
.
addElement
(
XmlElementGeneratorTools
.
generateKeysSelective
(
columns
,
"record."
));
this
.
generateExistsClause
(
introspectedTable
,
eleUpsertByExampleSelective
,
true
,
f
lag
);
// multiQueries
eleUpsertByExampleSelective
.
addElement
(
new
TextElement
(
";"
));
...
...
@@ -438,7 +442,7 @@ public class UpsertPlugin extends BasePlugin {
// update
eleUpsertByExampleSelective
.
addElement
(
new
TextElement
(
"update "
+
introspectedTable
.
getAliasedFullyQualifiedTableNameAtRuntime
()));
eleUpsertByExampleSelective
.
addElement
(
new
TextElement
(
"set"
));
eleUpsertByExampleSelective
.
addElement
(
XmlElementGeneratorTools
.
generateSetsSelective
(
ListUtilities
.
removeIdentityAndGeneratedAlwaysColumns
(
introspectedTable
.
getNonBLOBColumns
()
),
"record."
));
eleUpsertByExampleSelective
.
addElement
(
XmlElementGeneratorTools
.
generateSetsSelective
(
ListUtilities
.
removeIdentityAndGeneratedAlwaysColumns
(
columns
),
"record."
));
// update where
eleUpsertByExampleSelective
.
addElement
(
XmlElementGeneratorTools
.
getUpdateByExampleIncludeElement
(
introspectedTable
));
...
...
@@ -454,12 +458,11 @@ public class UpsertPlugin extends BasePlugin {
* @param introspectedTable
* @param element
* @param selective
* @param
withBLOB
s
* @param
allColumn
s
*/
private
void
generateExistsClause
(
IntrospectedTable
introspectedTable
,
XmlElement
element
,
boolean
selective
,
boolean
withBLOBs
){
private
void
generateExistsClause
(
IntrospectedTable
introspectedTable
,
XmlElement
element
,
boolean
selective
,
boolean
allColumns
){
List
<
IntrospectedColumn
>
columns
=
allColumns
?
introspectedTable
.
getAllColumns
()
:
introspectedTable
.
getNonBLOBColumns
();
List
<
IntrospectedColumn
>
columns
=
withBLOBs
?
introspectedTable
.
getAllColumns
()
:
introspectedTable
.
getNonBLOBColumns
();
logger
.
warn
(
withBLOBs
+
" ::::: "
+
columns
.
size
());
element
.
addElement
(
new
TextElement
(
"select"
));
if
(
selective
){
element
.
addElement
(
XmlElementGeneratorTools
.
generateValuesSelective
(
columns
,
"record."
,
false
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment