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
50b139f2
Commit
50b139f2
authored
May 16, 2018
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[issues#26][issues#27]:插件因为是复用的,需要进行属性的清空。
parent
567279db
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
26 deletions
+58
-26
src/main/java/com/itfsw/mybatis/generator/plugins/SelectOneByExamplePlugin.java
...w/mybatis/generator/plugins/SelectOneByExamplePlugin.java
+8
-0
src/main/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
...tfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
+50
-26
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/SelectOneByExamplePlugin.java
View file @
50b139f2
...
@@ -41,6 +41,14 @@ public class SelectOneByExamplePlugin extends BasePlugin {
...
@@ -41,6 +41,14 @@ public class SelectOneByExamplePlugin extends BasePlugin {
private
XmlElement
selectOneByExampleEle
;
private
XmlElement
selectOneByExampleEle
;
private
XmlElement
selectOneByExampleWithBLOBsEle
;
private
XmlElement
selectOneByExampleWithBLOBsEle
;
@Override
public
void
initialized
(
IntrospectedTable
introspectedTable
)
{
super
.
initialized
(
introspectedTable
);
// bug:26,27
this
.
selectOneByExampleWithBLOBsEle
=
null
;
this
.
selectOneByExampleEle
=
null
;
}
/**
/**
* Java Client Methods 生成
* Java Client Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
View file @
50b139f2
...
@@ -20,10 +20,7 @@ import com.itfsw.mybatis.generator.plugins.utils.*;
...
@@ -20,10 +20,7 @@ import com.itfsw.mybatis.generator.plugins.utils.*;
import
com.itfsw.mybatis.generator.plugins.utils.hook.ISelectOneByExamplePluginHook
;
import
com.itfsw.mybatis.generator.plugins.utils.hook.ISelectOneByExamplePluginHook
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedColumn
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.dom.java.FullyQualifiedJavaType
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.java.Interface
;
import
org.mybatis.generator.api.dom.java.Method
;
import
org.mybatis.generator.api.dom.java.Parameter
;
import
org.mybatis.generator.api.dom.xml.*
;
import
org.mybatis.generator.api.dom.xml.*
;
import
org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities
;
import
org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities
;
...
@@ -44,6 +41,9 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
...
@@ -44,6 +41,9 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
public
static
final
String
METHOD_SELECT_BY_PRIMARY_KEY_SELECTIVE
=
"selectByPrimaryKeySelective"
;
public
static
final
String
METHOD_SELECT_BY_PRIMARY_KEY_SELECTIVE
=
"selectByPrimaryKeySelective"
;
public
static
final
String
METHOD_SELECT_ONE_BY_EXAMPLE_SELECTIVE
=
"selectOneByExampleSelective"
;
public
static
final
String
METHOD_SELECT_ONE_BY_EXAMPLE_SELECTIVE
=
"selectOneByExampleSelective"
;
public
static
final
String
ID_FOR_PROPERTY_BASED_RESULT_MAP
=
"BasePropertyResultMap"
;
public
static
final
String
ID_FOR_PROPERTY_BASED_RESULT_MAP
=
"BasePropertyResultMap"
;
private
XmlElement
selectByExampleSelectiveEle
;
private
XmlElement
selectByPrimaryKeySelectiveEle
;
private
XmlElement
basePropertyResultMapEle
;
/**
/**
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
...
@@ -62,6 +62,20 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
...
@@ -62,6 +62,20 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
return
super
.
validate
(
warnings
);
return
super
.
validate
(
warnings
);
}
}
/**
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
* @param introspectedTable
*/
@Override
public
void
initialized
(
IntrospectedTable
introspectedTable
)
{
super
.
initialized
(
introspectedTable
);
// bug:26,27
this
.
selectByExampleSelectiveEle
=
null
;
this
.
selectByPrimaryKeySelectiveEle
=
null
;
this
.
basePropertyResultMapEle
=
null
;
}
// =========================================== client 方法生成 ===================================================
// =========================================== client 方法生成 ===================================================
@Override
@Override
...
@@ -121,18 +135,23 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
...
@@ -121,18 +135,23 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
// ============================================== sqlMap 生成 ===================================================
// ============================================== sqlMap 生成 ===================================================
@Override
@Override
public
boolean
sqlMapSelectByExampleWithoutBLOBsElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
public
boolean
clientSelectByExampleWithBLOBsMethodGenerated
(
Method
method
,
TopLevelClass
topLevelClass
,
IntrospectedTable
introspectedTable
)
{
return
super
.
sqlMapSelectByExampleWithoutBLOBsElementGenerated
(
element
,
introspectedTable
);
this
.
selectByExampleSelectiveEle
=
this
.
generateSelectSelectiveElement
(
METHOD_SELECT_BY_EXAMPLE_SELECTIVE
,
introspectedTable
,
false
,
true
);
return
super
.
clientSelectByExampleWithBLOBsMethodGenerated
(
method
,
topLevelClass
,
introspectedTable
);
}
}
@Override
@Override
public
boolean
sqlMapSelectByExampleWithBLOBsElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
public
boolean
clientSelectByExampleWithoutBLOBsMethodGenerated
(
Method
method
,
TopLevelClass
topLevelClass
,
IntrospectedTable
introspectedTable
)
{
return
super
.
sqlMapSelectByExampleWithBLOBsElementGenerated
(
element
,
introspectedTable
);
if
(!
introspectedTable
.
hasBLOBColumns
())
{
this
.
selectByExampleSelectiveEle
=
this
.
generateSelectSelectiveElement
(
METHOD_SELECT_BY_EXAMPLE_SELECTIVE
,
introspectedTable
,
false
,
true
);
}
return
super
.
clientSelectByExampleWithoutBLOBsMethodGenerated
(
method
,
topLevelClass
,
introspectedTable
);
}
}
@Override
@Override
public
boolean
sqlMapSelectByPrimaryKeyElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
public
boolean
clientSelectByPrimaryKeyMethodGenerated
(
Method
method
,
TopLevelClass
topLevelClass
,
IntrospectedTable
introspectedTable
)
{
return
super
.
sqlMapSelectByPrimaryKeyElementGenerated
(
element
,
introspectedTable
);
this
.
selectByPrimaryKeySelectiveEle
=
this
.
generateSelectSelectiveElement
(
METHOD_SELECT_BY_PRIMARY_KEY_SELECTIVE
,
introspectedTable
,
false
,
false
);
return
super
.
clientSelectByPrimaryKeyMethodGenerated
(
method
,
topLevelClass
,
introspectedTable
);
}
}
/**
/**
...
@@ -144,27 +163,19 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
...
@@ -144,27 +163,19 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
@Override
@Override
public
boolean
sqlMapDocumentGenerated
(
Document
document
,
IntrospectedTable
introspectedTable
)
{
public
boolean
sqlMapDocumentGenerated
(
Document
document
,
IntrospectedTable
introspectedTable
)
{
// issues#16
// issues#16
if
(
introspectedTable
.
isConstructorBased
())
{
if
(
this
.
basePropertyResultMapEle
!=
null
)
{
XmlElement
resultMapEle
=
new
XmlElement
(
"resultMap"
);
document
.
getRootElement
().
addElement
(
0
,
this
.
basePropertyResultMapEle
);
resultMapEle
.
addAttribute
(
new
Attribute
(
"id"
,
ID_FOR_PROPERTY_BASED_RESULT_MAP
));
resultMapEle
.
addAttribute
(
new
Attribute
(
"type"
,
introspectedTable
.
getRules
().
calculateAllFieldsClass
().
getFullyQualifiedName
()));
commentGenerator
.
addComment
(
resultMapEle
);
for
(
IntrospectedColumn
introspectedColumn
:
introspectedTable
.
getPrimaryKeyColumns
())
{
resultMapEle
.
addElement
(
XmlElementGeneratorTools
.
generateResultMapResultElement
(
"id"
,
introspectedColumn
));
}
for
(
IntrospectedColumn
introspectedColumn
:
introspectedTable
.
getNonPrimaryKeyColumns
())
{
resultMapEle
.
addElement
(
XmlElementGeneratorTools
.
generateResultMapResultElement
(
"result"
,
introspectedColumn
));
}
document
.
getRootElement
().
getElements
().
add
(
0
,
resultMapEle
);
}
}
// 1. selectByExampleSelective 方法
// 1. selectByExampleSelective 方法
FormatTools
.
addElementWithBestPosition
(
document
.
getRootElement
(),
this
.
generateSelectSelectiveElement
(
METHOD_SELECT_BY_EXAMPLE_SELECTIVE
,
introspectedTable
,
false
,
true
));
if
(
this
.
selectByExampleSelectiveEle
!=
null
)
{
FormatTools
.
addElementWithBestPosition
(
document
.
getRootElement
(),
this
.
selectByExampleSelectiveEle
);
}
// 2. selectByPrimaryKeySelective
// 2. selectByPrimaryKeySelective
FormatTools
.
addElementWithBestPosition
(
document
.
getRootElement
(),
this
.
generateSelectSelectiveElement
(
METHOD_SELECT_BY_PRIMARY_KEY_SELECTIVE
,
introspectedTable
,
false
,
false
));
if
(
this
.
selectByPrimaryKeySelectiveEle
!=
null
)
{
FormatTools
.
addElementWithBestPosition
(
document
.
getRootElement
(),
this
.
selectByPrimaryKeySelectiveEle
);
}
return
true
;
return
true
;
}
}
...
@@ -232,6 +243,19 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
...
@@ -232,6 +243,19 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
selectSelectiveEle
.
addAttribute
(
new
Attribute
(
"id"
,
id
));
selectSelectiveEle
.
addAttribute
(
new
Attribute
(
"id"
,
id
));
// issues#16
// issues#16
if
(
introspectedTable
.
isConstructorBased
())
{
if
(
introspectedTable
.
isConstructorBased
())
{
XmlElement
resultMapEle
=
new
XmlElement
(
"resultMap"
);
resultMapEle
.
addAttribute
(
new
Attribute
(
"id"
,
ID_FOR_PROPERTY_BASED_RESULT_MAP
));
resultMapEle
.
addAttribute
(
new
Attribute
(
"type"
,
introspectedTable
.
getRules
().
calculateAllFieldsClass
().
getFullyQualifiedName
()));
commentGenerator
.
addComment
(
resultMapEle
);
for
(
IntrospectedColumn
introspectedColumn
:
introspectedTable
.
getPrimaryKeyColumns
())
{
resultMapEle
.
addElement
(
XmlElementGeneratorTools
.
generateResultMapResultElement
(
"id"
,
introspectedColumn
));
}
for
(
IntrospectedColumn
introspectedColumn
:
introspectedTable
.
getNonPrimaryKeyColumns
())
{
resultMapEle
.
addElement
(
XmlElementGeneratorTools
.
generateResultMapResultElement
(
"result"
,
introspectedColumn
));
}
this
.
basePropertyResultMapEle
=
resultMapEle
;
selectSelectiveEle
.
addAttribute
(
new
Attribute
(
"resultMap"
,
ID_FOR_PROPERTY_BASED_RESULT_MAP
));
selectSelectiveEle
.
addAttribute
(
new
Attribute
(
"resultMap"
,
ID_FOR_PROPERTY_BASED_RESULT_MAP
));
}
else
if
(
introspectedTable
.
hasBLOBColumns
())
{
}
else
if
(
introspectedTable
.
hasBLOBColumns
())
{
selectSelectiveEle
.
addAttribute
(
new
Attribute
(
"resultMap"
,
introspectedTable
.
getResultMapWithBLOBsId
()));
selectSelectiveEle
.
addAttribute
(
new
Attribute
(
"resultMap"
,
introspectedTable
.
getResultMapWithBLOBsId
()));
...
...
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