Compare commits

...
8 Commits
10 changed files with 262 additions and 156 deletions
+55 -21
View File
@@ -7,7 +7,7 @@
* 查询单条数据插件(SelectOneByExamplePlugin)
* MySQL分页插件(LimitPlugin)
* 数据Model链式构建插件(ModelBuilderPlugin)
* Example Criteria 增强插件(CriteriaBuilderPlugin)
* Example Criteria 增强插件(ExampleEnhancedPlugin(CriteriaBuilderPlugin这个是老版本叫法,已经弃用))
* Example 目标包修改插件(ExampleTargetPlugin)
* 批量插入插件(BatchInsertPlugin)
* 逻辑删除插件(LogicalDeletePlugin)
@@ -18,7 +18,7 @@ Maven引用:
<dependency>
<groupId>com.itfsw</groupId>
<artifactId>mybatis-generator-plugin</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
</dependency>
```
---------------------------------------
@@ -43,7 +43,7 @@ public interface TbMapper {
}
```
### 2. MySQL分页插件
对应表Example类增加了方法
对应表Example类增加了Mysql分页方法,limit(Integer rows)、limit(Integer offset, Integer rows)和page(Integer page, Integer pageSize)
插件:
```xml
<!-- MySQL分页插件 -->
@@ -76,8 +76,9 @@ public class TbExample {
* @mbg.generated
* @author hewei
*/
public void limit(Integer rows) {
public TbExample limit(Integer rows) {
this.rows = rows;
return this;
}
/**
@@ -87,9 +88,10 @@ public class TbExample {
* @mbg.generated
* @author hewei
*/
public void limit(Integer offset, Integer rows) {
public TbExample limit(Integer offset, Integer rows) {
this.offset = offset;
this.rows = rows;
return this;
}
/**
@@ -99,9 +101,10 @@ public class TbExample {
* @mbg.generated
* @author hewei
*/
public void page(Integer page, Integer pageSize) {
public TbExample page(Integer page, Integer pageSize) {
this.offset = page * pageSize;
this.rows = pageSize;
return this;
}
// offset 和 rows 的getter&setter
@@ -121,6 +124,19 @@ public class TbExample {
offset = null;
}
}
public class Test {
public static void main(String[] args) {
this.tbMapper.selectByExample(
new TbExample()
.createCriteria()
.andField1GreaterThan(1)
.example()
.limit(10) // 查询前10条
.limit(10, 10) // 查询10~20条
.page(1, 10) // 查询第2页数据(每页10条)
);
}
}
```
### 3. 数据Model链式构建插件
这个是仿jquery的链式调用强化了表的Model的赋值操作
@@ -143,13 +159,14 @@ public class Test {
}
}
```
### 4. Example Criteria 增强插件(example,andIf)
* 表Example增加Criteria的快速返回example()方法。
* Criteria链式调用增强,以前如果有按条件增加的查询语句会打乱链式查询构建,现在有了andIf(boolean ifAdd, CriteriaAdd add)方法可一直使用链式调用下去。
### 4. Example 增强插件(example,andIf)
* Criteria的快速返回example()方法。
* Criteria链式调用增强,以前如果有按条件增加的查询语句会打乱链式查询构建,现在有了andIf(boolean ifAdd, CriteriaAdd add)方法可一直使用链式调用下去。
* Example增强了setOrderByClause方法,新增orderBy(String orderByClause)方法直接返回example,增强链式调用,可以一路.下去了。
插件:
```xml
<!-- Example Criteria 增强插件 -->
<plugin type="com.itfsw.mybatis.generator.plugins.CriteriaBuilderPlugin"/>
<plugin type="com.itfsw.mybatis.generator.plugins.ExampleEnhancedPlugin"/>
```
使用:
```java
@@ -157,12 +174,13 @@ public class Test {
public static void main(String[] args) {
// -----------------------------------example-----------------------------------
// 表Example.Criteria增加了工厂方法example()支持,使用后可链式构建查询条件使用example()返回Example对象
TbExample ex = new TbExample()
.createCriteria()
.andField1EqualTo(1)
.andField2EqualTo("xxx")
.example();
this.tbMapper.selectByExample(ex);
this.tbMapper.selectByExample(
new TbExample()
.createCriteria()
.andField1EqualTo(1)
.andField2EqualTo("xxx")
.example()
);
// -----------------------------------andIf-----------------------------------
// Criteria增强了链式调用,现在一些按条件增加的查询条件不会打乱链式调用了
@@ -180,13 +198,13 @@ public class Test {
this.tbMapper.selectByExample(oldEx);
// new
TbExample newEx;
newEx = new TbExample()
this.tbMapper.selectByExample(
new TbExample()
.createCriteria()
.andField1EqualTo(1)
.andField2EqualTo("xxx")
// 如果随机数大于0.5,附加Field3查询条件
.andIf(Math.random() > 0.5, new TbExample.Criteria.CriteriaAdd() {
.andIf(Math.random() > 0.5, new TbExample.Criteria.ICriteriaAdd() {
@Override
public TbExample.Criteria add(TbExample.Criteria add) {
return add.andField3EqualTo(2)
@@ -198,8 +216,24 @@ public class Test {
.andField3EqualTo(2)
.andField4EqualTo(new Date())
)
.example();
this.tbMapper.selectByExample(newEx);
.example()
);
// -----------------------------------orderBy-----------------------------------
// old
TbExample ex = new TbExample();
ex.createCriteria().andField1GreaterThan(1);
ex.setOrderByClause("field1 DESC");
this.tbMapper.selectByExample(ex);
// new
this.tbMapper.selectByExample(
new TbExample()
.createCriteria()
.andField1GreaterThan(1)
.example()
.orderBy("field1 DESC")
);
}
}
```
+2 -2
View File
@@ -3,7 +3,7 @@
<groupId>com.itfsw</groupId>
<artifactId>mybatis-generator-plugin</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
@@ -175,7 +175,7 @@
<connection>scm:git:https://github.com/itfsw/mybatis-generator-plugin.git</connection>
<developerConnection>scm:git:https://github.com/itfsw/mybatis-generator-plugin.git</developerConnection>
<url>https://github.com/itfsw/mybatis-generator-plugin</url>
<tag>v1.0.3</tag>
<tag>v1.0.4</tag>
</scm>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++distribution++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@@ -79,7 +79,6 @@ public class BatchInsertPlugin extends PluginAdapter {
*/
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
logger.debug("itfsw:生成" + interfaze.getType() + "对应batchInsert方法...");
// 方法生成
Method method = new Method(METHOD_BATCH_INSERT);
// 方法可见性 interface会忽略
@@ -95,6 +94,7 @@ public class BatchInsertPlugin extends PluginAdapter {
// interface 增加方法
interfaze.addMethod(method);
logger.debug("itfsw(批量插入插件):" + interfaze.getType().getShortName() + "增加batchInsert方法。");
return true;
}
@@ -190,6 +190,7 @@ public class BatchInsertPlugin extends PluginAdapter {
if (context.getPlugins().sqlMapInsertElementGenerated(element, introspectedTable)) {
document.getRootElement().addElement(element);
logger.debug("itfsw(批量插入插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加batchInsert实现方法。");
}
}
}
@@ -16,13 +16,6 @@
package com.itfsw.mybatis.generator.plugins;
import com.itfsw.mybatis.generator.plugins.utils.CommentTools;
import com.itfsw.mybatis.generator.plugins.utils.InnerInterface;
import com.itfsw.mybatis.generator.plugins.utils.InnerInterfaceWrapperToInnerClass;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.internal.util.StringUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,121 +29,16 @@ import java.util.List;
* @time:2016/12/28 14:56
* ---------------------------------------------------------------------------
*/
public class CriteriaBuilderPlugin extends PluginAdapter {
@Deprecated
public class CriteriaBuilderPlugin extends ExampleEnhancedPlugin{
private static final Logger logger = LoggerFactory.getLogger(CriteriaBuilderPlugin.class);
/**
* {@inheritDoc}
*/
@Override
public boolean validate(List<String> warnings) {
// 插件使用前提是targetRuntime为MyBatis3
if (StringUtility.stringHasValue(getContext().getTargetRuntime()) && "MyBatis3".equalsIgnoreCase(getContext().getTargetRuntime()) == false ){
logger.warn("itfsw:插件"+this.getClass().getTypeName()+"要求运行targetRuntime必须为MyBatis3!");
return false;
}
return true;
}
/**
* ModelExample Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param topLevelClass
* @param introspectedTable
* @return
*/
@Override
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
List<InnerClass> innerClasses = topLevelClass.getInnerClasses();
for (InnerClass innerClass : innerClasses) {
if ("Criteria".equals(innerClass.getType().getShortName())) {
// 工厂方法
addFactoryMethodToCriteria(topLevelClass, innerClass, introspectedTable);
// andIf
addAndIfMethodToCriteria(topLevelClass, innerClass, introspectedTable);
}
}
List<Method> methods = topLevelClass.getMethods();
for (Method method : methods) {
if (!"createCriteriaInternal".equals(method.getName()))
continue;
method.getBodyLines().set(0, "Criteria criteria = new Criteria(this);");
logger.debug("itfsw:CriteriaBuilder修改Example的createCriteriaInternal方法,修改构造Criteria时传入Example对象");
}
return true;
}
/**
* 添加工厂方法
*
* @param topLevelClass
* @param innerClass
* @param introspectedTable
*/
private void addFactoryMethodToCriteria(TopLevelClass topLevelClass, InnerClass innerClass, IntrospectedTable introspectedTable) {
Field f = new Field("example", topLevelClass.getType());
f.setVisibility(JavaVisibility.PRIVATE);
innerClass.addField(f);
// overwrite constructor
List<Method> methods = innerClass.getMethods();
for (Method method : methods) {
if (method.isConstructor()) {
method.addParameter(new Parameter(topLevelClass.getType(), "example"));
method.addBodyLine("this.example = example;");
logger.debug("itfsw:CriteriaBuilder修改Criteria的构造方法,增加example参数");
}
}
// add factory method "example"
Method method = new Method("example");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(topLevelClass.getType());
method.addBodyLine("return this.example;");
CommentTools.addGeneralMethodComment(method, introspectedTable);
innerClass.addMethod(method);
logger.debug("itfsw:CriteriaBuilder增加工厂方法example");
}
/**
* 增强Criteria的链式调用,添加andIf(boolean addIf, CriteriaAdd add)方法,实现链式调用中按条件增加查询语句
*
* @param topLevelClass
* @param innerClass
* @param introspectedTable
*/
private void addAndIfMethodToCriteria(TopLevelClass topLevelClass, InnerClass innerClass, IntrospectedTable introspectedTable){
// 添加接口CriteriaAdd
InnerInterface criteriaAddInterface = new InnerInterface("ICriteriaAdd");
criteriaAddInterface.setVisibility(JavaVisibility.PUBLIC);
CommentTools.addInterfaceComment(criteriaAddInterface, introspectedTable);
// ICriteriaAdd增加接口add
Method addMethod = new Method("add");
addMethod.setReturnType(innerClass.getType());
addMethod.addParameter(new Parameter(innerClass.getType(), "add"));
CommentTools.addGeneralMethodComment(addMethod, introspectedTable);
criteriaAddInterface.addMethod(addMethod);
logger.debug("itfsw:Criteria.ICriteriaAdd增加接口add");
InnerClass innerClassWrapper = new InnerInterfaceWrapperToInnerClass(criteriaAddInterface);
innerClass.addInnerClass(innerClassWrapper);
// 添加andIf方法
Method method = new Method("andIf");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(innerClass.getType());
method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "ifAdd"));
method.addParameter(new Parameter(criteriaAddInterface.getType(), "add"));
method.addBodyLine("if (ifAdd) {");
method.addBodyLine("add.add(this);");
method.addBodyLine("}");
method.addBodyLine("return this;");
CommentTools.addGeneralMethodComment(method, introspectedTable);
innerClass.addMethod(method);
logger.debug("itfsw:Criteria增加方法andIf");
logger.warn("itfsw:插件"+this.getClass().getTypeName()+"插件已经过时,请使用com.itfsw.mybatis.generator.plugins.ExampleEnhancedPlugin插件替换!");
return super.validate(warnings);
}
}
@@ -0,0 +1,166 @@
package com.itfsw.mybatis.generator.plugins;
import com.itfsw.mybatis.generator.plugins.utils.CommentTools;
import com.itfsw.mybatis.generator.plugins.utils.InnerInterface;
import com.itfsw.mybatis.generator.plugins.utils.InnerInterfaceWrapperToInnerClass;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.internal.util.StringUtility;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
/**
* ---------------------------------------------------------------------------
* Example 增强插件
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2017/1/16 16:28
* ---------------------------------------------------------------------------
*/
public class ExampleEnhancedPlugin extends PluginAdapter {
private static final Logger logger = LoggerFactory.getLogger(ExampleEnhancedPlugin.class);
/**
* {@inheritDoc}
*/
@Override
public boolean validate(List<String> warnings) {
// 插件使用前提是targetRuntime为MyBatis3
if (StringUtility.stringHasValue(getContext().getTargetRuntime()) && "MyBatis3".equalsIgnoreCase(getContext().getTargetRuntime()) == false ){
logger.warn("itfsw:插件"+this.getClass().getTypeName()+"要求运行targetRuntime必须为MyBatis3!");
return false;
}
return true;
}
/**
* ModelExample Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param topLevelClass
* @param introspectedTable
* @return
*/
@Override
public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
List<InnerClass> innerClasses = topLevelClass.getInnerClasses();
for (InnerClass innerClass : innerClasses) {
if ("Criteria".equals(innerClass.getType().getShortName())) {
// 工厂方法
addFactoryMethodToCriteria(topLevelClass, innerClass, introspectedTable);
// andIf
addAndIfMethodToCriteria(topLevelClass, innerClass, introspectedTable);
}
}
List<Method> methods = topLevelClass.getMethods();
for (Method method : methods) {
if (!"createCriteriaInternal".equals(method.getName()))
continue;
method.getBodyLines().set(0, "Criteria criteria = new Criteria(this);");
logger.debug("itfsw(Example增强插件):"+topLevelClass.getType().getShortName()+"修改createCriteriaInternal方法,修改构造Criteria时传入Example对象");
}
// orderBy方法
addOrderByMethodToExample(topLevelClass, introspectedTable);
return true;
}
/**
* 添加工厂方法
*
* @param topLevelClass
* @param innerClass
* @param introspectedTable
*/
private void addFactoryMethodToCriteria(TopLevelClass topLevelClass, InnerClass innerClass, IntrospectedTable introspectedTable) {
Field f = new Field("example", topLevelClass.getType());
f.setVisibility(JavaVisibility.PRIVATE);
innerClass.addField(f);
// overwrite constructor
List<Method> methods = innerClass.getMethods();
for (Method method : methods) {
if (method.isConstructor()) {
method.addParameter(new Parameter(topLevelClass.getType(), "example"));
method.addBodyLine("this.example = example;");
logger.debug("itfsw(Example增强插件):"+topLevelClass.getType().getShortName()+"修改构造方法,增加example参数");
}
}
// add factory method "example"
Method method = new Method("example");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(topLevelClass.getType());
method.addBodyLine("return this.example;");
CommentTools.addGeneralMethodComment(method, introspectedTable);
innerClass.addMethod(method);
logger.debug("itfsw(Example增强插件):"+topLevelClass.getType().getShortName()+"."+innerClass.getType().getShortName()+"增加工厂方法example");
}
/**
* 增强Criteria的链式调用,添加andIf(boolean addIf, CriteriaAdd add)方法,实现链式调用中按条件增加查询语句
*
* @param topLevelClass
* @param innerClass
* @param introspectedTable
*/
private void addAndIfMethodToCriteria(TopLevelClass topLevelClass, InnerClass innerClass, IntrospectedTable introspectedTable){
// 添加接口CriteriaAdd
InnerInterface criteriaAddInterface = new InnerInterface("ICriteriaAdd");
criteriaAddInterface.setVisibility(JavaVisibility.PUBLIC);
CommentTools.addInterfaceComment(criteriaAddInterface, introspectedTable);
logger.debug("itfsw(Example增强插件):"+topLevelClass.getType().getShortName()+"."+innerClass.getType().getShortName()+"增加接口ICriteriaAdd");
// ICriteriaAdd增加接口add
Method addMethod = new Method("add");
addMethod.setReturnType(innerClass.getType());
addMethod.addParameter(new Parameter(innerClass.getType(), "add"));
CommentTools.addGeneralMethodComment(addMethod, introspectedTable);
criteriaAddInterface.addMethod(addMethod);
logger.debug("itfsw(Example增强插件):"+topLevelClass.getType().getShortName()+"."+innerClass.getType().getShortName()+"."+criteriaAddInterface.getType().getShortName()+"增加方法add");
InnerClass innerClassWrapper = new InnerInterfaceWrapperToInnerClass(criteriaAddInterface);
innerClass.addInnerClass(innerClassWrapper);
// 添加andIf方法
Method method = new Method("andIf");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(innerClass.getType());
method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "ifAdd"));
method.addParameter(new Parameter(criteriaAddInterface.getType(), "add"));
method.addBodyLine("if (ifAdd) {");
method.addBodyLine("add.add(this);");
method.addBodyLine("}");
method.addBodyLine("return this;");
CommentTools.addGeneralMethodComment(method, introspectedTable);
innerClass.addMethod(method);
logger.debug("itfsw(Example增强插件):"+topLevelClass.getType().getShortName()+"."+innerClass.getType().getShortName()+"增加方法andIf");
}
/**
* Example增强了setOrderByClause方法,新增orderBy(String orderByClause)方法直接返回example,增强链式调用,可以一路.下去了。
*
* @param topLevelClass
* @param introspectedTable
*/
private void addOrderByMethodToExample(TopLevelClass topLevelClass, IntrospectedTable introspectedTable){
// 添加orderBy
Method method = new Method("orderBy");
method.setVisibility(JavaVisibility.PUBLIC);
method.setReturnType(topLevelClass.getType());
method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "orderByClause"));
method.addBodyLine("this.setOrderByClause(orderByClause);");
method.addBodyLine("return this;");
CommentTools.addGeneralMethodComment(method, introspectedTable);
topLevelClass.addMethod(method);
logger.debug("itfsw(Example增强插件):"+topLevelClass.getType().getShortName()+"增加方法orderBy");
}
}
@@ -80,7 +80,7 @@ public class ExampleTargetPlugin extends PluginAdapter {
introspectedTable.setExampleType(newExampleType);
logger.debug("itfsw:修改"+exampleType+"的包到"+this.targetPackage);
logger.debug("itfsw(Example 目标包修改插件):修改"+introspectedTable.getExampleType()+"的包到"+this.targetPackage);
}
}
@@ -82,7 +82,7 @@ public class LimitPlugin extends PluginAdapter {
rows.setType(integerWrapper);
CommentTools.addFieldComment(rows, introspectedTable);
topLevelClass.addField(rows);
logger.debug("itfsw:分页插件增加Example的offset和rows字段");
logger.debug("itfsw(MySQL分页插件):"+topLevelClass.getType().getShortName()+"增加offset和rows字段");
// 增加getter && setter 方法
Method setOffset = new Method();
@@ -116,38 +116,44 @@ public class LimitPlugin extends PluginAdapter {
getRows.addBodyLine("return rows;");
CommentTools.addGeneralMethodComment(getRows, introspectedTable);
topLevelClass.addMethod(getRows);
logger.debug("itfsw:分页插件增加Example的offset和rows的getter和setter");
logger.debug("itfsw(MySQL分页插件):"+topLevelClass.getType().getShortName()+"增加offset和rows的getter和setter实现。");
// 提供几个快捷方法
Method setLimit = new Method();
setLimit.setVisibility(JavaVisibility.PUBLIC);
setLimit.setReturnType(topLevelClass.getType());
setLimit.setName("limit");
setLimit.addParameter(new Parameter(integerWrapper, "rows"));
setLimit.addBodyLine("this.rows = rows;");
setLimit.addBodyLine("return this;");
CommentTools.addGeneralMethodComment(setLimit, introspectedTable);
topLevelClass.addMethod(setLimit);
Method setLimit2 = new Method();
setLimit2.setVisibility(JavaVisibility.PUBLIC);
setLimit2.setReturnType(topLevelClass.getType());
setLimit2.setName("limit");
setLimit2.addParameter(new Parameter(integerWrapper, "offset"));
setLimit2.addParameter(new Parameter(integerWrapper, "rows"));
setLimit2.addBodyLine("this.offset = offset;");
setLimit2.addBodyLine("this.rows = rows;");
setLimit2.addBodyLine("return this;");
CommentTools.addGeneralMethodComment(setLimit2, introspectedTable);
topLevelClass.addMethod(setLimit2);
logger.debug("itfsw:分页插件增加Example的limit方法");
logger.debug("itfsw(MySQL分页插件):"+topLevelClass.getType().getShortName()+"增加limit方法。");
Method setPage = new Method();
setPage.setVisibility(JavaVisibility.PUBLIC);
setPage.setReturnType(topLevelClass.getType());
setPage.setName("page");
setPage.addParameter(new Parameter(integerWrapper, "page"));
setPage.addParameter(new Parameter(integerWrapper, "pageSize"));
setPage.addBodyLine("this.offset = page * pageSize;");
setPage.addBodyLine("this.rows = pageSize;");
setPage.addBodyLine("return this;");
CommentTools.addGeneralMethodComment(setPage, introspectedTable);
topLevelClass.addMethod(setPage);
logger.debug("itfsw:分页插件增加Example的page方法");
logger.debug("itfsw(MySQL分页插件):"+topLevelClass.getType().getShortName()+"增加page方法");
// !!! clear 方法增加 offset 和 rows的清理
List<Method> methodList = topLevelClass.getMethods();
@@ -155,7 +161,7 @@ public class LimitPlugin extends PluginAdapter {
if (method.getName().equals("clear")){
method.addBodyLine("rows = null;");
method.addBodyLine("offset = null;");
logger.debug("itfsw:分页插件修正Example的clear方法,增加rows和offset字段的清空");
logger.debug("itfsw(MySQL分页插件):"+topLevelClass.getType().getShortName()+"修改clear方法,增加rows和offset字段的清空");
}
}
@@ -187,6 +193,8 @@ public class LimitPlugin extends PluginAdapter {
element.addElement(ifLimitNotNullElement);
logger.debug("itfsw(MySQL分页插件):"+introspectedTable.getMyBatis3XmlMapperFileName()+"selectByExample方法增加分页条件。");
return true;
}
@@ -116,10 +116,14 @@ public class LogicalDeletePlugin extends PluginAdapter {
|| JDBCType.VARCHAR == type){
this.logicalDeleteColumn = column;
} else {
logger.warn("itfsw:插件"+this.getClass().getTypeName()+"逻辑删除列的类型不支持(请使用数字列,字符串列,布尔列)!");
logger.warn("itfsw(逻辑删除插件):"+introspectedTable.getFullyQualifiedTable()+"逻辑删除列("+introspectedTable.getTableConfigurationProperty(LOGICAL_DELETE_COLUMN_KEY)+")的类型不在支持范围(请使用数字列,字符串列,布尔列)!");
}
}
}
if (introspectedTable.getTableConfigurationProperty(LOGICAL_DELETE_COLUMN_KEY) != null && this.logicalDeleteColumn == null){
logger.warn("itfsw(逻辑删除插件):"+introspectedTable.getFullyQualifiedTable()+"没有找到您配置的逻辑删除列("+introspectedTable.getTableConfigurationProperty(LOGICAL_DELETE_COLUMN_KEY)+")!");
}
}
/**
@@ -145,6 +149,7 @@ public class LogicalDeletePlugin extends PluginAdapter {
CommentTools.addGeneralMethodComment(mLogicalDeleteByExample, introspectedTable);
// interface 增加方法
interfaze.addMethod(mLogicalDeleteByExample);
logger.debug("itfsw(逻辑删除插件):"+interfaze.getType().getShortName()+"增加方法logicalDeleteByExample。");
// 2. 判断是否有主键,生成主键删除方法
if (introspectedTable.hasPrimaryKeyColumns()){
@@ -190,6 +195,7 @@ public class LogicalDeletePlugin extends PluginAdapter {
// interface 增加方法
interfaze.addImportedTypes(importedTypes);
interfaze.addMethod(mLogicalDeleteByPrimaryKey);
logger.debug("itfsw(逻辑删除插件):"+interfaze.getType().getShortName()+"增加方法logicalDeleteByPrimaryKey。");
}
}
return true;
@@ -241,6 +247,7 @@ public class LogicalDeletePlugin extends PluginAdapter {
logicalDeleteByExample.addElement(XmlElementGeneratorTools.getUpdateByExampleIncludeElement(introspectedTable));
document.getRootElement().addElement(logicalDeleteByExample);
logger.debug("itfsw(逻辑删除插件):"+introspectedTable.getMyBatis3XmlMapperFileName()+"增加方法logicalDeleteByExample的实现。");
// 2. 判断是否有主键,生成主键删除方法
if (introspectedTable.hasPrimaryKeyColumns()){
@@ -306,6 +313,7 @@ public class LogicalDeletePlugin extends PluginAdapter {
}
document.getRootElement().addElement(logicalDeleteByPrimaryKey);
logger.debug("itfsw(逻辑删除插件):"+introspectedTable.getMyBatis3XmlMapperFileName()+"增加方法logicalDeleteByPrimaryKey的实现。");
}
}
return true;
@@ -342,6 +350,7 @@ public class LogicalDeletePlugin extends PluginAdapter {
// 常量插入到第一位
ArrayList<Field> fields = (ArrayList<Field>) topLevelClass.getFields();
fields.add(0, field);
logger.debug("itfsw(逻辑删除插件):"+topLevelClass.getType().getShortName()+"增加方法DEL_FLAG的常量。");
}
return true;
}
@@ -401,6 +410,7 @@ public class LogicalDeletePlugin extends PluginAdapter {
method.addBodyLine(sb.toString());
innerClass.addMethod(method);
logger.debug("itfsw(逻辑删除插件):"+topLevelClass.getType().getShortName()+"."+innerClass.getType().getShortName()+"增加andDeleted方法。");
}
}
}
@@ -70,7 +70,7 @@ public class ModelBuilderPlugin extends PluginAdapter {
innerClass.setVisibility(JavaVisibility.PUBLIC);
innerClass.setStatic(true);
CommentTools.addClassComment(innerClass, introspectedTable);
logger.debug("itfsw:生成内部Builder类");
logger.debug("itfsw(数据Model链式构建插件):"+topLevelClass.getType().getShortName()+"增加内部Builder类。");
// 构建内部obj变量
Field f = new Field("obj", topLevelClass.getType());
@@ -84,7 +84,7 @@ public class ModelBuilderPlugin extends PluginAdapter {
constructor.addBodyLine(new StringBuilder("this.obj = new ")
.append(topLevelClass.getType().getShortName()).append("();").toString());
innerClass.addMethod(constructor);
logger.debug("itfsw:生成内部Builder类构造方法");
logger.debug("itfsw(数据Model链式构建插件):"+topLevelClass.getType().getShortName()+".Builder增加的构造方法。");
// !!可能Model存在复合主键情况,字段要加上这些
if (topLevelClass.getSuperClass() != null && topLevelClass.getSuperClass().compareTo(new FullyQualifiedJavaType(introspectedTable.getPrimaryKeyType())) == 0){
@@ -101,7 +101,7 @@ public class ModelBuilderPlugin extends PluginAdapter {
method.addBodyLine(new StringBuilder().append("return this;").toString());
CommentTools.addGeneralMethodComment(method, introspectedTable);
innerClass.addMethod(method);
logger.debug("itfsw:生成内部Builder类的复合主键字段对应方法"+field.getName());
logger.debug("itfsw(数据Model链式构建插件):"+topLevelClass.getType().getShortName()+".Builder增加"+method.getName()+"方法(复合主键)。");
}
}
@@ -119,7 +119,7 @@ public class ModelBuilderPlugin extends PluginAdapter {
method.addBodyLine(new StringBuilder().append("return this;").toString());
CommentTools.addGeneralMethodComment(method, introspectedTable);
innerClass.addMethod(method);
logger.debug("itfsw:生成内部Builder类的普通字段对应方法"+field.getName());
logger.debug("itfsw(数据Model链式构建插件):"+topLevelClass.getType().getShortName()+".Builder增加"+method.getName()+"方法。");
}
Method build = new Method("build");
@@ -128,7 +128,7 @@ public class ModelBuilderPlugin extends PluginAdapter {
build.addBodyLine("return this.obj;");
CommentTools.addGeneralMethodComment(build, introspectedTable);
innerClass.addMethod(build);
logger.debug("itfsw:生成内部Builder类的build方法");
logger.debug("itfsw(数据Model链式构建插件):"+topLevelClass.getType().getShortName()+".Builder增加build方法。");
topLevelClass.addInnerClass(innerClass);
return true;
@@ -69,7 +69,6 @@ public class SelectOneByExamplePlugin extends PluginAdapter {
*/
@Override
public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
logger.debug("itfsw:生成"+interfaze.getType()+"对应SelectOneByExample方法...");
// 方法生成
Method method = new Method(METHOD_NAME);
// 方法可见性 interface会忽略
@@ -85,6 +84,7 @@ public class SelectOneByExamplePlugin extends PluginAdapter {
// interface 增加方法
interfaze.addMethod(method);
logger.debug("itfsw(查询单条数据插件):"+interfaze.getType().getShortName()+"增加SelectOneByExample方法。");
return true;
}
@@ -98,8 +98,6 @@ public class SelectOneByExamplePlugin extends PluginAdapter {
*/
@Override
public boolean sqlMapDocumentGenerated(Document document, IntrospectedTable introspectedTable) {
logger.debug("itfsw:生成表"+introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()+"("+ (introspectedTable.hasBLOBColumns() ? "有" : "无")+"Blob类型)的mapping.xml对应SelectOneByExample方法...");
//数据库表名
String tableName = introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime();
@@ -178,6 +176,7 @@ public class SelectOneByExamplePlugin extends PluginAdapter {
// 添加到根节点
document.getRootElement().addElement(selectOneElement);
logger.debug("itfsw(查询单条数据插件):"+introspectedTable.getMyBatis3XmlMapperFileName()+"增加SelectOneByExample方法("+(introspectedTable.hasBLOBColumns() ? "有" : "无")+"Blob类型))。");
return true;
}