Compare commits

...
6 Commits
4 changed files with 40 additions and 11 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ Maven引用:
<dependency>
<groupId>com.itfsw</groupId>
<artifactId>mybatis-generator-plugin</artifactId>
<version>1.2.1</version>
<version>1.2.2</version>
</dependency>
```
---------------------------------------
+2 -2
View File
@@ -3,7 +3,7 @@
<groupId>com.itfsw</groupId>
<artifactId>mybatis-generator-plugin</artifactId>
<version>1.2.2</version>
<version>1.2.3</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
@@ -212,7 +212,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.2.2</tag>
<tag>V1.2.3</tag>
</scm>
<!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++distribution++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@@ -41,6 +41,14 @@ public class SelectOneByExamplePlugin extends BasePlugin {
private XmlElement selectOneByExampleEle;
private XmlElement selectOneByExampleWithBLOBsEle;
@Override
public void initialized(IntrospectedTable introspectedTable) {
super.initialized(introspectedTable);
// bug:26,27
this.selectOneByExampleWithBLOBsEle = null;
this.selectOneByExampleEle = null;
}
/**
* Java Client Methods 生成
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
@@ -20,10 +20,7 @@ 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.IntrospectedTable;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
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.java.*;
import org.mybatis.generator.api.dom.xml.*;
import org.mybatis.generator.codegen.mybatis3.MyBatis3FormattingUtilities;
@@ -44,6 +41,8 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
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 ID_FOR_PROPERTY_BASED_RESULT_MAP = "BasePropertyResultMap";
private XmlElement selectByExampleSelectiveEle;
private XmlElement selectByPrimaryKeySelectiveEle;
/**
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
@@ -62,6 +61,19 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
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;
}
// =========================================== client 方法生成 ===================================================
@Override
@@ -120,18 +132,24 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
// ============================================== sqlMap 生成 ===================================================
@Override
public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
this.selectByExampleSelectiveEle = this.generateSelectSelectiveElement(METHOD_SELECT_BY_EXAMPLE_SELECTIVE, introspectedTable, false, true);
return super.sqlMapSelectByExampleWithoutBLOBsElementGenerated(element, introspectedTable);
}
@Override
public boolean sqlMapSelectByExampleWithBLOBsElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
if (!introspectedTable.hasBLOBColumns()) {
this.selectByExampleSelectiveEle = this.generateSelectSelectiveElement(METHOD_SELECT_BY_EXAMPLE_SELECTIVE, introspectedTable, false, true);
}
return super.sqlMapSelectByExampleWithBLOBsElementGenerated(element, introspectedTable);
}
@Override
public boolean sqlMapSelectByPrimaryKeyElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {
this.selectByPrimaryKeySelectiveEle = this.generateSelectSelectiveElement(METHOD_SELECT_BY_PRIMARY_KEY_SELECTIVE, introspectedTable, false, false);
return super.sqlMapSelectByPrimaryKeyElementGenerated(element, introspectedTable);
}
@@ -156,15 +174,18 @@ public class SelectSelectivePlugin extends BasePlugin implements ISelectOneByExa
for (IntrospectedColumn introspectedColumn : introspectedTable.getNonPrimaryKeyColumns()) {
resultMapEle.addElement(XmlElementGeneratorTools.generateResultMapResultElement("result", introspectedColumn));
}
document.getRootElement().getElements().add(0, resultMapEle);
document.getRootElement().addElement(0, resultMapEle);
}
// 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
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;
}