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
3df69f4b
Commit
3df69f4b
authored
Oct 30, 2018
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
乐观锁插件
parent
858db7a8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
152 additions
and
3 deletions
+152
-3
src/main/java/com/itfsw/mybatis/generator/plugins/OptimisticLockerPlugin.java
...fsw/mybatis/generator/plugins/OptimisticLockerPlugin.java
+35
-1
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/HookAggregator.java
.../mybatis/generator/plugins/utils/hook/HookAggregator.java
+51
-2
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/ILogicalDeletePluginHook.java
...enerator/plugins/utils/hook/ILogicalDeletePluginHook.java
+66
-0
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/OptimisticLockerPlugin.java
View file @
3df69f4b
...
...
@@ -17,6 +17,7 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.utils.*
;
import
com.itfsw.mybatis.generator.plugins.utils.hook.ILogicalDeletePluginHook
;
import
com.itfsw.mybatis.generator.plugins.utils.hook.IModelBuilderPluginHook
;
import
com.itfsw.mybatis.generator.plugins.utils.hook.IOptimisticLockerPluginHook
;
import
org.mybatis.generator.api.IntrospectedColumn
;
...
...
@@ -38,9 +39,11 @@ import java.util.*;
* @time:2018/4/26 10:24
* ---------------------------------------------------------------------------
*/
public
class
OptimisticLockerPlugin
extends
BasePlugin
implements
IModelBuilderPluginHook
{
public
class
OptimisticLockerPlugin
extends
BasePlugin
implements
IModelBuilderPluginHook
,
ILogicalDeletePluginHook
{
public
static
final
String
METHOD_DELETE_WITH_VERSION_BY_EXAMPLE
=
"deleteWithVersionByExample"
;
// 方法名
public
static
final
String
METHOD_DELETE_WITH_VERSION_BY_PRIMARY_KEY
=
"deleteWithVersionByPrimaryKey"
;
// 方法名
public
static
final
String
METHOD_LOGICAL_DELETE_WITH_VERSION_BY_EXAMPLE
=
"logicalDeleteWithVersionByExample"
;
// 方法名
public
static
final
String
METHOD_LOGICAL_DELETE_WITH_VERSION_BY_PRIMARY_KEY
=
"logicalDeleteWithVersionByPrimaryKey"
;
// 方法名
public
static
final
String
METHOD_UPDATE_WITH_VERSION_BY_EXAMPLE_SELECTIVE
=
"updateWithVersionByExampleSelective"
;
// 方法名
public
static
final
String
METHOD_UPDATE_WITH_VERSION_BY_EXAMPLE_WITH_BLOBS
=
"updateWithVersionByExampleWithBLOBs"
;
// 方法名
public
static
final
String
METHOD_UPDATE_WITH_VERSION_BY_EXAMPLE_WITHOUT_BLOBS
=
"updateWithVersionByExample"
;
// 方法名
...
...
@@ -113,6 +116,28 @@ public class OptimisticLockerPlugin extends BasePlugin implements IModelBuilderP
return
super
.
clientDeleteByPrimaryKeyMethodGenerated
(
method
,
interfaze
,
introspectedTable
);
}
@Override
public
boolean
clientLogicalDeleteByExampleMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
if
(
this
.
versionColumn
!=
null
)
{
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
this
.
replaceDeleteExampleMethod
(
introspectedTable
,
method
,
interfaze
,
METHOD_LOGICAL_DELETE_WITH_VERSION_BY_EXAMPLE
)
);
}
return
true
;
}
@Override
public
boolean
clientLogicalDeleteByPrimaryKeyMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
if
(
this
.
versionColumn
!=
null
)
{
FormatTools
.
addMethodWithBestPosition
(
interfaze
,
this
.
replaceDeleteExampleMethod
(
introspectedTable
,
method
,
interfaze
,
METHOD_LOGICAL_DELETE_WITH_VERSION_BY_PRIMARY_KEY
)
);
}
return
true
;
}
@Override
public
boolean
clientUpdateByExampleSelectiveMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
if
(
this
.
versionColumn
!=
null
)
{
...
...
@@ -420,6 +445,15 @@ public class OptimisticLockerPlugin extends BasePlugin implements IModelBuilderP
return
super
.
sqlMapExampleWhereClauseElementGenerated
(
element
,
introspectedTable
);
}
@Override
public
boolean
sqlMapLogicalDeleteByExampleElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
return
true
;
}
@Override
public
boolean
sqlMapLogicalDeleteByPrimaryKeyElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
return
true
;
}
// =================================================== 一些生成方法 ========================================
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/HookAggregator.java
View file @
3df69f4b
...
...
@@ -43,7 +43,14 @@ import java.util.List;
* @time:2018/4/27 11:33
* ---------------------------------------------------------------------------
*/
public
class
HookAggregator
implements
IUpsertPluginHook
,
IModelBuilderPluginHook
,
IIncrementsPluginHook
,
IOptimisticLockerPluginHook
,
ISelectOneByExamplePluginHook
,
ITableConfigurationHook
{
public
class
HookAggregator
implements
IUpsertPluginHook
,
IModelBuilderPluginHook
,
IIncrementsPluginHook
,
IOptimisticLockerPluginHook
,
ISelectOneByExamplePluginHook
,
ITableConfigurationHook
,
ILogicalDeletePluginHook
{
protected
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BasePlugin
.
class
);
// 日志
private
final
static
HookAggregator
instance
=
new
HookAggregator
();
private
Context
context
;
...
...
@@ -256,7 +263,49 @@ public class HookAggregator implements IUpsertPluginHook, IModelBuilderPluginHoo
@Override
public
void
tableConfiguration
(
IntrospectedTable
introspectedTable
)
{
if
(!
this
.
getPlugins
(
ITableConfigurationHook
.
class
).
isEmpty
())
{
this
.
getPlugins
(
ITableConfigurationHook
.
class
).
get
(
0
).
tableConfiguration
(
introspectedTable
);
this
.
getPlugins
(
ITableConfigurationHook
.
class
).
get
(
0
).
tableConfiguration
(
introspectedTable
);
}
}
// ============================================= ILogicalDeletePluginHook ==============================================
@Override
public
boolean
clientLogicalDeleteByExampleMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
for
(
ILogicalDeletePluginHook
plugin
:
this
.
getPlugins
(
ILogicalDeletePluginHook
.
class
))
{
if
(!
plugin
.
clientLogicalDeleteByExampleMethodGenerated
(
method
,
interfaze
,
introspectedTable
))
{
return
false
;
}
}
return
true
;
}
@Override
public
boolean
clientLogicalDeleteByPrimaryKeyMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
)
{
for
(
ILogicalDeletePluginHook
plugin
:
this
.
getPlugins
(
ILogicalDeletePluginHook
.
class
))
{
if
(!
plugin
.
clientLogicalDeleteByPrimaryKeyMethodGenerated
(
method
,
interfaze
,
introspectedTable
))
{
return
false
;
}
}
return
true
;
}
@Override
public
boolean
sqlMapLogicalDeleteByExampleElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
for
(
ILogicalDeletePluginHook
plugin
:
this
.
getPlugins
(
ILogicalDeletePluginHook
.
class
))
{
if
(!
plugin
.
sqlMapLogicalDeleteByExampleElementGenerated
(
element
,
introspectedTable
))
{
return
false
;
}
}
return
true
;
}
@Override
public
boolean
sqlMapLogicalDeleteByPrimaryKeyElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
)
{
for
(
ILogicalDeletePluginHook
plugin
:
this
.
getPlugins
(
ILogicalDeletePluginHook
.
class
))
{
if
(!
plugin
.
sqlMapLogicalDeleteByPrimaryKeyElementGenerated
(
element
,
introspectedTable
))
{
return
false
;
}
}
return
true
;
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/utils/hook/ILogicalDeletePluginHook.java
0 → 100644
View file @
3df69f4b
/*
* 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
;
import
org.mybatis.generator.api.dom.xml.XmlElement
;
/**
* ---------------------------------------------------------------------------
*
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2018/9/11 11:00
* ---------------------------------------------------------------------------
*/
public
interface
ILogicalDeletePluginHook
{
/**
* logicalDeleteByExample
* @param method
* @param interfaze
* @param introspectedTable
* @return
*/
boolean
clientLogicalDeleteByExampleMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
);
/**
* logicalDeleteByPrimaryKey
* @param method
* @param interfaze
* @param introspectedTable
* @return
*/
boolean
clientLogicalDeleteByPrimaryKeyMethodGenerated
(
Method
method
,
Interface
interfaze
,
IntrospectedTable
introspectedTable
);
/**
* logicalDeleteByExample
* @param element
* @param introspectedTable
* @return
*/
boolean
sqlMapLogicalDeleteByExampleElementGenerated
(
XmlElement
element
,
IntrospectedTable
introspectedTable
);
/**
* logicalDeleteByPrimaryKey
* @param element
* @param introspectedTable
* @return
*/
boolean
sqlMapLogicalDeleteByPrimaryKeyElementGenerated
(
XmlElement
element
,
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