从拦截器代码看得出与之前文章写的实现思路一样,拦截器会在更新操作时以查询时查到的version值为条件,并设置新的version值为version+1,这样一来如果version值存在即没有被修改就可以更新成功。
public Object intercept(Invocation invocation) throws Throwable {
Object[] args = invocation.getArgs();
MappedStatement ms = (MappedStatement)args[0];
if (SqlCommandType.UPDATE != ms.getSqlCommandType()) {
return invocation.proceed();
} else {
Object param = args[1];
if (param instanceof Map) {
Map map = (Map)param;
Object et = map.getOrDefault("et", (Object)null);
if (et != null) {
String methodId = ms.getId();
String methodName = methodId.substring(methodId.lastIndexOf(".") + 1);
TableInfo tableInfo = TableInfoHelper.getTableInfo(et.getClass());