This commit is contained in:
Looly
2022-05-26 12:03:20 +08:00
parent d368b76586
commit b404b11b0b
26 changed files with 103 additions and 140 deletions

View File

@@ -417,7 +417,7 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
* @throws DbRuntimeException SQL执行异常
*/
public int del(final String tableName, final String field, final Object value) throws DbRuntimeException {
return del(Entity.create(tableName).set(field, value));
return del(Entity.of(tableName).set(field, value));
}
/**
@@ -470,7 +470,7 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
* @throws DbRuntimeException SQL执行异常
*/
public <T> Entity get(final String tableName, final String field, final T value) throws DbRuntimeException {
return this.get(Entity.create(tableName).set(field, value));
return this.get(Entity.of(tableName).set(field, value));
}
/**
@@ -620,7 +620,7 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
* @throws DbRuntimeException SQL执行异常
*/
public List<Entity> findAll(final String tableName) throws DbRuntimeException {
return findAll(Entity.create(tableName));
return findAll(Entity.of(tableName));
}
/**
@@ -633,7 +633,7 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
* @throws DbRuntimeException SQL执行异常
*/
public List<Entity> findBy(final String tableName, final String field, final Object value) throws DbRuntimeException {
return findAll(Entity.create(tableName).set(field, value));
return findAll(Entity.of(tableName).set(field, value));
}
/**
@@ -661,7 +661,7 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
* @throws DbRuntimeException SQL执行异常
*/
public List<Entity> findLike(final String tableName, final String field, final String value, final LikeType likeType) throws DbRuntimeException {
return findAll(Entity.create(tableName).set(field, SqlUtil.buildLikeValue(value, likeType, true)));
return findAll(Entity.of(tableName).set(field, SqlUtil.buildLikeValue(value, likeType, true)));
}
/**

View File

@@ -219,7 +219,7 @@ public class ActiveEntity extends Entity {
* @return this
*/
public ActiveEntity update(final String primaryKey) {
db.update(this, Entity.create().set(primaryKey, this.get(primaryKey)));
db.update(this, Entity.of().set(primaryKey, this.get(primaryKey)));
return this;
}
// -------------------------------------------------------------------------- CRUD end

View File

@@ -139,7 +139,7 @@ public class DaoTemplate {
if (pk == null) {
return 0;
}
return this.del(Entity.create(tableName).set(primaryKeyField, pk));
return this.del(Entity.of(tableName).set(primaryKeyField, pk));
}
/**
@@ -156,7 +156,7 @@ public class DaoTemplate {
return 0;
}
return this.del(Entity.create(tableName).set(field, value));
return this.del(Entity.of(tableName).set(field, value));
}
/**
@@ -208,7 +208,7 @@ public class DaoTemplate {
throw new DbRuntimeException(StrUtil.format("Please determine `{}` for update", primaryKeyField));
}
final Entity where = Entity.create(tableName).set(primaryKeyField, pk);
final Entity where = Entity.of(tableName).set(primaryKeyField, pk);
final Entity record = entity.clone();
record.remove(primaryKeyField);
@@ -252,7 +252,7 @@ public class DaoTemplate {
* @throws DbRuntimeException SQL执行异常
*/
public <T> Entity get(final String field, final T value) throws DbRuntimeException {
return this.get(Entity.create(tableName).set(field, value));
return this.get(Entity.of(tableName).set(field, value));
}
/**
@@ -279,7 +279,7 @@ public class DaoTemplate {
* @throws DbRuntimeException SQL执行异常
*/
public <T> List<Entity> find(final String field, final T value) throws DbRuntimeException {
return this.find(Entity.create(tableName).set(field, value));
return this.find(Entity.of(tableName).set(field, value));
}
/**
@@ -289,7 +289,7 @@ public class DaoTemplate {
* @throws DbRuntimeException SQL执行异常
*/
public List<Entity> findAll() throws DbRuntimeException {
return this.find(Entity.create(tableName));
return this.find(Entity.of(tableName));
}
/**
@@ -377,7 +377,7 @@ public class DaoTemplate {
*/
private Entity fixEntity(Entity entity) {
if (null == entity) {
entity = Entity.create(tableName);
entity = Entity.of(tableName);
} else if (StrUtil.isBlank(entity.getTableName())) {
entity.setTableName(tableName);
}

View File

@@ -39,7 +39,7 @@ public class Entity extends Dict {
*
* @return Entity
*/
public static Entity create() {
public static Entity of() {
return new Entity();
}
@@ -49,7 +49,7 @@ public class Entity extends Dict {
* @param tableName 表名
* @return Entity
*/
public static Entity create(final String tableName) {
public static Entity of(final String tableName) {
return new Entity(tableName);
}
@@ -61,7 +61,7 @@ public class Entity extends Dict {
* @return Entity
*/
public static <T> Entity parse(final T bean) {
return create(null).parseBean(bean);
return of(null).parseBean(bean);
}
/**
@@ -74,7 +74,7 @@ public class Entity extends Dict {
* @return Entity
*/
public static <T> Entity parse(final T bean, final boolean isToUnderlineCase, final boolean ignoreNullValue) {
return create(null).parseBean(bean, isToUnderlineCase, ignoreNullValue);
return of(null).parseBean(bean, isToUnderlineCase, ignoreNullValue);
}
/**
@@ -85,7 +85,7 @@ public class Entity extends Dict {
* @return Entity
*/
public static <T> Entity parseWithUnderlineCase(final T bean) {
return create(null).parseBean(bean, true, true);
return of(null).parseBean(bean, true, true);
}
// --------------------------------------------------------------- Static method end

View File

@@ -1,6 +1,5 @@
package cn.hutool.db.dialect;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.sql.Order;
@@ -134,7 +133,7 @@ public interface Dialect extends Serializable {
* @throws SQLException SQL执行异常
*/
default PreparedStatement psForCount(final Connection conn, final Query query) throws SQLException {
return psForFind(conn, query.clone().setFields(ListUtil.of("count(1)")));
return psForCount(conn, SqlBuilder.create().query(query));
}
/**

View File

@@ -172,7 +172,7 @@ public class MetaUtil {
*/
public static Entity createLimitedEntity(final DataSource ds, final String tableName) {
final String[] columnNames = getColumnNames(ds, tableName);
return Entity.create(tableName).setFieldNames(columnNames);
return Entity.of(tableName).setFieldNames(columnNames);
}
/**