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
ab702538
Commit
ab702538
authored
May 02, 2018
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构代码插件依赖关系
parent
23cf1069
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
13 deletions
+74
-13
src/main/java/com/itfsw/mybatis/generator/plugins/IncrementsPlugin.java
...com/itfsw/mybatis/generator/plugins/IncrementsPlugin.java
+41
-4
src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
...sw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
+11
-2
src/main/java/com/itfsw/mybatis/generator/plugins/utils/XmlElementGeneratorTools.java
...tis/generator/plugins/utils/XmlElementGeneratorTools.java
+4
-4
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/HookAggregator.java
.../mybatis/generator/plugins/utils/hook/HookAggregator.java
+11
-2
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/IIncrementsPluginHook.java
...s/generator/plugins/utils/hook/IIncrementsPluginHook.java
+7
-1
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/IncrementsPlugin.java
View file @
ab702538
...
@@ -247,10 +247,10 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
...
@@ -247,10 +247,10 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
* @return
* @return
*/
*/
@Override
@Override
public
List
<
Element
>
incrementElementGenerated
(
IntrospectedColumn
introspectedColumn
,
String
prefix
,
boolean
hasComma
)
{
public
List
<
Element
>
increment
Set
ElementGenerated
(
IntrospectedColumn
introspectedColumn
,
String
prefix
,
boolean
hasComma
)
{
List
<
Element
>
list
=
new
ArrayList
<>();
List
<
Element
>
list
=
new
ArrayList
<>();
if
(
incTools
.
supportColumn
(
introspectedColumn
)){
if
(
incTools
.
supportColumn
(
introspectedColumn
))
{
// 1. column = 节点
// 1. column = 节点
list
.
add
(
new
TextElement
(
MyBatis3FormattingUtilities
.
getEscapedColumnName
(
introspectedColumn
)
+
" = "
));
list
.
add
(
new
TextElement
(
MyBatis3FormattingUtilities
.
getEscapedColumnName
(
introspectedColumn
)
+
" = "
));
...
@@ -289,6 +289,43 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
...
@@ -289,6 +289,43 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
return
list
;
return
list
;
}
}
/**
* 生成增量操作节点(SelectiveEnhancedPlugin)
* @return
*/
@Override
public
Element
incrementSetsWithSelectiveEnhancedPluginElementGenerated
()
{
if
(
incTools
.
support
())
{
XmlElement
choose
=
new
XmlElement
(
"choose"
);
for
(
IntrospectedColumn
introspectedColumn
:
incTools
.
getColumns
())
{
XmlElement
when
=
new
XmlElement
(
"when"
);
// 需要 inc 的列
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"'"
);
sb
.
append
(
introspectedColumn
.
getActualColumnName
());
sb
.
append
(
"'.toString()"
);
sb
.
append
(
" == "
);
sb
.
append
(
"column.value"
);
when
.
addAttribute
(
new
Attribute
(
"test"
,
sb
.
toString
()));
when
.
addElement
(
new
TextElement
(
"${column.value} = ${column.value} ${record.incrementsColumnsInfoMap."
+
introspectedColumn
.
getActualColumnName
()
+
".value} #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"
));
choose
.
addElement
(
when
);
}
XmlElement
otherwise
=
new
XmlElement
(
"otherwise"
);
otherwise
.
addElement
(
new
TextElement
(
"${column.value} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"
));
choose
.
addElement
(
otherwise
);
return
choose
;
}
return
null
;
}
// =================================================== 原生方法的支持 ====================================================
// =================================================== 原生方法的支持 ====================================================
/**
/**
...
@@ -310,7 +347,7 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
...
@@ -310,7 +347,7 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
String
columnName
=
strs
[
0
].
trim
();
String
columnName
=
strs
[
0
].
trim
();
IntrospectedColumn
introspectedColumn
=
IntrospectedTableTools
.
safeGetColumn
(
introspectedTable
,
columnName
);
IntrospectedColumn
introspectedColumn
=
IntrospectedTableTools
.
safeGetColumn
(
introspectedTable
,
columnName
);
// 查找是否需要进行增量操作
// 查找是否需要进行增量操作
List
<
Element
>
incrementEles
=
PluginTools
.
getHook
(
IIncrementsPluginHook
.
class
).
incrementElementGenerated
(
introspectedColumn
,
hasPrefix
?
"record."
:
null
,
true
);
List
<
Element
>
incrementEles
=
PluginTools
.
getHook
(
IIncrementsPluginHook
.
class
).
increment
Set
ElementGenerated
(
introspectedColumn
,
hasPrefix
?
"record."
:
null
,
true
);
if
(!
incrementEles
.
isEmpty
())
{
if
(!
incrementEles
.
isEmpty
())
{
xmlElement
.
getElements
().
clear
();
xmlElement
.
getElements
().
clear
();
xmlElement
.
getElements
().
addAll
(
incrementEles
);
xmlElement
.
getElements
().
addAll
(
incrementEles
);
...
@@ -340,7 +377,7 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
...
@@ -340,7 +377,7 @@ public class IncrementsPlugin extends BasePlugin implements IModelBuilderPluginH
String
columnName
=
text
.
split
(
"="
)[
0
].
trim
();
String
columnName
=
text
.
split
(
"="
)[
0
].
trim
();
IntrospectedColumn
introspectedColumn
=
IntrospectedTableTools
.
safeGetColumn
(
introspectedTable
,
columnName
);
IntrospectedColumn
introspectedColumn
=
IntrospectedTableTools
.
safeGetColumn
(
introspectedTable
,
columnName
);
// 查找判断是否需要进行节点替换
// 查找判断是否需要进行节点替换
List
<
Element
>
incrementEles
=
PluginTools
.
getHook
(
IIncrementsPluginHook
.
class
).
incrementElementGenerated
(
introspectedColumn
,
hasPrefix
?
"record."
:
null
,
text
.
endsWith
(
","
));
List
<
Element
>
incrementEles
=
PluginTools
.
getHook
(
IIncrementsPluginHook
.
class
).
increment
Set
ElementGenerated
(
introspectedColumn
,
hasPrefix
?
"record."
:
null
,
text
.
endsWith
(
","
));
if
(!
incrementEles
.
isEmpty
())
{
if
(!
incrementEles
.
isEmpty
())
{
newEles
.
addAll
(
incrementEles
);
newEles
.
addAll
(
incrementEles
);
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/SelectiveEnhancedPlugin.java
View file @
ab702538
...
@@ -19,6 +19,7 @@ package com.itfsw.mybatis.generator.plugins;
...
@@ -19,6 +19,7 @@ package com.itfsw.mybatis.generator.plugins;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.PluginTools
;
import
com.itfsw.mybatis.generator.plugins.utils.PluginTools
;
import
com.itfsw.mybatis.generator.plugins.utils.XmlElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.XmlElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.hook.IIncrementsPluginHook
;
import
com.itfsw.mybatis.generator.plugins.utils.hook.IUpsertPluginHook
;
import
com.itfsw.mybatis.generator.plugins.utils.hook.IUpsertPluginHook
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.IntrospectedTable
;
...
@@ -27,6 +28,7 @@ import org.mybatis.generator.api.dom.java.Interface;
...
@@ -27,6 +28,7 @@ import org.mybatis.generator.api.dom.java.Interface;
import
org.mybatis.generator.api.dom.java.Method
;
import
org.mybatis.generator.api.dom.java.Method
;
import
org.mybatis.generator.api.dom.java.Parameter
;
import
org.mybatis.generator.api.dom.java.Parameter
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
import
org.mybatis.generator.api.dom.xml.Element
;
import
org.mybatis.generator.api.dom.xml.TextElement
;
import
org.mybatis.generator.api.dom.xml.TextElement
;
import
org.mybatis.generator.api.dom.xml.XmlElement
;
import
org.mybatis.generator.api.dom.xml.XmlElement
;
import
org.mybatis.generator.codegen.mybatis3.ListUtilities
;
import
org.mybatis.generator.codegen.mybatis3.ListUtilities
;
...
@@ -253,7 +255,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin implements IUpsertPlugin
...
@@ -253,7 +255,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin implements IUpsertPlugin
// selective
// selective
answer
.
addElement
(
new
TextElement
(
"SET"
));
answer
.
addElement
(
new
TextElement
(
"SET"
));
answer
.
addElement
(
this
.
generateSetsSelective
(
ListUtilities
.
removeGeneratedAlwaysColumns
(
introspectedTable
.
get
All
Columns
())));
answer
.
addElement
(
this
.
generateSetsSelective
(
ListUtilities
.
removeGeneratedAlwaysColumns
(
introspectedTable
.
get
NonPrimaryKey
Columns
())));
XmlElementGeneratorTools
.
generateWhereByPrimaryKeyTo
(
answer
,
introspectedTable
.
getPrimaryKeyColumns
(),
"record."
);
XmlElementGeneratorTools
.
generateWhereByPrimaryKeyTo
(
answer
,
introspectedTable
.
getPrimaryKeyColumns
(),
"record."
);
...
@@ -445,7 +447,14 @@ public class SelectiveEnhancedPlugin extends BasePlugin implements IUpsertPlugin
...
@@ -445,7 +447,14 @@ public class SelectiveEnhancedPlugin extends BasePlugin implements IUpsertPlugin
setForeachEle
.
addAttribute
(
new
Attribute
(
"collection"
,
"selective"
));
setForeachEle
.
addAttribute
(
new
Attribute
(
"collection"
,
"selective"
));
setForeachEle
.
addAttribute
(
new
Attribute
(
"item"
,
"column"
));
setForeachEle
.
addAttribute
(
new
Attribute
(
"item"
,
"column"
));
setForeachEle
.
addAttribute
(
new
Attribute
(
"separator"
,
","
));
setForeachEle
.
addAttribute
(
new
Attribute
(
"separator"
,
","
));
setForeachEle
.
addElement
(
new
TextElement
(
"${column.value} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"
));
Element
incrementEle
=
PluginTools
.
getHook
(
IIncrementsPluginHook
.
class
).
incrementSetsWithSelectiveEnhancedPluginElementGenerated
();
if
(
incrementEle
==
null
)
{
setForeachEle
.
addElement
(
new
TextElement
(
"${column.value} = #{record.${column.javaProperty},jdbcType=${column.jdbcType}}"
));
}
else
{
setForeachEle
.
addElement
(
incrementEle
);
}
XmlElement
setOtherwiseEle
=
new
XmlElement
(
"otherwise"
);
XmlElement
setOtherwiseEle
=
new
XmlElement
(
"otherwise"
);
setOtherwiseEle
.
addElement
(
XmlElementGeneratorTools
.
generateSetsSelective
(
columns
,
"record."
));
setOtherwiseEle
.
addElement
(
XmlElementGeneratorTools
.
generateSetsSelective
(
columns
,
"record."
));
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/utils/XmlElementGeneratorTools.java
View file @
ab702538
...
@@ -383,8 +383,8 @@ public class XmlElementGeneratorTools {
...
@@ -383,8 +383,8 @@ public class XmlElementGeneratorTools {
switch
(
type
)
{
switch
(
type
)
{
case
3
:
case
3
:
List
<
Element
>
incrementEles
=
PluginTools
.
getHook
(
IIncrementsPluginHook
.
class
).
increment
ElementGenerated
(
introspectedColumn
,
prefix
,
columnIterator
.
hasNext
()
);
List
<
Element
>
incrementEles
=
PluginTools
.
getHook
(
IIncrementsPluginHook
.
class
).
increment
SetElementGenerated
(
introspectedColumn
,
prefix
,
false
);
if
(
incrementEles
.
isEmpty
())
{
if
(
!
incrementEles
.
isEmpty
())
{
// 增量插件支持
// 增量插件支持
if
(
sb
.
length
()
>
0
)
{
if
(
sb
.
length
()
>
0
)
{
list
.
add
(
new
TextElement
(
sb
.
toString
()));
list
.
add
(
new
TextElement
(
sb
.
toString
()));
...
@@ -498,8 +498,8 @@ public class XmlElementGeneratorTools {
...
@@ -498,8 +498,8 @@ public class XmlElementGeneratorTools {
private
static
void
generateSelectiveCommColumnTo
(
XmlElement
element
,
IntrospectedColumn
introspectedColumn
,
String
prefix
,
int
type
)
{
private
static
void
generateSelectiveCommColumnTo
(
XmlElement
element
,
IntrospectedColumn
introspectedColumn
,
String
prefix
,
int
type
)
{
switch
(
type
)
{
switch
(
type
)
{
case
3
:
case
3
:
List
<
Element
>
incrementEles
=
PluginTools
.
getHook
(
IIncrementsPluginHook
.
class
).
incrementElementGenerated
(
introspectedColumn
,
prefix
,
true
);
List
<
Element
>
incrementEles
=
PluginTools
.
getHook
(
IIncrementsPluginHook
.
class
).
increment
Set
ElementGenerated
(
introspectedColumn
,
prefix
,
true
);
if
(
incrementEles
.
isEmpty
())
{
if
(
!
incrementEles
.
isEmpty
())
{
// 增量插件支持
// 增量插件支持
for
(
Element
ele
:
incrementEles
)
{
for
(
Element
ele
:
incrementEles
)
{
element
.
addElement
(
ele
);
element
.
addElement
(
ele
);
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/HookAggregator.java
View file @
ab702538
...
@@ -97,11 +97,20 @@ public class HookAggregator implements IUpsertPluginHook, IModelBuilderPluginHoo
...
@@ -97,11 +97,20 @@ public class HookAggregator implements IUpsertPluginHook, IModelBuilderPluginHoo
// ============================================= IIncrementsPluginHook ==============================================
// ============================================= IIncrementsPluginHook ==============================================
@Override
@Override
public
List
<
Element
>
incrementElementGenerated
(
IntrospectedColumn
introspectedColumn
,
String
prefix
,
boolean
hasComma
)
{
public
List
<
Element
>
increment
Set
ElementGenerated
(
IntrospectedColumn
introspectedColumn
,
String
prefix
,
boolean
hasComma
)
{
if
(
this
.
getPlugins
(
IIncrementsPluginHook
.
class
).
isEmpty
())
{
if
(
this
.
getPlugins
(
IIncrementsPluginHook
.
class
).
isEmpty
())
{
return
new
ArrayList
<>();
return
new
ArrayList
<>();
}
else
{
}
else
{
return
this
.
getPlugins
(
IIncrementsPluginHook
.
class
).
get
(
0
).
incrementElementGenerated
(
introspectedColumn
,
prefix
,
hasComma
);
return
this
.
getPlugins
(
IIncrementsPluginHook
.
class
).
get
(
0
).
incrementSetElementGenerated
(
introspectedColumn
,
prefix
,
hasComma
);
}
}
@Override
public
Element
incrementSetsWithSelectiveEnhancedPluginElementGenerated
()
{
if
(
this
.
getPlugins
(
IIncrementsPluginHook
.
class
).
isEmpty
()){
return
null
;
}
else
{
return
this
.
getPlugins
(
IIncrementsPluginHook
.
class
).
get
(
0
).
incrementSetsWithSelectiveEnhancedPluginElementGenerated
();
}
}
}
}
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/IIncrementsPluginHook.java
View file @
ab702538
...
@@ -37,5 +37,11 @@ public interface IIncrementsPluginHook {
...
@@ -37,5 +37,11 @@ public interface IIncrementsPluginHook {
* @param hasComma
* @param hasComma
* @return
* @return
*/
*/
List
<
Element
>
incrementElementGenerated
(
IntrospectedColumn
introspectedColumn
,
String
prefix
,
boolean
hasComma
);
List
<
Element
>
incrementSetElementGenerated
(
IntrospectedColumn
introspectedColumn
,
String
prefix
,
boolean
hasComma
);
/**
* 生成增量操作节点(SelectiveEnhancedPlugin)
* @return
*/
Element
incrementSetsWithSelectiveEnhancedPluginElementGenerated
();
}
}
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