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
baf72992
Commit
baf72992
authored
May 07, 2018
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SelectSelectivePlugin插件重构
parent
0be29103
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
294 additions
and
100 deletions
+294
-100
src/main/java/com/itfsw/mybatis/generator/plugins/SelectOneByExamplePlugin.java
...w/mybatis/generator/plugins/SelectOneByExamplePlugin.java
+14
-10
src/main/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
...tfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
+106
-89
src/main/java/com/itfsw/mybatis/generator/plugins/utils/JavaElementTools.java
...fsw/mybatis/generator/plugins/utils/JavaElementTools.java
+78
-0
src/main/java/com/itfsw/mybatis/generator/plugins/utils/XmlElementGeneratorTools.java
...tis/generator/plugins/utils/XmlElementGeneratorTools.java
+21
-0
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/HookAggregator.java
.../mybatis/generator/plugins/utils/hook/HookAggregator.java
+24
-1
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/ISelectOneByExamplePluginHook.java
...tor/plugins/utils/hook/ISelectOneByExamplePluginHook.java
+51
-0
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/SelectOneByExamplePlugin.java
View file @
baf72992
...
@@ -16,10 +16,8 @@
...
@@ -16,10 +16,8 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.*
;
import
com.itfsw.mybatis.generator.plugins.utils.FormatTools
;
import
com.itfsw.mybatis.generator.plugins.utils.hook.ISelectOneByExamplePluginHook
;
import
com.itfsw.mybatis.generator.plugins.utils.JavaElementGeneratorTools
;
import
com.itfsw.mybatis.generator.plugins.utils.XmlElementGeneratorTools
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.java.*
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
import
org.mybatis.generator.api.dom.xml.Attribute
;
...
@@ -60,9 +58,12 @@ public class SelectOneByExamplePlugin extends BasePlugin {
...
@@ -60,9 +58,12 @@ public class SelectOneByExamplePlugin extends BasePlugin {
);
);
commentGenerator
.
addGeneralMethodComment
(
method
,
introspectedTable
);
commentGenerator
.
addGeneralMethodComment
(
method
,
introspectedTable
);
// hook
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
clientSelectOneByExampleWithoutBLOBsMethodGenerated
(
method
,
interfaze
,
introspectedTable
))
{
// interface 增加方法
// interface 增加方法
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExample方法。"
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExample方法。"
);
}
// 方法生成 selectOneByExampleWithBLOBs !!! 注意这里的行为不以有没有生成Model 的 WithBLOBs类为基准
// 方法生成 selectOneByExampleWithBLOBs !!! 注意这里的行为不以有没有生成Model 的 WithBLOBs类为基准
if
(
introspectedTable
.
hasBLOBColumns
())
{
if
(
introspectedTable
.
hasBLOBColumns
())
{
...
@@ -75,10 +76,13 @@ public class SelectOneByExamplePlugin extends BasePlugin {
...
@@ -75,10 +76,13 @@ public class SelectOneByExamplePlugin extends BasePlugin {
);
);
commentGenerator
.
addGeneralMethodComment
(
method1
,
introspectedTable
);
commentGenerator
.
addGeneralMethodComment
(
method1
,
introspectedTable
);
// hook
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
clientSelectOneByExampleWithBLOBsMethodGenerated
(
method1
,
interfaze
,
introspectedTable
))
{
// interface 增加方法
// interface 增加方法
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method1
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method1
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExampleWithBLOBs方法。"
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExampleWithBLOBs方法。"
);
}
}
}
return
true
;
return
true
;
}
}
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
View file @
baf72992
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.*
;
import
com.itfsw.mybatis.generator.plugins.utils.*
;
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.*
;
import
org.mybatis.generator.api.dom.java.*
;
...
@@ -40,7 +41,7 @@ import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
...
@@ -40,7 +41,7 @@ import static org.mybatis.generator.internal.util.StringUtility.stringHasValue;
* @time:2017/6/29 13:34
* @time:2017/6/29 13:34
* ---------------------------------------------------------------------------
* ---------------------------------------------------------------------------
*/
*/
public
class
SelectSelectivePlugin
extends
BasePlugin
{
public
class
SelectSelectivePlugin
extends
BasePlugin
implements
ISelectOneByExamplePluginHook
{
public
static
final
String
METHOD_SELECT_BY_EXAMPLE_SELECTIVE
=
"selectByExampleSelective"
;
public
static
final
String
METHOD_SELECT_BY_EXAMPLE_SELECTIVE
=
"selectByExampleSelective"
;
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"
;
...
@@ -63,74 +64,83 @@ public class SelectSelectivePlugin extends BasePlugin {
...
@@ -63,74 +64,83 @@ public class SelectSelectivePlugin extends BasePlugin {
return
super
.
validate
(
warnings
);
return
super
.
validate
(
warnings
);
}
}
/**
// =========================================== client 方法生成 ===================================================
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
* @param interfaze
* @param topLevelClass
* @param introspectedTable
* @return
*/
@Override
@Override
public
boolean
clientGenerated
(
Interface
interfaze
,
TopLevelClass
topLevelClass
,
IntrospectedTable
introspectedTable
)
{
public
boolean
clientSelectByExampleWithBLOBsMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
// 找出全字段对应的Model
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
this
.
replaceMethodWithSelective
(
FullyQualifiedJavaType
fullFieldModel
=
introspectedTable
.
getRules
().
calculateAllFieldsClass
();
method
,
// 返回list类型
METHOD_SELECT_BY_EXAMPLE_SELECTIVE
,
FullyQualifiedJavaType
listType
=
FullyQualifiedJavaType
.
getNewListInstance
();
"@Param(\"example\")"
,
listType
.
addTypeArgument
(
fullFieldModel
);
introspectedTable
// column枚举
));
FullyQualifiedJavaType
selectiveType
=
new
FullyQualifiedJavaType
(
fullFieldModel
.
getShortName
()
+
"."
+
ModelColumnPlugin
.
ENUM_NAME
);
return
super
.
clientSelectByExampleWithBLOBsMethodGenerated
(
method
,
interfaze
,
introspectedTable
);
}
// 1. selectByExampleSelective 方法
@Override
Method
mSelectByExampleSelective
=
JavaElementGeneratorTools
.
generateMethod
(
public
boolean
clientSelectByExampleWithoutBLOBsMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
if
(!
introspectedTable
.
hasBLOBColumns
())
{
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
this
.
replaceMethodWithSelective
(
method
,
METHOD_SELECT_BY_EXAMPLE_SELECTIVE
,
METHOD_SELECT_BY_EXAMPLE_SELECTIVE
,
JavaVisibility
.
DEFAULT
,
"@Param(\"example\")"
,
listType
,
introspectedTable
new
Parameter
(
new
FullyQualifiedJavaType
(
introspectedTable
.
getExampleType
()),
"example"
,
"@Param(\"example\")"
),
));
new
Parameter
(
selectiveType
,
"selective"
,
"@Param(\"selective\")"
,
true
)
}
);
return
super
.
clientSelectByExampleWithoutBLOBsMethodGenerated
(
method
,
interfaze
,
introspectedTable
);
commentGenerator
.
addGeneralMethodComment
(
mSelectByExampleSelective
,
introspectedTable
);
}
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mSelectByExampleSelective
);
// 2. selectByPrimaryKeySelective
Method
mSelectByPrimaryKeySelective
=
JavaElementGeneratorTools
.
generateMethod
(
@Override
METHOD_SELECT_BY_PRIMARY_KEY_SELECTIVE
,
public
boolean
clientSelectByPrimaryKeyMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
JavaVisibility
.
DEFAULT
,
fullFieldModel
);
if
(
introspectedTable
.
getRules
().
generatePrimaryKeyClass
())
{
if
(
introspectedTable
.
getRules
().
generatePrimaryKeyClass
())
{
FullyQualifiedJavaType
type
=
new
FullyQualifiedJavaType
(
introspectedTable
.
getPrimaryKeyType
());
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
this
.
replaceMethodWithSelective
(
mSelectByPrimaryKeySelective
.
addParameter
(
new
Parameter
(
type
,
"key"
,
"@Param(\"record\")"
));
method
,
METHOD_SELECT_BY_PRIMARY_KEY_SELECTIVE
,
"@Param(\"record\")"
,
introspectedTable
));
}
else
{
}
else
{
// no primary key class - fields are in the base class
Method
withSelective
=
JavaElementTools
.
clone
(
method
);
// if more than one PK field, then we need to annotate the
FormatTools
.
replaceGeneralMethodComment
(
commentGenerator
,
withSelective
,
introspectedTable
);
// parameters
// for MyBatis3
withSelective
.
setName
(
METHOD_SELECT_BY_PRIMARY_KEY_SELECTIVE
);
List
<
IntrospectedColumn
>
introspectedColumns
=
introspectedTable
.
getPrimaryKeyColumns
();
withSelective
.
getParameters
().
clear
();
for
(
IntrospectedColumn
introspectedColumn
:
introspectedColumns
)
{
for
(
IntrospectedColumn
introspectedColumn
:
introspectedTable
.
getPrimaryKeyColumns
())
{
FullyQualifiedJavaType
type
=
introspectedColumn
.
getFullyQualifiedJavaType
();
withSelective
.
addParameter
(
new
Parameter
(
introspectedColumn
.
getFullyQualifiedJavaType
(),
introspectedColumn
.
getJavaProperty
(),
"@Param(\""
+
introspectedColumn
.
getJavaProperty
()
+
"\")"
));
Parameter
parameter
=
new
Parameter
(
type
,
introspectedColumn
.
getJavaProperty
());
parameter
.
addAnnotation
(
"@Param(\""
+
introspectedColumn
.
getJavaProperty
()
+
"\")"
);
mSelectByPrimaryKeySelective
.
addParameter
(
parameter
);
}
}
// selective
withSelective
.
addParameter
(
new
Parameter
(
this
.
getModelColumnFullyQualifiedJavaType
(
introspectedTable
),
"selective"
,
"@Param(\"selective\")"
,
true
)
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
withSelective
);
}
return
super
.
clientSelectByPrimaryKeyMethodGenerated
(
method
,
interfaze
,
introspectedTable
);
}
}
mSelectByPrimaryKeySelective
.
addParameter
(
new
Parameter
(
selectiveType
,
"selective"
,
"@Param(\"selective\")"
,
true
));
commentGenerator
.
addGeneralMethodComment
(
mSelectByPrimaryKeySelective
,
introspectedTable
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mSelectByPrimaryKeySelective
);
// 3. selectOneByExampleSelective
@Override
if
(
PluginTools
.
getPluginConfiguration
(
context
,
SelectOneByExamplePlugin
.
class
)
!=
null
)
{
public
boolean
clientSelectOneByExampleWithBLOBsMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
Method
mSelectOneByExampleSelective
=
JavaElementGeneratorTools
.
generateMethod
(
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
this
.
replaceMethodWithSelective
(
method
,
METHOD_SELECT_ONE_BY_EXAMPLE_SELECTIVE
,
METHOD_SELECT_ONE_BY_EXAMPLE_SELECTIVE
,
JavaVisibility
.
DEFAULT
,
"@Param(\"example\")"
,
fullFieldModel
,
introspectedTable
new
Parameter
(
new
FullyQualifiedJavaType
(
introspectedTable
.
getExampleType
()),
"example"
,
"@Param(\"example\")"
),
));
new
Parameter
(
selectiveType
,
"selective"
,
"@Param(\"selective\")"
,
true
)
return
true
;
);
commentGenerator
.
addGeneralMethodComment
(
mSelectOneByExampleSelective
,
introspectedTable
);
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
mSelectOneByExampleSelective
);
}
}
@Override
public
boolean
clientSelectOneByExampleWithoutBLOBsMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
if
(!
introspectedTable
.
hasBLOBColumns
())
{
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
this
.
replaceMethodWithSelective
(
method
,
METHOD_SELECT_ONE_BY_EXAMPLE_SELECTIVE
,
"@Param(\"example\")"
,
introspectedTable
));
}
return
true
;
return
true
;
}
}
...
@@ -285,38 +295,53 @@ public class SelectSelectivePlugin extends BasePlugin {
...
@@ -285,38 +295,53 @@ public class SelectSelectivePlugin extends BasePlugin {
return
true
;
return
true
;
}
}
// =========================================== 一些私有方法 =====================================================
/**
/**
* @param answer
* 替换方法成withSelective
* @param method
* @param name
* @param firstAnnotation
* @param introspectedTable
* @param introspectedTable
* @
see ResultMapWithoutBLOBsElementGenerator#addResultMapElements(XmlElement)
* @
return
*/
*/
private
void
addResultMapElementsWithoutBLOBs
(
XmlElement
answer
,
IntrospectedTable
introspectedTable
)
{
private
Method
replaceMethodWithSelective
(
Method
method
,
String
name
,
String
firstAnnotation
,
IntrospectedTable
introspectedTable
)
{
for
(
IntrospectedColumn
introspectedColumn
:
introspectedTable
.
getPrimaryKeyColumns
())
{
Method
withSelective
=
JavaElementTools
.
clone
(
method
);
XmlElement
resultElement
=
new
XmlElement
(
"id"
);
FormatTools
.
replaceGeneralMethodComment
(
commentGenerator
,
withSelective
,
introspectedTable
);
withSelective
.
setName
(
name
);
// example
withSelective
.
getParameters
().
get
(
0
).
addAnnotation
(
firstAnnotation
);
// selective
withSelective
.
addParameter
(
new
Parameter
(
this
.
getModelColumnFullyQualifiedJavaType
(
introspectedTable
),
"selective"
,
"@Param(\"selective\")"
,
true
)
);
resultElement
.
addAttribute
(
new
Attribute
(
"column"
,
MyBatis3FormattingUtilities
.
getRenamedColumnNameForResultMap
(
introspectedColumn
)));
return
withSelective
;
resultElement
.
addAttribute
(
new
Attribute
(
"property"
,
introspectedColumn
.
getJavaProperty
()));
}
resultElement
.
addAttribute
(
new
Attribute
(
"jdbcType"
,
introspectedColumn
.
getJdbcTypeName
()));
if
(
stringHasValue
(
introspectedColumn
.
getTypeHandler
()))
{
/**
resultElement
.
addAttribute
(
new
Attribute
(
"typeHandler"
,
introspectedColumn
.
getTypeHandler
()));
* 获取ModelColumn type
* @param introspectedTable
* @return
*/
private
FullyQualifiedJavaType
getModelColumnFullyQualifiedJavaType
(
IntrospectedTable
introspectedTable
)
{
return
new
FullyQualifiedJavaType
(
introspectedTable
.
getRules
().
calculateAllFieldsClass
().
getShortName
()
+
"."
+
ModelColumnPlugin
.
ENUM_NAME
);
}
}
answer
.
addElement
(
resultElement
);
/**
* @param answer
* @param introspectedTable
* @see ResultMapWithoutBLOBsElementGenerator#addResultMapElements(XmlElement)
*/
private
void
addResultMapElementsWithoutBLOBs
(
XmlElement
answer
,
IntrospectedTable
introspectedTable
)
{
for
(
IntrospectedColumn
introspectedColumn
:
introspectedTable
.
getPrimaryKeyColumns
())
{
answer
.
addElement
(
XmlElementGeneratorTools
.
generateResultMapResultElement
(
"id"
,
introspectedColumn
));
}
}
List
<
IntrospectedColumn
>
columns
=
introspectedTable
.
getBaseColumns
();
List
<
IntrospectedColumn
>
columns
=
introspectedTable
.
getBaseColumns
();
for
(
IntrospectedColumn
introspectedColumn
:
columns
)
{
for
(
IntrospectedColumn
introspectedColumn
:
columns
)
{
XmlElement
resultElement
=
new
XmlElement
(
"result"
);
answer
.
addElement
(
XmlElementGeneratorTools
.
generateResultMapResultElement
(
"result"
,
introspectedColumn
));
resultElement
.
addAttribute
(
new
Attribute
(
"column"
,
MyBatis3FormattingUtilities
.
getRenamedColumnNameForResultMap
(
introspectedColumn
)));
resultElement
.
addAttribute
(
new
Attribute
(
"property"
,
introspectedColumn
.
getJavaProperty
()));
resultElement
.
addAttribute
(
new
Attribute
(
"jdbcType"
,
introspectedColumn
.
getJdbcTypeName
()));
if
(
stringHasValue
(
introspectedColumn
.
getTypeHandler
()))
{
resultElement
.
addAttribute
(
new
Attribute
(
"typeHandler"
,
introspectedColumn
.
getTypeHandler
()));
}
answer
.
addElement
(
resultElement
);
}
}
}
}
...
@@ -327,15 +352,7 @@ public class SelectSelectivePlugin extends BasePlugin {
...
@@ -327,15 +352,7 @@ public class SelectSelectivePlugin extends BasePlugin {
*/
*/
private
void
addResultMapElementsWithBLOBs
(
XmlElement
answer
,
IntrospectedTable
introspectedTable
)
{
private
void
addResultMapElementsWithBLOBs
(
XmlElement
answer
,
IntrospectedTable
introspectedTable
)
{
for
(
IntrospectedColumn
introspectedColumn
:
introspectedTable
.
getBLOBColumns
())
{
for
(
IntrospectedColumn
introspectedColumn
:
introspectedTable
.
getBLOBColumns
())
{
XmlElement
resultElement
=
new
XmlElement
(
"result"
);
answer
.
addElement
(
XmlElementGeneratorTools
.
generateResultMapResultElement
(
"result"
,
introspectedColumn
));
resultElement
.
addAttribute
(
new
Attribute
(
"column"
,
MyBatis3FormattingUtilities
.
getRenamedColumnNameForResultMap
(
introspectedColumn
)));
resultElement
.
addAttribute
(
new
Attribute
(
"property"
,
introspectedColumn
.
getJavaProperty
()));
resultElement
.
addAttribute
(
new
Attribute
(
"jdbcType"
,
introspectedColumn
.
getJdbcTypeName
()));
if
(
stringHasValue
(
introspectedColumn
.
getTypeHandler
()))
{
resultElement
.
addAttribute
(
new
Attribute
(
"typeHandler"
,
introspectedColumn
.
getTypeHandler
()));
}
answer
.
addElement
(
resultElement
);
}
}
}
}
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/utils/JavaElementTools.java
0 → 100644
View file @
baf72992
/*
* Copyright (c) 2018.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
.
utils
;
import
org.mybatis.generator.api.dom.java.FullyQualifiedJavaType
;
import
org.mybatis.generator.api.dom.java.Method
;
import
org.mybatis.generator.api.dom.java.Parameter
;
import
org.mybatis.generator.api.dom.java.TypeParameter
;
/**
* ---------------------------------------------------------------------------
*
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2018/5/7 18:14
* ---------------------------------------------------------------------------
*/
public
class
JavaElementTools
{
/**
* clone
* @param method
* @return
*/
public
static
Method
clone
(
Method
method
)
{
Method
dest
=
new
Method
(
method
.
getName
());
// 注解
for
(
String
javaDocLine
:
method
.
getJavaDocLines
())
{
dest
.
addJavaDocLine
(
javaDocLine
);
}
dest
.
setReturnType
(
method
.
getReturnType
());
for
(
Parameter
parameter
:
method
.
getParameters
())
{
dest
.
addParameter
(
JavaElementTools
.
clone
(
parameter
));
}
for
(
FullyQualifiedJavaType
exception
:
method
.
getExceptions
())
{
dest
.
addException
(
exception
);
}
for
(
TypeParameter
typeParameter
:
method
.
getTypeParameters
())
{
dest
.
addTypeParameter
(
typeParameter
);
}
dest
.
addBodyLines
(
method
.
getBodyLines
());
dest
.
setConstructor
(
method
.
isConstructor
());
dest
.
setNative
(
method
.
isNative
());
dest
.
setSynchronized
(
method
.
isSynchronized
());
dest
.
setDefault
(
method
.
isDefault
());
dest
.
setFinal
(
method
.
isFinal
());
dest
.
setStatic
(
method
.
isStatic
());
dest
.
setVisibility
(
method
.
getVisibility
());
return
dest
;
}
/**
* clone
* @param parameter
* @return
*/
public
static
Parameter
clone
(
Parameter
parameter
)
{
Parameter
dest
=
new
Parameter
(
parameter
.
getType
(),
parameter
.
getName
(),
parameter
.
isVarargs
());
for
(
String
annotation
:
parameter
.
getAnnotations
())
{
dest
.
addAnnotation
(
annotation
);
}
return
dest
;
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/utils/XmlElementGeneratorTools.java
View file @
baf72992
...
@@ -32,6 +32,8 @@ import java.util.Arrays;
...
@@ -32,6 +32,8 @@ import java.util.Arrays;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
static
org
.
mybatis
.
generator
.
internal
.
util
.
StringUtility
.
stringHasValue
;
/**
/**
* ---------------------------------------------------------------------------
* ---------------------------------------------------------------------------
* Xml 节点生成工具 参考 org.mybatis.generator.codegen.mybatis3.xmlmapper.elements.AbstractXmlElementGenerator
* Xml 节点生成工具 参考 org.mybatis.generator.codegen.mybatis3.xmlmapper.elements.AbstractXmlElementGenerator
...
@@ -543,4 +545,23 @@ public class XmlElementGeneratorTools {
...
@@ -543,4 +545,23 @@ public class XmlElementGeneratorTools {
}
}
return
false
;
return
false
;
}
}
/**
* 生成resultMap的result 节点
* @param name
* @param introspectedColumn
* @return
*/
public
static
XmlElement
generateResultMapResultElement
(
String
name
,
IntrospectedColumn
introspectedColumn
)
{
XmlElement
resultElement
=
new
XmlElement
(
name
);
resultElement
.
addAttribute
(
new
Attribute
(
"column"
,
MyBatis3FormattingUtilities
.
getRenamedColumnNameForResultMap
(
introspectedColumn
)));
resultElement
.
addAttribute
(
new
Attribute
(
"property"
,
introspectedColumn
.
getJavaProperty
()));
resultElement
.
addAttribute
(
new
Attribute
(
"jdbcType"
,
introspectedColumn
.
getJdbcTypeName
()));
if
(
stringHasValue
(
introspectedColumn
.
getTypeHandler
()))
{
resultElement
.
addAttribute
(
new
Attribute
(
"typeHandler"
,
introspectedColumn
.
getTypeHandler
()));
}
return
resultElement
;
}
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/HookAggregator.java
View file @
baf72992
...
@@ -42,7 +42,7 @@ import java.util.List;
...
@@ -42,7 +42,7 @@ import java.util.List;
* @time:2018/4/27 11:33
* @time:2018/4/27 11:33
* ---------------------------------------------------------------------------
* ---------------------------------------------------------------------------
*/
*/
public
class
HookAggregator
implements
IUpsertPluginHook
,
IModelBuilderPluginHook
,
IIncrementsPluginHook
,
IOptimisticLockerPluginHook
{
public
class
HookAggregator
implements
IUpsertPluginHook
,
IModelBuilderPluginHook
,
IIncrementsPluginHook
,
IOptimisticLockerPluginHook
,
ISelectOneByExamplePluginHook
{
protected
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BasePlugin
.
class
);
// 日志
protected
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BasePlugin
.
class
);
// 日志
private
final
static
HookAggregator
instance
=
new
HookAggregator
();
private
final
static
HookAggregator
instance
=
new
HookAggregator
();
private
Context
context
;
private
Context
context
;
...
@@ -207,4 +207,27 @@ public class HookAggregator implements IUpsertPluginHook, IModelBuilderPluginHoo
...
@@ -207,4 +207,27 @@ public class HookAggregator implements IUpsertPluginHook, IModelBuilderPluginHoo
return
this
.
getPlugins
(
IOptimisticLockerPluginHook
.
class
).
get
(
0
).
generateSetsSelectiveElement
(
columns
,
versionColumn
,
setsElement
);
return
this
.
getPlugins
(
IOptimisticLockerPluginHook
.
class
).
get
(
0
).
generateSetsSelectiveElement
(
columns
,
versionColumn
,
setsElement
);
}
}
}
}
// ============================================= ISelectOneByExamplePluginHook ==============================================
@Override
public
boolean
clientSelectOneByExampleWithBLOBsMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
for
(
ISelectOneByExamplePluginHook
plugin
:
this
.
getPlugins
(
ISelectOneByExamplePluginHook
.
class
))
{
if
(!
plugin
.
clientSelectOneByExampleWithBLOBsMethodGenerated
(
method
,
interfaze
,
introspectedTable
))
{
return
false
;
}
}
return
true
;
}
@Override
public
boolean
clientSelectOneByExampleWithoutBLOBsMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
for
(
ISelectOneByExamplePluginHook
plugin
:
this
.
getPlugins
(
ISelectOneByExamplePluginHook
.
class
))
{
if
(!
plugin
.
clientSelectOneByExampleWithoutBLOBsMethodGenerated
(
method
,
interfaze
,
introspectedTable
))
{
return
false
;
}
}
return
true
;
}
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/ISelectOneByExamplePluginHook.java
0 → 100644
View file @
baf72992
/*
* Copyright (c) 2018.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
.
utils
.
hook
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.dom.java.Interface
;
import
org.mybatis.generator.api.dom.java.Method
;
/**
* ---------------------------------------------------------------------------
*
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2018/5/7 18:51
* ---------------------------------------------------------------------------
*/
public
interface
ISelectOneByExamplePluginHook
{
/**
* selectOneByExampleWithBLOBs 接口方法生成
* @param method
* @param interfaze
* @param introspectedTable
* @return
*/
boolean
clientSelectOneByExampleWithBLOBsMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
);
/**
* selectOneByExample 接口方法生成
* @param method
* @param interfaze
* @param introspectedTable
* @return
*/
boolean
clientSelectOneByExampleWithoutBLOBsMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
);
}
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