Commit 0f16031f authored by hewei's avatar hewei

测试工具优化,每次执行前重置数据,防止脏数据

parent eaa6be0e
...@@ -21,8 +21,6 @@ import org.apache.ibatis.session.SqlSession; ...@@ -21,8 +21,6 @@ import org.apache.ibatis.session.SqlSession;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Array; import java.lang.reflect.Array;
...@@ -52,7 +50,7 @@ public class ExampleEnhancedPluginTest { ...@@ -52,7 +50,7 @@ public class ExampleEnhancedPluginTest {
* 测试生成的example方法 * 测试生成的example方法
*/ */
@Test @Test
public void testExample() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testExample() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -73,7 +71,7 @@ public class ExampleEnhancedPluginTest { ...@@ -73,7 +71,7 @@ public class ExampleEnhancedPluginTest {
* 测试生成的orderBy方法 * 测试生成的orderBy方法
*/ */
@Test @Test
public void testOrderBy() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testOrderBy() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -96,7 +94,7 @@ public class ExampleEnhancedPluginTest { ...@@ -96,7 +94,7 @@ public class ExampleEnhancedPluginTest {
* 测试andIf方法 * 测试andIf方法
*/ */
@Test @Test
public void testAndIf() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testAndIf() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
......
...@@ -19,16 +19,11 @@ package com.itfsw.mybatis.generator.plugins; ...@@ -19,16 +19,11 @@ package com.itfsw.mybatis.generator.plugins;
import com.itfsw.mybatis.generator.plugins.tools.*; import com.itfsw.mybatis.generator.plugins.tools.*;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import java.io.IOException;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -41,15 +36,6 @@ import java.util.List; ...@@ -41,15 +36,6 @@ import java.util.List;
* --------------------------------------------------------------------------- * ---------------------------------------------------------------------------
*/ */
public class IncrementsPluginTest { public class IncrementsPluginTest {
/**
* 初始化数据库
*/
@Before
public void init() throws Exception {
DBHelper.createDB("scripts/IncrementsPlugin/init.sql");
}
/** /**
* 测试没有配置ModelBuilderPlugin * 测试没有配置ModelBuilderPlugin
*/ */
...@@ -67,7 +53,7 @@ public class IncrementsPluginTest { ...@@ -67,7 +53,7 @@ public class IncrementsPluginTest {
@Test @Test
public void testModelBuilderMethod() throws Exception { public void testModelBuilderMethod() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override @Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception { public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
// 1. 测试生成的方法 // 1. 测试生成的方法
...@@ -116,7 +102,7 @@ public class IncrementsPluginTest { ...@@ -116,7 +102,7 @@ public class IncrementsPluginTest {
@Test @Test
public void testSqlAndExecute() throws Exception { public void testSqlAndExecute() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override @Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception { public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
...@@ -216,9 +202,9 @@ public class IncrementsPluginTest { ...@@ -216,9 +202,9 @@ public class IncrementsPluginTest {
* 测试整合 SelectiveEnhancedPlugin 插件 * 测试整合 SelectiveEnhancedPlugin 插件
*/ */
@Test @Test
public void testWithSelectiveEnhancedPlugin() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testWithSelectiveEnhancedPlugin() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-selective-enhanced-plugin.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-selective-enhanced-plugin.xml");
tool.generate(new AbstractShellCallback() { tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override @Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception { public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
// 1. 测试updateByExampleSelective // 1. 测试updateByExampleSelective
...@@ -309,9 +295,9 @@ public class IncrementsPluginTest { ...@@ -309,9 +295,9 @@ public class IncrementsPluginTest {
* 测试整合 UpsertPlugin * 测试整合 UpsertPlugin
*/ */
@Test @Test
public void testWithUpsertPlugin() throws InterruptedException, SQLException, InvalidConfigurationException, IOException, XMLParserException { public void testWithUpsertPlugin() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-upsert-plugin.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-upsert-plugin.xml");
tool.generate(new AbstractShellCallback() { tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override @Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception { public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper"))); ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
...@@ -364,11 +350,12 @@ public class IncrementsPluginTest { ...@@ -364,11 +350,12 @@ public class IncrementsPluginTest {
// sql // sql
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "upsertSelective", tbBuilder.invoke("build")); sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "upsertSelective", tbBuilder.invoke("build"));
Assert.assertEquals(sql, "insert into tb ( id, field1, inc_f1, inc_f2 ) values ( 30, 'ts2', 10, 1 ) on duplicate key update id = 30, field1 = 'ts2', inc_f1 = inc_f1 + 10 , inc_f2 = 1"); Assert.assertEquals(sql, "insert into tb ( id, field1, inc_f1, inc_f2 ) values ( 30, 'ts2', 10, 1 ) on duplicate key update id = 30, field1 = 'ts2', inc_f1 = inc_f1 + 10 , inc_f2 = 1");
result = tbMapper.invoke("upsert", tbBuilder.invoke("build")); result = tbMapper.invoke("upsertSelective", tbBuilder.invoke("build"));
Assert.assertEquals(result, 1); Assert.assertEquals(result, 1);
// 再次执行触发update // 再次执行触发update
tbBuilder.invoke("incF1", 10L, tbBuilderInc.getObject()); tbBuilder.invoke("incF1", 10L, tbBuilderInc.getObject());
tbMapper.invoke("upsertSelective", tbBuilder.invoke("build")); result = tbMapper.invoke("upsertSelective", tbBuilder.invoke("build"));
Assert.assertEquals(result, 2);
rs = DBHelper.execute(sqlSession, "select * from tb where id = 30"); rs = DBHelper.execute(sqlSession, "select * from tb where id = 30");
rs.first(); rs.first();
Assert.assertEquals(rs.getInt("inc_f1"), 20); Assert.assertEquals(rs.getInt("inc_f1"), 20);
...@@ -383,11 +370,12 @@ public class IncrementsPluginTest { ...@@ -383,11 +370,12 @@ public class IncrementsPluginTest {
// sql // sql
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "upsertByExampleSelective", tbBuilder.invoke("build"), tbExample.getObject()); sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "upsertByExampleSelective", tbBuilder.invoke("build"), tbExample.getObject());
Assert.assertEquals(sql, "update tb set id = 40, field1 = 'ts3', inc_f1 = inc_f1 + 10 , inc_f2 = 1 WHERE ( field1 = 'ts3' ) ; insert into tb ( id, field1, inc_f1, inc_f2 ) select 40, 'ts3', 10, 1 from dual where not exists ( select 1 from tb WHERE ( field1 = 'ts3' ) )"); Assert.assertEquals(sql, "update tb set id = 40, field1 = 'ts3', inc_f1 = inc_f1 + 10 , inc_f2 = 1 WHERE ( field1 = 'ts3' ) ; insert into tb ( id, field1, inc_f1, inc_f2 ) select 40, 'ts3', 10, 1 from dual where not exists ( select 1 from tb WHERE ( field1 = 'ts3' ) )");
result = tbMapper.invoke("upsert", tbBuilder.invoke("build")); result = tbMapper.invoke("upsertByExampleSelective", tbBuilder.invoke("build"), tbExample.getObject());
Assert.assertEquals(result, 1); Assert.assertEquals(result, 0);
// 再次执行触发update // 再次执行触发update
tbBuilder.invoke("incF1", 10L, tbBuilderInc.getObject()); tbBuilder.invoke("incF1", 10L, tbBuilderInc.getObject());
tbMapper.invoke("upsertByExampleSelective", tbBuilder.invoke("build"), tbExample.getObject()); result = tbMapper.invoke("upsertByExampleSelective", tbBuilder.invoke("build"), tbExample.getObject());
Assert.assertEquals(result, 1);
rs = DBHelper.execute(sqlSession, "select * from tb where id = 40"); rs = DBHelper.execute(sqlSession, "select * from tb where id = 40");
rs.first(); rs.first();
Assert.assertEquals(rs.getInt("inc_f1"), 20); Assert.assertEquals(rs.getInt("inc_f1"), 20);
...@@ -399,9 +387,9 @@ public class IncrementsPluginTest { ...@@ -399,9 +387,9 @@ public class IncrementsPluginTest {
* 测试 autoDelimitKeywords * 测试 autoDelimitKeywords
*/ */
@Test @Test
public void testWithAutoDelimitKeywords() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testWithAutoDelimitKeywords() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-autoDelimitKeywords.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-autoDelimitKeywords.xml");
tool.generate(new AbstractShellCallback() { tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override @Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception { public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
// 1. 测试updateByExample、updateByExampleSelective // 1. 测试updateByExample、updateByExampleSelective
...@@ -426,4 +414,72 @@ public class IncrementsPluginTest { ...@@ -426,4 +414,72 @@ public class IncrementsPluginTest {
} }
}); });
} }
/**
* 测试同时整合 UpsertPlugin 和 SelectiveEnhancedPlugin
*/
@Test
public void testWithUpsertAndSelectiveEnhancedPlugin() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/IncrementsPlugin/mybatis-generator-with-upsert-and-selective-enhanced-plugin.xml");
tool.generate(() -> DBHelper.createDB("scripts/IncrementsPlugin/init.sql"), new AbstractShellCallback() {
@Override
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
// --------------------------- upsertSelective (非空判断) ---------------------------------
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
ObjectUtil tbBuilder = new ObjectUtil(loader, packagz + ".Tb$Builder");
ObjectUtil tbBuilderInc = new ObjectUtil(loader, packagz + ".Tb$Builder$Inc#INC");
tbBuilder.invoke("id", 10L);
tbBuilder.invoke("field1", "ts1");
tbBuilder.invoke("incF1", 10L, tbBuilderInc.getObject());
// sql
String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "upsertSelective", tbBuilder.invoke("build"));
Assert.assertEquals(sql, "insert into tb ( id, field1, inc_f1 ) values ( 10, 'ts1', 10 ) on duplicate key update id = 10, field1 = 'ts1', inc_f1 = inc_f1 + 10");
Object result = tbMapper.invoke("upsertSelective", tbBuilder.invoke("build"), Array.newInstance(new ObjectUtil(loader, packagz + ".Tb$Column#field1").getCls(), 0));
Assert.assertEquals(result, 1);
// 再次执行触发update
tbBuilder.invoke("incF1", 10L, tbBuilderInc.getObject());
tbMapper.invoke("upsertSelective", tbBuilder.invoke("build"), Array.newInstance(new ObjectUtil(loader, packagz + ".Tb$Column#field1").getCls(), 0));
ResultSet rs = DBHelper.execute(sqlSession, "select * from tb where id = 10");
rs.first();
Assert.assertEquals(rs.getInt("inc_f1"), 20);
// --------------------------- upsertSelective (指定字段) ---------------------------------
tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
tbBuilder = new ObjectUtil(loader, packagz + ".Tb$Builder");
tbBuilderInc = new ObjectUtil(loader, packagz + ".Tb$Builder$Inc#INC");
tbBuilder.invoke("id", 20L);
tbBuilder.invoke("field1", "ts1");
tbBuilder.invoke("incF1", 20L, tbBuilderInc.getObject());
ObjectUtil TbColumnId = new ObjectUtil(loader, packagz + ".Tb$Column#id");
ObjectUtil TbColumnField1 = new ObjectUtil(loader, packagz + ".Tb$Column#field1");
ObjectUtil TbColumnIncF1 = new ObjectUtil(loader, packagz + ".Tb$Column#incF1");
ObjectUtil TbColumnIncF2 = new ObjectUtil(loader, packagz + ".Tb$Column#incF2");
Object columns = Array.newInstance(TbColumnField1.getCls(), 4);
Array.set(columns, 0, TbColumnId.getObject());
Array.set(columns, 1, TbColumnField1.getObject());
Array.set(columns, 2, TbColumnIncF1.getObject());
Array.set(columns, 3, TbColumnIncF2.getObject());
// sql
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "upsertSelective", tbBuilder.invoke("build"), columns);
Assert.assertEquals(sql, "insert into tb ( id , field1 , inc_f1 , inc_f2 ) values ( 20 , 'ts1' , 20 , null ) on duplicate key update id = 20 , field1 = 'ts1' , inc_f1 = inc_f1 + 20 , inc_f2 = null");
result = tbMapper.invoke("upsertSelective", tbBuilder.invoke("build"), columns);
Assert.assertEquals(result, 1);
// 再次执行触发update
tbBuilder.invoke("incF1", 20L, tbBuilderInc.getObject());
result = tbMapper.invoke("upsertSelective", tbBuilder.invoke("build"), columns);
Assert.assertEquals(result, 2);
rs = DBHelper.execute(sqlSession, "select * from tb where id = 20");
rs.first();
Assert.assertEquals(rs.getInt("inc_f1"), 40);
}
});
}
} }
...@@ -61,7 +61,7 @@ public class LimitPluginTest { ...@@ -61,7 +61,7 @@ public class LimitPluginTest {
* 测试生成的Sql语句和具体执行 * 测试生成的Sql语句和具体执行
*/ */
@Test @Test
public void testSqlAndExecute() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testSqlAndExecute() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LimitPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LimitPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
......
...@@ -80,7 +80,7 @@ public class LogicalDeletePluginTest { ...@@ -80,7 +80,7 @@ public class LogicalDeletePluginTest {
* 测试 logicalDeleteByExample * 测试 logicalDeleteByExample
*/ */
@Test @Test
public void testLogicalDeleteByExample() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testLogicalDeleteByExample() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -108,7 +108,7 @@ public class LogicalDeletePluginTest { ...@@ -108,7 +108,7 @@ public class LogicalDeletePluginTest {
* 测试 logicalDeleteByPrimaryKey * 测试 logicalDeleteByPrimaryKey
*/ */
@Test @Test
public void testLogicalDeleteByPrimaryKey() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testLogicalDeleteByPrimaryKey() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -132,7 +132,7 @@ public class LogicalDeletePluginTest { ...@@ -132,7 +132,7 @@ public class LogicalDeletePluginTest {
* 测试关联生成的方法和常量 * 测试关联生成的方法和常量
*/ */
@Test @Test
public void testOtherMethods() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testOtherMethods() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -159,7 +159,7 @@ public class LogicalDeletePluginTest { ...@@ -159,7 +159,7 @@ public class LogicalDeletePluginTest {
* 测试自定义常量 * 测试自定义常量
*/ */
@Test @Test
public void testCustomConst() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testCustomConst() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator-with-customConstName.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator-with-customConstName.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -186,7 +186,7 @@ public class LogicalDeletePluginTest { ...@@ -186,7 +186,7 @@ public class LogicalDeletePluginTest {
* 测试Model andLogicalDeleted 方法 * 测试Model andLogicalDeleted 方法
*/ */
@Test @Test
public void testModelAndLogicalDeletedMethod() throws InterruptedException, SQLException, InvalidConfigurationException, IOException, XMLParserException { public void testModelAndLogicalDeletedMethod() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator-with-customConstName.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator-with-customConstName.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -206,7 +206,7 @@ public class LogicalDeletePluginTest { ...@@ -206,7 +206,7 @@ public class LogicalDeletePluginTest {
* 测试 selectByPrimaryKeyWithLogicalDelete * 测试 selectByPrimaryKeyWithLogicalDelete
*/ */
@Test @Test
public void testSelectByPrimaryKeyWithLogicalDelete() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testSelectByPrimaryKeyWithLogicalDelete() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator-with-customConstName.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator-with-customConstName.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
......
...@@ -24,8 +24,6 @@ import org.apache.ibatis.session.SqlSession; ...@@ -24,8 +24,6 @@ import org.apache.ibatis.session.SqlSession;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -51,7 +49,7 @@ public class ModelBuilderPluginTest { ...@@ -51,7 +49,7 @@ public class ModelBuilderPluginTest {
* 测试生成的model * 测试生成的model
*/ */
@Test @Test
public void test() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void test() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ModelBuilderPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ModelBuilderPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -113,7 +111,7 @@ public class ModelBuilderPluginTest { ...@@ -113,7 +111,7 @@ public class ModelBuilderPluginTest {
* 测试静态builder方法 * 测试静态builder方法
*/ */
@Test @Test
public void testBuilderMethod() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testBuilderMethod() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ModelBuilderPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ModelBuilderPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
......
...@@ -24,8 +24,6 @@ import org.apache.ibatis.session.SqlSession; ...@@ -24,8 +24,6 @@ import org.apache.ibatis.session.SqlSession;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -51,7 +49,7 @@ public class ModelColumnPluginTest { ...@@ -51,7 +49,7 @@ public class ModelColumnPluginTest {
* 测试生成的model * 测试生成的model
*/ */
@Test @Test
public void test() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void test() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ModelColumnPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ModelColumnPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
......
...@@ -65,7 +65,7 @@ public class OldSelectiveEnhancedPluginTest { ...@@ -65,7 +65,7 @@ public class OldSelectiveEnhancedPluginTest {
* 测试Model * 测试Model
*/ */
@Test @Test
public void testModel() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testModel() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -91,7 +91,7 @@ public class OldSelectiveEnhancedPluginTest { ...@@ -91,7 +91,7 @@ public class OldSelectiveEnhancedPluginTest {
* 测试insertSelective增强 * 测试insertSelective增强
*/ */
@Test @Test
public void testInsertSelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testInsertSelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -125,7 +125,7 @@ public class OldSelectiveEnhancedPluginTest { ...@@ -125,7 +125,7 @@ public class OldSelectiveEnhancedPluginTest {
* 测试 updateByExampleSelective * 测试 updateByExampleSelective
*/ */
@Test @Test
public void testUpdateByExampleSelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpdateByExampleSelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -160,7 +160,7 @@ public class OldSelectiveEnhancedPluginTest { ...@@ -160,7 +160,7 @@ public class OldSelectiveEnhancedPluginTest {
* 测试 updateByPrimaryKeySelective * 测试 updateByPrimaryKeySelective
*/ */
@Test @Test
public void testUpdateByPrimaryKeySelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpdateByPrimaryKeySelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -192,7 +192,7 @@ public class OldSelectiveEnhancedPluginTest { ...@@ -192,7 +192,7 @@ public class OldSelectiveEnhancedPluginTest {
* 测试 upsertSelective * 测试 upsertSelective
*/ */
@Test @Test
public void testUpsertSelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpsertSelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -226,7 +226,7 @@ public class OldSelectiveEnhancedPluginTest { ...@@ -226,7 +226,7 @@ public class OldSelectiveEnhancedPluginTest {
* 测试 upsertByExampleSelective * 测试 upsertByExampleSelective
*/ */
@Test @Test
public void testUpsertByExampleSelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpsertByExampleSelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/OldSelectiveEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
......
...@@ -21,8 +21,6 @@ import org.apache.ibatis.session.SqlSession; ...@@ -21,8 +21,6 @@ import org.apache.ibatis.session.SqlSession;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
...@@ -48,7 +46,7 @@ public class SelectOneByExamplePluginTest { ...@@ -48,7 +46,7 @@ public class SelectOneByExamplePluginTest {
* 测试 selectOneByExample * 测试 selectOneByExample
*/ */
@Test @Test
public void testSelectOneByExample() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testSelectOneByExample() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectOneByExamplePlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectOneByExamplePlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -75,7 +73,7 @@ public class SelectOneByExamplePluginTest { ...@@ -75,7 +73,7 @@ public class SelectOneByExamplePluginTest {
* 测试 selectOneByExampleWithBLOBs * 测试 selectOneByExampleWithBLOBs
*/ */
@Test @Test
public void testSelectOneByExampleWithBLOBs() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testSelectOneByExampleWithBLOBs() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectOneByExamplePlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectOneByExamplePlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
......
...@@ -65,7 +65,7 @@ public class SelectiveEnhancedPluginTest { ...@@ -65,7 +65,7 @@ public class SelectiveEnhancedPluginTest {
* 测试insertSelective增强 * 测试insertSelective增强
*/ */
@Test @Test
public void testInsertSelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testInsertSelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectiveEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectiveEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -98,7 +98,7 @@ public class SelectiveEnhancedPluginTest { ...@@ -98,7 +98,7 @@ public class SelectiveEnhancedPluginTest {
* 测试 updateByExampleSelective * 测试 updateByExampleSelective
*/ */
@Test @Test
public void testUpdateByExampleSelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpdateByExampleSelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectiveEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectiveEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -132,7 +132,7 @@ public class SelectiveEnhancedPluginTest { ...@@ -132,7 +132,7 @@ public class SelectiveEnhancedPluginTest {
* 测试 updateByPrimaryKeySelective * 测试 updateByPrimaryKeySelective
*/ */
@Test @Test
public void testUpdateByPrimaryKeySelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpdateByPrimaryKeySelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectiveEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectiveEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -163,7 +163,7 @@ public class SelectiveEnhancedPluginTest { ...@@ -163,7 +163,7 @@ public class SelectiveEnhancedPluginTest {
* 测试 upsertSelective * 测试 upsertSelective
*/ */
@Test @Test
public void testUpsertSelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpsertSelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectiveEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectiveEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -196,7 +196,7 @@ public class SelectiveEnhancedPluginTest { ...@@ -196,7 +196,7 @@ public class SelectiveEnhancedPluginTest {
* 测试 upsertByExampleSelective * 测试 upsertByExampleSelective
*/ */
@Test @Test
public void testUpsertByExampleSelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpsertByExampleSelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectiveEnhancedPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/SelectiveEnhancedPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
......
...@@ -65,7 +65,7 @@ public class UpsertPluginTest { ...@@ -65,7 +65,7 @@ public class UpsertPluginTest {
* 测试 upsert * 测试 upsert
*/ */
@Test @Test
public void testUpsert() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpsert() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -97,7 +97,7 @@ public class UpsertPluginTest { ...@@ -97,7 +97,7 @@ public class UpsertPluginTest {
* 测试 upsertWithBLOBs * 测试 upsertWithBLOBs
*/ */
@Test @Test
public void testUpsertWithBLOBs() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpsertWithBLOBs() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -151,7 +151,7 @@ public class UpsertPluginTest { ...@@ -151,7 +151,7 @@ public class UpsertPluginTest {
* 测试 upsertSelective * 测试 upsertSelective
*/ */
@Test @Test
public void testUpsertSelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpsertSelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -190,7 +190,7 @@ public class UpsertPluginTest { ...@@ -190,7 +190,7 @@ public class UpsertPluginTest {
* 测试 upsertByExample * 测试 upsertByExample
*/ */
@Test @Test
public void testUpsertByExample() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpsertByExample() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -226,7 +226,7 @@ public class UpsertPluginTest { ...@@ -226,7 +226,7 @@ public class UpsertPluginTest {
* 测试 upsertByExampleWithBLOBs * 测试 upsertByExampleWithBLOBs
*/ */
@Test @Test
public void testUpsertByExampleWithBLOBs() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpsertByExampleWithBLOBs() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -287,7 +287,7 @@ public class UpsertPluginTest { ...@@ -287,7 +287,7 @@ public class UpsertPluginTest {
* 测试 upsertByExampleSelective * 测试 upsertByExampleSelective
*/ */
@Test @Test
public void testUpsertByExampleSelective() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testUpsertByExampleSelective() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
...@@ -332,7 +332,7 @@ public class UpsertPluginTest { ...@@ -332,7 +332,7 @@ public class UpsertPluginTest {
* 测试 存在自增主键的情况 * 测试 存在自增主键的情况
*/ */
@Test @Test
public void testWithIdentityAndGeneratedAlwaysColumns() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { public void testWithIdentityAndGeneratedAlwaysColumns() throws Exception {
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml"); MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/UpsertPlugin/mybatis-generator.xml");
tool.generate(new AbstractShellCallback() { tool.generate(new AbstractShellCallback() {
@Override @Override
......
/*
* 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.tools;
/**
* ---------------------------------------------------------------------------
* 回调之前执行
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2018/4/25 18:42
* ---------------------------------------------------------------------------
*/
public interface IBeforeCallback {
/**
* 执行
*/
void run() throws Exception;
}
...@@ -81,19 +81,35 @@ public class MyBatisGeneratorTool { ...@@ -81,19 +81,35 @@ public class MyBatisGeneratorTool {
/** /**
* 执行MyBatisGenerator * 执行MyBatisGenerator
* @param before
* @param callback * @param callback
* @return * @return
* @throws SQLException * @throws SQLException
* @throws IOException * @throws IOException
* @throws InterruptedException * @throws InterruptedException
*/ */
public MyBatisGenerator generate(AbstractShellCallback callback) throws InvalidConfigurationException, InterruptedException, SQLException, IOException { public MyBatisGenerator generate(IBeforeCallback before, AbstractShellCallback callback) throws Exception {
before.run();
callback.setTool(this); callback.setTool(this);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null, null, null, true); myBatisGenerator.generate(null, null, null, true);
return myBatisGenerator; return myBatisGenerator;
} }
/**
* 执行MyBatisGenerator
* @param callback
* @return
* @throws SQLException
* @throws IOException
* @throws InterruptedException
*/
public MyBatisGenerator generate(AbstractShellCallback callback) throws Exception {
return this.generate(() -> {
}, callback);
}
/** /**
* 执行MyBatisGenerator(不生成文件) * 执行MyBatisGenerator(不生成文件)
* @return * @return
......
...@@ -23,7 +23,7 @@ CREATE TABLE `tb` ( ...@@ -23,7 +23,7 @@ CREATE TABLE `tb` (
`id` bigint(20) NOT NULL COMMENT '注释1', `id` bigint(20) NOT NULL COMMENT '注释1',
`field1` varchar(255) DEFAULT NULL COMMENT '注释2', `field1` varchar(255) DEFAULT NULL COMMENT '注释2',
`inc_f1` bigint(20) NOT NULL DEFAULT '0', `inc_f1` bigint(20) NOT NULL DEFAULT '0',
`inc_f2` bigint(20) NOT NULL DEFAULT '0', `inc_f2` bigint(20) DEFAULT '0',
`inc_f3` bigint(20) DEFAULT '0', `inc_f3` bigint(20) DEFAULT '0',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<properties resource="db.properties"/>
<!--导入属性配置 -->
<context id="default" targetRuntime="MyBatis3">
<!-- 插件 -->
<plugin type="com.itfsw.mybatis.generator.plugins.IncrementsPlugin" />
<plugin type="com.itfsw.mybatis.generator.plugins.ModelBuilderPlugin" />
<plugin type="com.itfsw.mybatis.generator.plugins.UpsertPlugin">
<property name="allowMultiQueries" value="true"/>
</plugin>
<plugin type="com.itfsw.mybatis.generator.plugins.ModelColumnPlugin"/>
<plugin type="com.itfsw.mybatis.generator.plugins.SelectiveEnhancedPlugin"/>
<!--jdbc的数据库连接 -->
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
targetPackage 指定生成的model生成所在的包名
targetProject 指定在该项目下所在的路径 -->
<javaModelGenerator targetPackage="" targetProject="">
<!-- 是否对model添加 构造函数 -->
<property name="constructorBased" value="true"/>
<!-- 给Model添加一个父类 -->
<!--<property name="rootClass" value="com.itfsw.base"/>-->
</javaModelGenerator>
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
<sqlMapGenerator targetPackage="" targetProject="" />
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<table tableName="tb">
<property name="incrementsColumns" value="inc_f1"/>
</table>
<table tableName="tb_keys">
<property name="incrementsColumns" value="inc_f1,inc_f2,inc_f3"/>
</table>
<table tableName="tb_blobs">
<property name="incrementsColumns" value="inc_f1,inc_f3"/>
</table>
</context>
</generatorConfiguration>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment