移动类的位置。
parent
fa3f4695f1
commit
c8e61a2a82
|
@ -1,4 +1,4 @@
|
||||||
package xyz.zhouxy.plusone.commons.util;
|
package xyz.zhouxy.plusone.commons.jdbc;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -15,6 +15,10 @@ import java.util.Set;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
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
|
@Beta
|
||||||
public class DbRecord extends AbstractMapWrapper<String, Object, DbRecord> {
|
public class DbRecord extends AbstractMapWrapper<String, Object, DbRecord> {
|
||||||
|
|
|
@ -19,7 +19,6 @@ import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
import com.google.common.annotations.Beta;
|
||||||
|
|
||||||
import xyz.zhouxy.plusone.commons.util.DbRecord;
|
|
||||||
import xyz.zhouxy.plusone.commons.util.MoreCollections;
|
import xyz.zhouxy.plusone.commons.util.MoreCollections;
|
||||||
|
|
||||||
@Beta
|
@Beta
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
package xyz.zhouxy.plusone.commons.util;
|
package xyz.zhouxy.plusone.commons.util;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
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 static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
@ -19,6 +16,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
|
||||||
|
import xyz.zhouxy.plusone.commons.jdbc.DbRecord;
|
||||||
import xyz.zhouxy.plusone.commons.jdbc.JdbcUtil;
|
import xyz.zhouxy.plusone.commons.jdbc.JdbcUtil;
|
||||||
|
|
||||||
class JdbcUtilTests {
|
class JdbcUtilTests {
|
||||||
|
@ -51,14 +49,10 @@ class JdbcUtilTests {
|
||||||
@Test
|
@Test
|
||||||
void testQuery() throws SQLException {
|
void testQuery() throws SQLException {
|
||||||
Connection conn = this.dataSource.getConnection();
|
Connection conn = this.dataSource.getConnection();
|
||||||
List<Map<String, Object>> ms = JdbcUtil.connect(conn).query(
|
List<DbRecord> rs = JdbcUtil.connect(conn).queryToRecordList(
|
||||||
"SELECT * FROM public.base_table WHERE id IN (?, ?, ?)", 501533, 501554, 544599);
|
"SELECT * FROM public.base_table WHERE id IN (?, ?, ?)", 501533, 501554, 544599);
|
||||||
assertNotNull(ms);
|
assertEquals(3, rs.size());
|
||||||
List<DbRecord> es = ms.stream()
|
for (DbRecord baseEntity : rs) {
|
||||||
.map(input -> new DbRecord().putAll(input))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
assertEquals(3, es.size());
|
|
||||||
for (DbRecord baseEntity : es) {
|
|
||||||
log.info("id: {}", baseEntity.getValueAsLong("id"));
|
log.info("id: {}", baseEntity.getValueAsLong("id"));
|
||||||
assertNull(baseEntity.getValueAsString("updated_by"));
|
assertNull(baseEntity.getValueAsString("updated_by"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue