upsert 接口和h2方言的upsert完成并测试通过

This commit is contained in:
icefairy
2022-01-14 12:34:10 +08:00
parent c5673bb06b
commit 64d21372ec
7 changed files with 179 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
package cn.hutool.db;
import com.alibaba.druid.support.json.JSONUtils;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -9,14 +10,14 @@ import java.util.List;
/**
* H2数据库单元测试
*
*
* @author looly
*
*/
public class H2Test {
private static final String DS_GROUP_NAME = "h2";
@BeforeClass
public static void init() throws SQLException {
Db db = Db.use(DS_GROUP_NAME);
@@ -27,7 +28,7 @@ public class H2Test {
db.insert(Entity.create("test").set("a", 3).set("b", 31));
db.insert(Entity.create("test").set("a", 4).set("b", 41));
}
@Test
public void queryTest() throws SQLException {
List<Entity> query = Db.use(DS_GROUP_NAME).query("select * from test");
@@ -39,4 +40,11 @@ public class H2Test {
List<Entity> query = Db.use(DS_GROUP_NAME).find(Entity.create("test"));
Assert.assertEquals(4, query.size());
}
@Test
public void upsertTest() throws SQLException {
Db db=Db.use(DS_GROUP_NAME);
db.upsert(Entity.create("test").set("a",1).set("b",111),"a");
Entity a1=db.get("test","a",1);
Assert.assertEquals(Long.valueOf(111),a1.getLong("b"));
}
}