mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -582,7 +582,7 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public <T> List<T> find(final Entity where, final Class<T> beanClass) throws DbRuntimeException {
|
||||
return find(where.getFieldNames(), where, BeanListHandler.create(beanClass));
|
||||
return find(where.getFieldNames(), where, BeanListHandler.of(beanClass));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -594,7 +594,7 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
||||
* @throws DbRuntimeException SQL执行异常
|
||||
*/
|
||||
public List<Entity> findAll(final Entity where) throws DbRuntimeException {
|
||||
return find(where, EntityListHandler.create());
|
||||
return find(where, EntityListHandler.of());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -609,7 +609,7 @@ public abstract class AbstractDb<R extends AbstractDb<R>> extends DefaultConnect
|
||||
* @since 3.2.2
|
||||
*/
|
||||
public <T> List<T> findAll(final Entity where, final Class<T> beanClass) throws DbRuntimeException {
|
||||
return find(where, BeanListHandler.create(beanClass));
|
||||
return find(where, BeanListHandler.of(beanClass));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -23,7 +23,7 @@ public class ActiveEntity extends Entity {
|
||||
*
|
||||
* @return ActiveEntity
|
||||
*/
|
||||
public static ActiveEntity create() {
|
||||
public static ActiveEntity of() {
|
||||
return new ActiveEntity();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ActiveEntity extends Entity {
|
||||
* @param tableName 表名
|
||||
* @return ActiveEntity
|
||||
*/
|
||||
public static ActiveEntity create(final String tableName) {
|
||||
public static ActiveEntity of(final String tableName) {
|
||||
return new ActiveEntity(tableName);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ActiveEntity extends Entity {
|
||||
* @return ActiveEntity
|
||||
*/
|
||||
public static <T> ActiveEntity parse(final T bean) {
|
||||
return create(null).parseBean(bean);
|
||||
return of(null).parseBean(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ public class ActiveEntity extends Entity {
|
||||
* @return ActiveEntity
|
||||
*/
|
||||
public static <T> ActiveEntity parse(final T bean, final boolean isToUnderlineCase, final boolean ignoreNullValue) {
|
||||
return create(null).parseBean(bean, isToUnderlineCase, ignoreNullValue);
|
||||
return of(null).parseBean(bean, isToUnderlineCase, ignoreNullValue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ public class ActiveEntity extends Entity {
|
||||
* @return ActiveEntity
|
||||
*/
|
||||
public static <T> ActiveEntity parseWithUnderlineCase(final T bean) {
|
||||
return create(null).parseBean(bean, true, true);
|
||||
return of(null).parseBean(bean, true, true);
|
||||
}
|
||||
// --------------------------------------------------------------- Static method end
|
||||
|
||||
|
@@ -133,7 +133,7 @@ public interface Dialect extends Serializable {
|
||||
* @throws SQLException SQL执行异常
|
||||
*/
|
||||
default PreparedStatement psForCount(final Connection conn, final Query query) throws SQLException {
|
||||
return psForCount(conn, SqlBuilder.create().query(query));
|
||||
return psForCount(conn, SqlBuilder.of().query(query));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -43,7 +43,7 @@ public class AnsiSqlDialect implements Dialect {
|
||||
|
||||
@Override
|
||||
public PreparedStatement psForInsert(final Connection conn, final Entity entity) throws SQLException {
|
||||
final SqlBuilder insert = SqlBuilder.create(wrapper).insert(entity, this.dialectName());
|
||||
final SqlBuilder insert = SqlBuilder.of(wrapper).insert(entity, this.dialectName());
|
||||
|
||||
return StatementUtil.prepareStatement(conn, insert);
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class AnsiSqlDialect implements Dialect {
|
||||
throw new DbRuntimeException("Entities for batch insert is empty !");
|
||||
}
|
||||
// 批量,根据第一行数据结构生成SQL占位符
|
||||
final SqlBuilder insert = SqlBuilder.create(wrapper).insert(entities[0], this.dialectName());
|
||||
final SqlBuilder insert = SqlBuilder.of(wrapper).insert(entities[0], this.dialectName());
|
||||
final Set<String> fields = CollUtil.filter(entities[0].keySet(), StrUtil::isNotBlank);
|
||||
return StatementUtil.prepareStatementForBatch(conn, insert.build(), fields, entities);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class AnsiSqlDialect implements Dialect {
|
||||
// 对于无条件的删除语句直接抛出异常禁止,防止误删除
|
||||
throw new SQLException("No 'WHERE' condition, we can't prepared statement for delete everything.");
|
||||
}
|
||||
final SqlBuilder delete = SqlBuilder.create(wrapper).delete(query.getFirstTableName()).where(where);
|
||||
final SqlBuilder delete = SqlBuilder.of(wrapper).delete(query.getFirstTableName()).where(where);
|
||||
|
||||
return StatementUtil.prepareStatement(conn, delete);
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class AnsiSqlDialect implements Dialect {
|
||||
throw new SQLException("No 'WHERE' condition, we can't prepare statement for update everything.");
|
||||
}
|
||||
|
||||
final SqlBuilder update = SqlBuilder.create(wrapper).update(entity).where(where);
|
||||
final SqlBuilder update = SqlBuilder.of(wrapper).update(entity).where(where);
|
||||
|
||||
return StatementUtil.prepareStatement(conn, update);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class AnsiSqlDialect implements Dialect {
|
||||
throw new DbRuntimeException("Table name must be not empty !");
|
||||
}
|
||||
|
||||
final SqlBuilder find = SqlBuilder.create(wrapper).query(query);
|
||||
final SqlBuilder find = SqlBuilder.of(wrapper).query(query);
|
||||
return psForPage(conn, find, query.getPage());
|
||||
}
|
||||
|
||||
|
@@ -40,7 +40,7 @@ public class H2Dialect extends AnsiSqlDialect {
|
||||
public PreparedStatement psForUpsert(final Connection conn, final Entity entity, final String... keys) throws SQLException {
|
||||
Assert.notEmpty(keys, "Keys must be not empty for H2 MERGE SQL.");
|
||||
SqlBuilder.validateEntity(entity);
|
||||
final SqlBuilder builder = SqlBuilder.create(wrapper);
|
||||
final SqlBuilder builder = SqlBuilder.of(wrapper);
|
||||
|
||||
final StringBuilder fieldsPart = new StringBuilder();
|
||||
final StringBuilder placeHolder = new StringBuilder();
|
||||
|
@@ -51,7 +51,7 @@ public class MysqlDialect extends AnsiSqlDialect{
|
||||
@Override
|
||||
public PreparedStatement psForUpsert(final Connection conn, final Entity entity, final String... keys) throws SQLException {
|
||||
SqlBuilder.validateEntity(entity);
|
||||
final SqlBuilder builder = SqlBuilder.create(wrapper);
|
||||
final SqlBuilder builder = SqlBuilder.of(wrapper);
|
||||
|
||||
final StringBuilder fieldsPart = new StringBuilder();
|
||||
final StringBuilder placeHolder = new StringBuilder();
|
||||
|
@@ -35,7 +35,7 @@ public class PostgresqlDialect extends AnsiSqlDialect{
|
||||
public PreparedStatement psForUpsert(final Connection conn, final Entity entity, final String... keys) throws SQLException {
|
||||
Assert.notEmpty(keys, "Keys must be not empty for Postgres.");
|
||||
SqlBuilder.validateEntity(entity);
|
||||
final SqlBuilder builder = SqlBuilder.create(wrapper);
|
||||
final SqlBuilder builder = SqlBuilder.of(wrapper);
|
||||
|
||||
final StringBuilder fieldsPart = new StringBuilder();
|
||||
final StringBuilder placeHolder = new StringBuilder();
|
||||
|
@@ -136,7 +136,7 @@ public abstract class DSFactory implements Closeable, Serializable{
|
||||
* @param setting 数据库配置项
|
||||
* @return 日志实现类
|
||||
*/
|
||||
public static DSFactory create(final Setting setting) {
|
||||
public static DSFactory of(final Setting setting) {
|
||||
final DSFactory dsFactory = doCreate(setting);
|
||||
log.debug("Use [{}] DataSource As Default", dsFactory.dataSourceName);
|
||||
return dsFactory;
|
||||
|
@@ -42,7 +42,7 @@ public class GlobalDSFactory {
|
||||
if (null == factory) {
|
||||
synchronized (lock) {
|
||||
if (null == factory) {
|
||||
factory = DSFactory.create(null);
|
||||
factory = DSFactory.of(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ public class BeanHandler<E> implements RsHandler<E>{
|
||||
* @param beanType Bean类型
|
||||
* @return BeanHandler对象
|
||||
*/
|
||||
public static <E> BeanHandler<E> create(final Class<E> beanType) {
|
||||
public static <E> BeanHandler<E> of(final Class<E> beanType) {
|
||||
return new BeanHandler<>(beanType);
|
||||
}
|
||||
|
||||
|
@@ -24,7 +24,7 @@ public class BeanListHandler<E> implements RsHandler<List<E>> {
|
||||
* @param beanType Bean类型
|
||||
* @return BeanListHandler对象
|
||||
*/
|
||||
public static <E> BeanListHandler<E> create(final Class<E> beanType) {
|
||||
public static <E> BeanListHandler<E> of(final Class<E> beanType) {
|
||||
return new BeanListHandler<>(beanType);
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ public class EntityHandler implements RsHandler<Entity>{
|
||||
* 创建一个 EntityHandler对象
|
||||
* @return EntityHandler对象
|
||||
*/
|
||||
public static EntityHandler create() {
|
||||
public static EntityHandler of() {
|
||||
return new EntityHandler();
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ public class EntityListHandler implements RsHandler<List<Entity>>{
|
||||
* 创建一个 EntityListHandler对象
|
||||
* @return EntityListHandler对象
|
||||
*/
|
||||
public static EntityListHandler create() {
|
||||
public static EntityListHandler of() {
|
||||
return new EntityListHandler();
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,7 @@ public class EntitySetHandler implements RsHandler<LinkedHashSet<Entity>>{
|
||||
* 创建一个 EntityHandler对象
|
||||
* @return EntityHandler对象
|
||||
*/
|
||||
public static EntitySetHandler create() {
|
||||
public static EntitySetHandler of() {
|
||||
return new EntitySetHandler();
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,7 @@ public class NumberHandler implements RsHandler<Number>{
|
||||
* 创建一个 NumberHandler对象
|
||||
* @return NumberHandler对象
|
||||
*/
|
||||
public static NumberHandler create() {
|
||||
public static NumberHandler of() {
|
||||
return new NumberHandler();
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,7 @@ public class PageResultHandler implements RsHandler<PageResult<Entity>> {
|
||||
* @param pageResult 分页结果集空对象
|
||||
* @return EntityHandler对象
|
||||
*/
|
||||
public static PageResultHandler create(final PageResult<Entity> pageResult) {
|
||||
public static PageResultHandler of(final PageResult<Entity> pageResult) {
|
||||
return new PageResultHandler(pageResult);
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,7 @@ public class StringHandler implements RsHandler<String>{
|
||||
* 创建一个 NumberHandler对象
|
||||
* @return NumberHandler对象
|
||||
*/
|
||||
public static StringHandler create() {
|
||||
public static StringHandler of() {
|
||||
return new StringHandler();
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,7 @@ public class ValueListHandler implements RsHandler<List<List<Object>>>{
|
||||
* 创建一个 EntityListHandler对象
|
||||
* @return EntityListHandler对象
|
||||
*/
|
||||
public static ValueListHandler create() {
|
||||
public static ValueListHandler of() {
|
||||
return new ValueListHandler();
|
||||
}
|
||||
|
||||
|
@@ -70,7 +70,7 @@ public class Column implements Serializable, Cloneable {
|
||||
* @return 列对象
|
||||
* @since 5.4.3
|
||||
*/
|
||||
public static Column create(final Table table, final ResultSet columnMetaRs) {
|
||||
public static Column of(final Table table, final ResultSet columnMetaRs) {
|
||||
return new Column(table, columnMetaRs);
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,7 @@ public class ColumnIndexInfo implements Serializable, Cloneable {
|
||||
* @param rs 结果集,通过DatabaseMetaData#getIndexInfo获取
|
||||
* @return ColumnIndexInfo
|
||||
*/
|
||||
public static ColumnIndexInfo create(final ResultSet rs) {
|
||||
public static ColumnIndexInfo of(final ResultSet rs) {
|
||||
try {
|
||||
return new ColumnIndexInfo(
|
||||
rs.getString("COLUMN_NAME"),
|
||||
|
@@ -207,7 +207,7 @@ public class MetaUtil {
|
||||
* @since 5.7.22
|
||||
*/
|
||||
public static Table getTableMeta(final DataSource ds, String catalog, String schema, final String tableName) {
|
||||
final Table table = Table.create(tableName);
|
||||
final Table table = Table.of(tableName);
|
||||
Connection conn = null;
|
||||
try {
|
||||
conn = ds.getConnection();
|
||||
@@ -246,7 +246,7 @@ public class MetaUtil {
|
||||
try (final ResultSet rs = metaData.getColumns(catalog, schema, tableName, null)) {
|
||||
if (null != rs) {
|
||||
while (rs.next()) {
|
||||
table.setColumn(Column.create(table, rs));
|
||||
table.setColumn(Column.of(table, rs));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,7 +269,7 @@ public class MetaUtil {
|
||||
indexInfo = new IndexInfo(rs.getBoolean("NON_UNIQUE"), indexName, tableName, schema, catalog);
|
||||
indexInfoMap.put(key, indexInfo);
|
||||
}
|
||||
indexInfo.getColumnIndexInfoList().add(ColumnIndexInfo.create(rs));
|
||||
indexInfo.getColumnIndexInfoList().add(ColumnIndexInfo.of(rs));
|
||||
}
|
||||
}
|
||||
table.setIndexInfoList(ListUtil.of(indexInfoMap.values()));
|
||||
|
@@ -45,7 +45,7 @@ public class Table implements Serializable, Cloneable {
|
||||
*/
|
||||
private final Map<String, Column> columns = new LinkedHashMap<>();
|
||||
|
||||
public static Table create(final String tableName) {
|
||||
public static Table of(final String tableName) {
|
||||
return new Table(tableName);
|
||||
}
|
||||
|
||||
|
@@ -32,7 +32,7 @@ public class SqlBuilder implements Builder<String> {
|
||||
*
|
||||
* @return SQL构建器
|
||||
*/
|
||||
public static SqlBuilder create() {
|
||||
public static SqlBuilder of() {
|
||||
return new SqlBuilder();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class SqlBuilder implements Builder<String> {
|
||||
* @param wrapper 包装器
|
||||
* @return SQL构建器
|
||||
*/
|
||||
public static SqlBuilder create(final Wrapper wrapper) {
|
||||
public static SqlBuilder of(final Wrapper wrapper) {
|
||||
return new SqlBuilder(wrapper);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class SqlBuilder implements Builder<String> {
|
||||
* @since 5.5.3
|
||||
*/
|
||||
public static SqlBuilder of(final CharSequence sql) {
|
||||
return create().append(sql);
|
||||
return of().append(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -23,9 +23,9 @@ public class OracleTest {
|
||||
final Query query = new Query(SqlUtil.buildConditions(where), where.getTableName());
|
||||
query.setPage(page);
|
||||
|
||||
final SqlBuilder find = SqlBuilder.create(null).query(query).orderBy(page.getOrders());
|
||||
final SqlBuilder find = SqlBuilder.of(null).query(query).orderBy(page.getOrders());
|
||||
final int[] startEnd = page.getStartEnd();
|
||||
final SqlBuilder builder = SqlBuilder.create(null).append("SELECT * FROM ( SELECT row_.*, rownum rownum_ from ( ")//
|
||||
final SqlBuilder builder = SqlBuilder.of(null).append("SELECT * FROM ( SELECT row_.*, rownum rownum_ from ( ")//
|
||||
.append(find)//
|
||||
.append(" ) row_ where rownum <= ").append(startEnd[1])//
|
||||
.append(") table_alias")//
|
||||
|
@@ -7,22 +7,22 @@ public class SqlBuilderTest {
|
||||
|
||||
@Test
|
||||
public void queryNullTest() {
|
||||
final SqlBuilder builder = SqlBuilder.create().select().from("user").where(new Condition("name", "= null"));
|
||||
final SqlBuilder builder = SqlBuilder.of().select().from("user").where(new Condition("name", "= null"));
|
||||
Assert.assertEquals("SELECT * FROM user WHERE name IS NULL", builder.build());
|
||||
|
||||
final SqlBuilder builder2 = SqlBuilder.create().select().from("user").where(new Condition("name", "is null"));
|
||||
final SqlBuilder builder2 = SqlBuilder.of().select().from("user").where(new Condition("name", "is null"));
|
||||
Assert.assertEquals("SELECT * FROM user WHERE name IS NULL", builder2.build());
|
||||
|
||||
final SqlBuilder builder3 = SqlBuilder.create().select().from("user").where(new Condition("name", "!= null"));
|
||||
final SqlBuilder builder3 = SqlBuilder.of().select().from("user").where(new Condition("name", "!= null"));
|
||||
Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder3.build());
|
||||
|
||||
final SqlBuilder builder4 = SqlBuilder.create().select().from("user").where(new Condition("name", "is not null"));
|
||||
final SqlBuilder builder4 = SqlBuilder.of().select().from("user").where(new Condition("name", "is not null"));
|
||||
Assert.assertEquals("SELECT * FROM user WHERE name IS NOT NULL", builder4.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void orderByTest() {
|
||||
final SqlBuilder builder = SqlBuilder.create().select("id", "username").from("user")
|
||||
final SqlBuilder builder = SqlBuilder.of().select("id", "username").from("user")
|
||||
.join("role", SqlBuilder.Join.INNER)
|
||||
.on("user.id = role.user_id")
|
||||
.where(new Condition("age", ">=", 18),
|
||||
|
Reference in New Issue
Block a user