bugfix[issues#39]:OptimisticLockerPlugin表配置属性作用域异常
This commit is contained in:
@@ -69,6 +69,8 @@ public class OptimisticLockerPlugin extends BasePlugin implements IModelBuilderP
|
||||
if (this.versionColumn == null) {
|
||||
warnings.add("itfsw(乐观锁插件):表" + introspectedTable.getFullyQualifiedTable() + "配置的版本列(" + introspectedTable.getTableConfigurationProperty(PRO_VERSION_COLUMN) + ")没有找到!");
|
||||
}
|
||||
} else {
|
||||
this.versionColumn = null;
|
||||
}
|
||||
|
||||
// 自定义nextVersion
|
||||
|
||||
@@ -71,7 +71,7 @@ public class BugFixedTest {
|
||||
|
||||
sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "selectByExampleSelective", tbExample.getObject(), columns);
|
||||
Assert.assertEquals(sql, "select id , field1 , `table` from tb Test WHERE ( Test.id < '160' ) order by `table` ASC");
|
||||
ObjectUtil result1 = new ObjectUtil(((List)tbMapper.invoke("selectByExampleSelective", tbExample.getObject(), columns)).get(0));
|
||||
ObjectUtil result1 = new ObjectUtil(((List) tbMapper.invoke("selectByExampleSelective", tbExample.getObject(), columns)).get(0));
|
||||
Assert.assertEquals(result1.get("table"), "tb");
|
||||
}
|
||||
});
|
||||
@@ -107,4 +107,24 @@ public class BugFixedTest {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 乐观锁插件好像变量作用域问题导致,前一个表的配置会影响后一个表配置
|
||||
*/
|
||||
@Test
|
||||
public void issues39() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/issues-39.xml");
|
||||
tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-39.sql"), new AbstractShellCallback() {
|
||||
@Override
|
||||
public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception {
|
||||
ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));
|
||||
// 第一个生成对应方法
|
||||
Assert.assertEquals(tbMapper.getMethods(OptimisticLockerPlugin.METHOD_DELETE_WITH_VERSION_BY_EXAMPLE).size(), 1);
|
||||
|
||||
ObjectUtil tb1Mapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".Tb1Mapper")));
|
||||
// 第一个生成对应方法
|
||||
Assert.assertEquals(tb1Mapper.getMethods(OptimisticLockerPlugin.METHOD_DELETE_WITH_VERSION_BY_EXAMPLE).size(), 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Navicat MySQL Data Transfer
|
||||
|
||||
Source Server : localhost
|
||||
Source Server Version : 50617
|
||||
Source Host : localhost:3306
|
||||
Source Database : mybatis-generator-plugin
|
||||
|
||||
Target Server Type : MYSQL
|
||||
Target Server Version : 50617
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 2017-06-27 11:17:08
|
||||
*/
|
||||
|
||||
SET FOREIGN_KEY_CHECKS=0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb`;
|
||||
CREATE TABLE `tb` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`vs` int DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for tb1
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `tb1`;
|
||||
CREATE TABLE `tb1` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',
|
||||
`field1` varchar(255) DEFAULT NULL COMMENT '注释2',
|
||||
`vs` int DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
@@ -0,0 +1,58 @@
|
||||
<?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">
|
||||
<property name="autoDelimitKeywords" value="true"/>
|
||||
<property name="beginningDelimiter" value="`"/>
|
||||
<property name="endingDelimiter" value="`"/>
|
||||
|
||||
<!-- 乐观锁插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.OptimisticLockerPlugin"></plugin>
|
||||
|
||||
<!--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="versionColumn" value="vs"/>
|
||||
</table>
|
||||
<table tableName="tb1">
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
Reference in New Issue
Block a user