mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.map.Dict;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.func.Func0;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.map.Dict;
|
||||
import cn.hutool.core.reflect.ReflectUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.db.sql.SqlUtil;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
@@ -154,8 +154,8 @@ public class Entity extends Dict {
|
||||
* @return 自身
|
||||
*/
|
||||
public Entity setFieldNames(Collection<String> fieldNames) {
|
||||
if (CollectionUtil.isNotEmpty(fieldNames)) {
|
||||
this.fieldNames = CollectionUtil.newHashSet(true, fieldNames);
|
||||
if (CollUtil.isNotEmpty(fieldNames)) {
|
||||
this.fieldNames = CollUtil.newHashSet(true, fieldNames);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -168,7 +168,7 @@ public class Entity extends Dict {
|
||||
*/
|
||||
public Entity setFieldNames(String... fieldNames) {
|
||||
if (ArrayUtil.isNotEmpty(fieldNames)) {
|
||||
this.fieldNames = CollectionUtil.newLinkedHashSet(fieldNames);
|
||||
this.fieldNames = CollUtil.newLinkedHashSet(fieldNames);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.collection.ArrayIter;
|
||||
import cn.hutool.core.collection.iter.ArrayIter;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package cn.hutool.db.ds.pooled;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.db.DbRuntimeException;
|
||||
import cn.hutool.db.ds.simple.AbstractDataSource;
|
||||
|
||||
@@ -146,7 +146,7 @@ public class PooledDataSource extends AbstractDataSource {
|
||||
|
||||
@Override
|
||||
synchronized public void close() {
|
||||
if (CollectionUtil.isNotEmpty(this.freePool)) {
|
||||
if (CollUtil.isNotEmpty(this.freePool)) {
|
||||
this.freePool.forEach(PooledConnection::release);
|
||||
this.freePool.clear();
|
||||
this.freePool = null;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.db.DbRuntimeException;
|
||||
import cn.hutool.db.Entity;
|
||||
@@ -12,7 +12,7 @@ import java.util.Collection;
|
||||
* 查询对象,用于传递查询所需的字段值<br>
|
||||
* 查询对象根据表名(可以多个),多个条件 {@link Condition} 构建查询对象完成查询。<br>
|
||||
* 如果想自定义返回结果,则可在查询对象中自定义要查询的字段名,分页{@link Page}信息来自定义结果。
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
@@ -40,7 +40,7 @@ public class Query {
|
||||
// --------------------------------------------------------------- Constructor start
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param tableNames 表名
|
||||
*/
|
||||
public Query(String... tableNames) {
|
||||
@@ -50,7 +50,7 @@ public class Query {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param where 条件语句
|
||||
* @param tableNames 表名
|
||||
*/
|
||||
@@ -60,7 +60,7 @@ public class Query {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param where 条件语句
|
||||
* @param page 分页
|
||||
* @param tableNames 表名
|
||||
@@ -71,7 +71,7 @@ public class Query {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param fields 字段
|
||||
* @param tableNames 表名
|
||||
* @param where 条件
|
||||
@@ -88,7 +88,7 @@ public class Query {
|
||||
// --------------------------------------------------------------- Getters and Setters start
|
||||
/**
|
||||
* 获得查询的字段名列表
|
||||
*
|
||||
*
|
||||
* @return 查询的字段名列表
|
||||
*/
|
||||
public Collection<String> getFields() {
|
||||
@@ -97,7 +97,7 @@ public class Query {
|
||||
|
||||
/**
|
||||
* 设置查询的字段名列表
|
||||
*
|
||||
*
|
||||
* @param fields 查询的字段名列表
|
||||
* @return this
|
||||
*/
|
||||
@@ -108,18 +108,18 @@ public class Query {
|
||||
|
||||
/**
|
||||
* 设置查询的字段名列表
|
||||
*
|
||||
*
|
||||
* @param fields 查询的字段名列表
|
||||
* @return this
|
||||
*/
|
||||
public Query setFields(String... fields) {
|
||||
this.fields = CollectionUtil.newArrayList(fields);
|
||||
this.fields = CollUtil.newArrayList(fields);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得表名数组
|
||||
*
|
||||
*
|
||||
* @return 表名数组
|
||||
*/
|
||||
public String[] getTableNames() {
|
||||
@@ -128,7 +128,7 @@ public class Query {
|
||||
|
||||
/**
|
||||
* 设置表名
|
||||
*
|
||||
*
|
||||
* @param tableNames 表名
|
||||
* @return this
|
||||
*/
|
||||
@@ -139,7 +139,7 @@ public class Query {
|
||||
|
||||
/**
|
||||
* 获得条件语句
|
||||
*
|
||||
*
|
||||
* @return 条件语句
|
||||
*/
|
||||
public Condition[] getWhere() {
|
||||
@@ -148,7 +148,7 @@ public class Query {
|
||||
|
||||
/**
|
||||
* 设置条件语句
|
||||
*
|
||||
*
|
||||
* @param where 条件语句
|
||||
* @return this
|
||||
*/
|
||||
@@ -159,7 +159,7 @@ public class Query {
|
||||
|
||||
/**
|
||||
* 获得分页对象,无分页返回{@code null}
|
||||
*
|
||||
*
|
||||
* @return 分页对象 or {@code null}
|
||||
*/
|
||||
public Page getPage() {
|
||||
@@ -168,7 +168,7 @@ public class Query {
|
||||
|
||||
/**
|
||||
* 设置分页对象
|
||||
*
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @return this
|
||||
*/
|
||||
@@ -180,7 +180,7 @@ public class Query {
|
||||
|
||||
/**
|
||||
* 获得第一个表名
|
||||
*
|
||||
*
|
||||
* @return 表名
|
||||
* @throws DbRuntimeException 没有表
|
||||
*/
|
||||
|
@@ -1,9 +1,9 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import cn.hutool.core.builder.Builder;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.db.DbRuntimeException;
|
||||
import cn.hutool.db.Entity;
|
||||
import cn.hutool.db.dialect.DialectName;
|
||||
@@ -277,14 +277,14 @@ public class SqlBuilder implements Builder<String> {
|
||||
sql.append("DISTINCT ");
|
||||
}
|
||||
|
||||
if (CollectionUtil.isEmpty(fields)) {
|
||||
if (CollUtil.isEmpty(fields)) {
|
||||
sql.append("*");
|
||||
} else {
|
||||
if (null != wrapper) {
|
||||
// 包装字段名
|
||||
fields = wrapper.wrap(fields);
|
||||
}
|
||||
sql.append(CollectionUtil.join(fields, StrUtil.COMMA));
|
||||
sql.append(CollUtil.join(fields, StrUtil.COMMA));
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import cn.hutool.core.collection.ArrayIter;
|
||||
import cn.hutool.core.collection.iter.ArrayIter;
|
||||
import cn.hutool.core.lang.func.Func1;
|
||||
import cn.hutool.db.DbUtil;
|
||||
import cn.hutool.db.StatementUtil;
|
||||
|
@@ -1,10 +1,9 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.db.Entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -114,7 +113,7 @@ public class Wrapper implements Serializable {
|
||||
//对于Oracle这类数据库,表名中包含用户名需要单独拆分包装
|
||||
if (field.contains(StrUtil.DOT)) {
|
||||
final Collection<String> target = CollUtil.edit(StrUtil.split(field, CharUtil.DOT, 2), t -> StrUtil.format("{}{}{}", preWrapQuote, t, sufWrapQuote));
|
||||
return CollectionUtil.join(target, StrUtil.DOT);
|
||||
return CollUtil.join(target, StrUtil.DOT);
|
||||
}
|
||||
|
||||
return StrUtil.format("{}{}{}", preWrapQuote, field, sufWrapQuote);
|
||||
@@ -148,7 +147,7 @@ public class Wrapper implements Serializable {
|
||||
* @return 包装后的字段名
|
||||
*/
|
||||
public Collection<String> wrap(Collection<String> fields) {
|
||||
if (CollectionUtil.isEmpty(fields)) {
|
||||
if (CollUtil.isEmpty(fields)) {
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.db.handler.EntityListHandler;
|
||||
@@ -33,7 +33,7 @@ public class ConcurentTest {
|
||||
ThreadUtil.execute(() -> {
|
||||
List<Entity> find;
|
||||
try {
|
||||
find = db.find(CollectionUtil.newArrayList("name AS name2"), Entity.create("user"), new EntityListHandler());
|
||||
find = db.find(CollUtil.newArrayList("name AS name2"), Entity.create("user"), new EntityListHandler());
|
||||
} catch (SQLException e) {
|
||||
throw new DbRuntimeException(e);
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.db.meta;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.db.ds.DSFactory;
|
||||
import org.junit.Assert;
|
||||
@@ -27,7 +27,7 @@ public class MetaUtilTest {
|
||||
@Test
|
||||
public void getTableMetaTest() {
|
||||
Table table = MetaUtil.getTableMeta(ds, "user");
|
||||
Assert.assertEquals(CollectionUtil.newHashSet("id"), table.getPkNames());
|
||||
Assert.assertEquals(CollUtil.newHashSet("id"), table.getPkNames());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user