Skip to content

Commit

Permalink
delete 方法去掉乐观锁条件
Browse files Browse the repository at this point in the history
  • Loading branch information
abel533 committed Nov 24, 2018
1 parent 334ef6e commit 0d63b7b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public String delete(MappedStatement ms) {
sql.append(SqlHelper.notAllNullParameterCheck("_parameter", EntityHelper.getColumns(entityClass)));
}
sql.append(SqlHelper.deleteFromTable(entityClass, tableName(entityClass)));
sql.append(SqlHelper.whereAllIfColumns(entityClass, isNotEmpty(), true));
sql.append(SqlHelper.whereAllIfColumns(entityClass, isNotEmpty()));
return sql.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
import org.junit.Assert;
import org.junit.Test;
import tk.mybatis.mapper.mapper.CountryMapper;
import tk.mybatis.mapper.mapper.CountryVersionMapper;
import tk.mybatis.mapper.mapper.MybatisHelper;
import tk.mybatis.mapper.model.Country;
import tk.mybatis.mapper.model.CountryVersion;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -153,60 +151,6 @@ public void testDynamicDeleteException() {
}
}

/**
* 乐观锁删除
*/
@Test
public void testDeleteByVersion() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryVersionMapper mapper = sqlSession.getMapper(CountryVersionMapper.class);
CountryVersion countryVersion = new CountryVersion();
countryVersion.setId(100);

//没有指定版本时删除不了
Assert.assertEquals(0, mapper.delete(countryVersion));

//版本不对的时候的时候删除不了
countryVersion.setVersion(2);
Assert.assertEquals(0, mapper.delete(countryVersion));

//版本正确的时候可以真正删除
countryVersion.setVersion(1);
Assert.assertEquals(1, mapper.delete(countryVersion));
} finally {
sqlSession.rollback();
sqlSession.close();
}
}

/**
* 乐观锁删除
*/
@Test
public void testDeleteByPrimaryKeyAndVersion() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
CountryVersionMapper mapper = sqlSession.getMapper(CountryVersionMapper.class);
//根据主键删除,没有指定版本时删除不了
Assert.assertEquals(0, mapper.deleteByPrimaryKey(100));

CountryVersion countryVersion = new CountryVersion();
countryVersion.setId(100);

//版本不对的时候的时候删除不了
countryVersion.setVersion(2);
Assert.assertEquals(0, mapper.deleteByPrimaryKey(countryVersion));

//版本正确的时候可以真正删除
countryVersion.setVersion(1);
Assert.assertEquals(1, mapper.deleteByPrimaryKey(countryVersion));
} finally {
sqlSession.rollback();
sqlSession.close();
}
}

class Key {
}

Expand Down

0 comments on commit 0d63b7b

Please sign in to comment.