Переглянути джерело

Merge remote-tracking branch 'origin/dev' into dev

= 7 роки тому
батько
коміт
d35c07984b

+ 2 - 3
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/plugins/OptimisticLockerInterceptor.java

@@ -10,7 +10,6 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.apache.ibatis.binding.MapperMethod;
 import org.apache.ibatis.executor.Executor;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.mapping.SqlCommandType;
@@ -72,8 +71,8 @@ public class OptimisticLockerInterceptor implements Interceptor {
             return invocation.proceed();
         }
         Object param = args[1];
-        if (param instanceof MapperMethod.ParamMap) {
-            MapperMethod.ParamMap map = (MapperMethod.ParamMap) param;
+        if (param instanceof HashMap) {
+            HashMap map = (HashMap) param;
             Wrapper ew = null;
             if (map.containsKey(NAME_ENTITY_WRAPPER)) {//mapper.update(updEntity, EntityWrapper<>(whereEntity);
                 ew = (Wrapper) map.get(NAME_ENTITY_WRAPPER);

+ 59 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/H2ARTest.java

@@ -0,0 +1,59 @@
+package com.baomidou.mybatisplus.test.h2;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.UUID;
+
+import javax.sql.DataSource;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.baomidou.mybatisplus.test.h2.base.AbstractH2UserTest;
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserIntVersionAR;
+
+/**
+ * <p>
+ * AR测试
+ * </p>
+ *
+ * @author yuxiaobin
+ * @date 2018/3/15
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:h2/spring-test-h2.xml"})
+public class H2ARTest extends AbstractH2UserTest {
+
+    @BeforeClass
+    public static void initDB() throws SQLException, IOException {
+        @SuppressWarnings("resource")
+        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:h2/spring-test-h2.xml");
+        DataSource ds = (DataSource) context.getBean("dataSource");
+        try (Connection conn = ds.getConnection()) {
+            initData(conn);
+        }
+    }
+
+    @Test
+    public void testAROptimisticLock() {
+        H2UserIntVersionAR user = new H2UserIntVersionAR();
+        user = user.selectById(105);
+        System.out.println(user);
+        Assert.assertNotNull(user);
+        int version = user.getVersion();
+        String updateName = UUID.randomUUID().toString().substring(0, 20);
+        user.setName(updateName);
+        user.updateById();
+        user = user.selectById();
+        Assert.assertEquals("name shoud be updated", updateName, user.getName());
+        Assert.assertEquals("version shoud be updated", version + 1, user.getVersion().intValue());
+    }
+
+}

+ 15 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/mapper/H2UserIntVersionARMapper.java

@@ -0,0 +1,15 @@
+package com.baomidou.mybatisplus.test.h2.entity.mapper;
+
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2UserIntVersionAR;
+
+/**
+ * <p>
+ * 这里继承自定义父类 SuperMapper
+ * </p>
+ *
+ * @author Caratacus
+ * @date 2017/4/1
+ */
+public interface H2UserIntVersionARMapper extends SuperMapper<H2UserIntVersionAR> {
+
+}

+ 117 - 0
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/test/h2/entity/persistent/H2UserIntVersionAR.java

@@ -0,0 +1,117 @@
+/**
+ * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * <p>
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.baomidou.mybatisplus.test.h2.entity.persistent;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.activerecord.Model;
+import com.baomidou.mybatisplus.annotations.TableField;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableName;
+import com.baomidou.mybatisplus.annotations.Version;
+import com.baomidou.mybatisplus.enums.FieldFill;
+import com.baomidou.mybatisplus.enums.FieldStrategy;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 测试用户类
+ * </p>
+ *
+ * @author hubin sjy
+ */
+/* 表名 value 注解【 驼峰命名可无 】, resultMap 注解测试【 映射 xml 的 resultMap 内容 】 */
+@Data
+@Accessors(chain = true)
+@TableName("h2user")
+public class H2UserIntVersionAR extends Model<H2UserIntVersionAR> {
+
+    @TableId(value = "test_id")
+    private Long id;
+
+    @TableField(value = "last_updated_dt", fill = FieldFill.UPDATE)
+    private Date lastUpdatedDt;
+
+    /* 测试忽略验证 */
+    private String name;
+
+    private Integer age;
+
+    /*BigDecimal 测试*/
+    private BigDecimal price;
+
+    /* 测试下划线字段命名类型, 字段填充 */
+    @TableField(value = "test_type", strategy = FieldStrategy.IGNORED)
+    private Integer testType;
+
+    private String desc;
+
+    @TableField
+	private Date testDate;
+
+    @Version
+    private Integer version;
+
+
+    public H2UserIntVersionAR() {
+
+    }
+
+    public H2UserIntVersionAR(String name) {
+        this.name = name;
+    }
+
+    public H2UserIntVersionAR(Integer testType) {
+        this.testType = testType;
+    }
+
+    public H2UserIntVersionAR(String name, Integer age) {
+        this.name = name;
+        this.age = age;
+    }
+
+    public H2UserIntVersionAR(Long id, String name) {
+        this.setId(id);
+        this.name = name;
+    }
+
+    public H2UserIntVersionAR(Long id, Integer age) {
+        this.setId(id);
+        this.age = age;
+    }
+
+    public H2UserIntVersionAR(Long id, String name, Integer age, Integer testType) {
+        this.setId(id);
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+    public H2UserIntVersionAR(String name, Integer age, Integer testType) {
+        this.name = name;
+        this.age = age;
+        this.testType = testType;
+    }
+
+    @Override
+    protected Serializable pkVal() {
+        return id;
+    }
+}