fix batch

This commit is contained in:
Looly
2019-09-22 00:05:48 +08:00
parent c9f77e1746
commit 0e453b099a
8 changed files with 163 additions and 88 deletions

View File

@@ -1,29 +1,24 @@
package cn.hutool.db;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.db.handler.EntityListHandler;
import cn.hutool.db.pojo.User;
import cn.hutool.db.sql.Condition;
import cn.hutool.db.sql.Condition.LikeType;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.SQLException;
import java.util.List;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.db.ActiveEntity;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.handler.EntityListHandler;
import cn.hutool.db.pojo.User;
import cn.hutool.db.sql.Condition;
import cn.hutool.db.sql.Condition.LikeType;
/**
* 增删改查测试
*
* @author looly
*
* @author looly
*/
public class CRUDTest {
@@ -34,13 +29,13 @@ public class CRUDTest {
List<Entity> results = db.findAll(Entity.create("user").set("age", "is null"));
Assert.assertEquals(0, results.size());
}
@Test
public void findIsNullTest2() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("age", "= null"));
Assert.assertEquals(0, results.size());
}
@Test
public void findIsNullTest3() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("age", null));
@@ -52,13 +47,13 @@ public class CRUDTest {
List<Entity> results = db.findAll(Entity.create("user").set("age", "between '18' and '40'"));
Assert.assertEquals(1, results.size());
}
@Test
public void findByBigIntegerTest() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("age", new BigInteger("12")));
Assert.assertEquals(2, results.size());
}
@Test
public void findByBigDecimalTest() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("age", new BigDecimal("12")));
@@ -70,31 +65,31 @@ public class CRUDTest {
List<Entity> results = db.findAll(Entity.create("user").set("name", "like \"%三%\""));
Assert.assertEquals(2, results.size());
}
@Test
public void findLikeTest2() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("name", new Condition("name", "", LikeType.Contains)));
Assert.assertEquals(2, results.size());
}
@Test
public void findLikeTest3() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("name", new Condition("name", null, LikeType.Contains)));
Assert.assertEquals(0, results.size());
}
@Test
public void findInTest() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("id", "in 1,2,3"));
Assert.assertEquals(2, results.size());
}
@Test
public void findInTest2() throws SQLException {
List<Entity> results = db.findAll(Entity.create("user").set("id", new Condition("id", new long[] {1,2,3})));
List<Entity> results = db.findAll(Entity.create("user").set("id", new Condition("id", new long[]{1, 2, 3})));
Assert.assertEquals(2, results.size());
}
@Test
public void findAllTest() throws SQLException {
List<Entity> results = db.findAll("user");
@@ -106,19 +101,19 @@ public class CRUDTest {
List<Entity> find = db.find(CollUtil.newArrayList("name AS name2"), Entity.create("user"), new EntityListHandler());
Assert.assertFalse(find.isEmpty());
}
@Test
public void findActiveTest() throws SQLException {
public void findActiveTest() {
ActiveEntity entity = new ActiveEntity(db, "user");
entity.setFieldNames("name AS name2").load();
Assert.assertEquals("user", entity.getTableName());
Assert.assertFalse(entity.isEmpty());
}
/**
* 对增删改查做单元测试
*
* @throws SQLException
*
* @throws SQLException SQL异常
*/
@Test
@Ignore
@@ -159,6 +154,7 @@ public class CRUDTest {
user2.setGender(false);
Entity data1 = Entity.parse(user1);
data1.put("name", null);
Entity data2 = Entity.parse(user2);
Console.log(data1);