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
Expand all
Hide 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
);
// interface 增加方法
// hook
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method
);
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
clientSelectOneByExampleWithoutBLOBsMethodGenerated
(
method
,
interfaze
,
introspectedTable
))
{
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExample方法。"
);
// interface 增加方法
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExample方法。"
);
}
// 方法生成 selectOneByExampleWithBLOBs !!! 注意这里的行为不以有没有生成Model 的 WithBLOBs类为基准
// 方法生成 selectOneByExampleWithBLOBs !!! 注意这里的行为不以有没有生成Model 的 WithBLOBs类为基准
if
(
introspectedTable
.
hasBLOBColumns
())
{
if
(
introspectedTable
.
hasBLOBColumns
())
{
...
@@ -75,9 +76,12 @@ public class SelectOneByExamplePlugin extends BasePlugin {
...
@@ -75,9 +76,12 @@ public class SelectOneByExamplePlugin extends BasePlugin {
);
);
commentGenerator
.
addGeneralMethodComment
(
method1
,
introspectedTable
);
commentGenerator
.
addGeneralMethodComment
(
method1
,
introspectedTable
);
// interface 增加方法
// hook
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method1
);
if
(
PluginTools
.
getHook
(
ISelectOneByExamplePluginHook
.
class
).
clientSelectOneByExampleWithBLOBsMethodGenerated
(
method1
,
interfaze
,
introspectedTable
))
{
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExampleWithBLOBs方法。"
);
// interface 增加方法
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
method1
);
logger
.
debug
(
"itfsw(查询单条数据插件):"
+
interfaze
.
getType
().
getShortName
()
+
"增加selectOneByExampleWithBLOBs方法。"
);
}
}
}
return
true
;
return
true
;
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
View file @
baf72992
This diff is collapsed.
Click to expand it.
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