From c8e61a2a8272ea25cce26458672706a4bb29418c Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Tue, 9 May 2023 14:32:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=B1=BB=E7=9A=84=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/commons/{util => jdbc}/DbRecord.java | 6 +++++- .../xyz/zhouxy/plusone/commons/jdbc/JdbcUtil.java | 1 - .../zhouxy/plusone/commons/util/JdbcUtilTests.java | 14 ++++---------- 3 files changed, 9 insertions(+), 12 deletions(-) rename src/main/java/xyz/zhouxy/plusone/commons/{util => jdbc}/DbRecord.java (90%) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/DbRecord.java b/src/main/java/xyz/zhouxy/plusone/commons/jdbc/DbRecord.java similarity index 90% rename from src/main/java/xyz/zhouxy/plusone/commons/util/DbRecord.java rename to src/main/java/xyz/zhouxy/plusone/commons/jdbc/DbRecord.java index 9507546..62955ea 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/DbRecord.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/jdbc/DbRecord.java @@ -1,4 +1,4 @@ -package xyz.zhouxy.plusone.commons.util; +package xyz.zhouxy.plusone.commons.jdbc; import java.util.ArrayList; import java.util.Collection; @@ -15,6 +15,10 @@ import java.util.Set; import com.google.common.annotations.Beta; +import xyz.zhouxy.plusone.commons.util.AbstractMapWrapper; +import xyz.zhouxy.plusone.commons.util.Assert; +import xyz.zhouxy.plusone.commons.util.OptionalUtil; + @Beta public class DbRecord extends AbstractMapWrapper { diff --git a/src/main/java/xyz/zhouxy/plusone/commons/jdbc/JdbcUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/jdbc/JdbcUtil.java index 0eced64..2463c09 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/jdbc/JdbcUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/jdbc/JdbcUtil.java @@ -19,7 +19,6 @@ import org.apache.commons.lang3.ArrayUtils; import com.google.common.annotations.Beta; -import xyz.zhouxy.plusone.commons.util.DbRecord; import xyz.zhouxy.plusone.commons.util.MoreCollections; @Beta diff --git a/src/test/java/xyz/zhouxy/plusone/commons/util/JdbcUtilTests.java b/src/test/java/xyz/zhouxy/plusone/commons/util/JdbcUtilTests.java index f8862e0..fd733b1 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/util/JdbcUtilTests.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/util/JdbcUtilTests.java @@ -1,14 +1,11 @@ package xyz.zhouxy.plusone.commons.util; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import java.sql.Connection; import java.sql.SQLException; import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; import javax.sql.DataSource; @@ -19,6 +16,7 @@ import org.slf4j.LoggerFactory; import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; +import xyz.zhouxy.plusone.commons.jdbc.DbRecord; import xyz.zhouxy.plusone.commons.jdbc.JdbcUtil; class JdbcUtilTests { @@ -51,14 +49,10 @@ class JdbcUtilTests { @Test void testQuery() throws SQLException { Connection conn = this.dataSource.getConnection(); - List> ms = JdbcUtil.connect(conn).query( + List rs = JdbcUtil.connect(conn).queryToRecordList( "SELECT * FROM public.base_table WHERE id IN (?, ?, ?)", 501533, 501554, 544599); - assertNotNull(ms); - List es = ms.stream() - .map(input -> new DbRecord().putAll(input)) - .collect(Collectors.toList()); - assertEquals(3, es.size()); - for (DbRecord baseEntity : es) { + assertEquals(3, rs.size()); + for (DbRecord baseEntity : rs) { log.info("id: {}", baseEntity.getValueAsLong("id")); assertNull(baseEntity.getValueAsString("updated_by")); }