From 52c1d05b95a26c9652483f9b8be70d12862e1952 Mon Sep 17 00:00:00 2001 From: zhouhao Date: Tue, 28 May 2024 10:29:51 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hswebframework/ezorm/core/param/Term.java | 17 ++++++++++--- .../rdb/metadata/TableOrViewMetadata.java | 24 ++++++++++++++----- .../term/AbstractTermFragmentBuilder.java | 7 +++++- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/hsweb-easy-orm-core/src/main/java/org/hswebframework/ezorm/core/param/Term.java b/hsweb-easy-orm-core/src/main/java/org/hswebframework/ezorm/core/param/Term.java index 0cffd87d..646c730b 100644 --- a/hsweb-easy-orm-core/src/main/java/org/hswebframework/ezorm/core/param/Term.java +++ b/hsweb-easy-orm-core/src/main/java/org/hswebframework/ezorm/core/param/Term.java @@ -17,7 +17,7 @@ */ @Getter @Setter -public class Term implements Serializable,Cloneable { +public class Term implements Serializable, Cloneable { private static final long serialVersionUID = 1L; /** @@ -35,13 +35,13 @@ public class Term implements Serializable,Cloneable { /** * 链接类型 */ - @Schema(description = "多个条件关联类型",defaultValue = "and") + @Schema(description = "多个条件关联类型", defaultValue = "and") private Type type = Type.and; /** * 条件类型 */ - @Schema(description = "动态条件类型",defaultValue = "eq") + @Schema(description = "动态条件类型", defaultValue = "eq") private String termType = TermType.eq; /** @@ -59,6 +59,17 @@ public class Term implements Serializable,Cloneable { @Schema(description = "嵌套条件") private List terms = new LinkedList<>(); + public static Term of(String column, + String termType, + Object value, + String... options) { + Term term = new Term(); + term.setColumn(column); + term.setTermType(termType); + term.setValue(value); + term.getOptions().addAll(Arrays.asList(options)); + return term; + } public Term or(String term, Object value) { return or(term, TermType.eq, value); diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/TableOrViewMetadata.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/TableOrViewMetadata.java index 564c8731..d871f850 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/TableOrViewMetadata.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/TableOrViewMetadata.java @@ -51,7 +51,7 @@ public interface TableOrViewMetadata extends ObjectMetadata, FeatureSupportedMet List findColumns(); /** - * 获取当前表或者视图对列 + * 获取当前表或者视图的列 * * @param name 列名或者别名 * @return Optional @@ -60,6 +60,18 @@ public interface TableOrViewMetadata extends ObjectMetadata, FeatureSupportedMet */ Optional getColumn(String name); + /** + * 立即获取当前表或者视图的列,如果不存在则抛出异常: {@link IllegalStateException} + * + * @param name 列名称 + * @return RDBColumnMetadata + */ + default RDBColumnMetadata getColumnNow(String name) { + return getColumn(name) + .orElseThrow(() -> new IllegalStateException("column not found:" + name + " in " + getFullName())); + } + + /** * 查找列,可查找通过外键关联表对列或者其他表对列 * @@ -129,17 +141,17 @@ default void fireEvent(EventType eventType, Consumer contextConsum default String getFullName() { return StringUtils.concat( - getSchema().getName(), - ".", - getName() + getSchema().getName(), + ".", + getName() ); } default String getQuoteName() { return getDialect().quote(getSchema().getName(), false) - + "." - + getDialect().quote(getName(), false); + + "." + + getDialect().quote(getName(), false); } @Override diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java index 33f4d8c5..3748110c 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/operator/builder/fragments/term/AbstractTermFragmentBuilder.java @@ -1,5 +1,6 @@ package org.hswebframework.ezorm.rdb.operator.builder.fragments.term; +import com.google.common.collect.Lists; import lombok.AllArgsConstructor; import lombok.Getter; import org.hswebframework.ezorm.core.param.Term; @@ -54,8 +55,12 @@ protected List convertList(RDBColumnMetadata column, Term term) { //集合 if (value instanceof Collection) { Collection listValue = ((Collection) value); - List list = new ArrayList<>(listValue.size()); + if (listValue instanceof List) { + return Lists.transform(((List) listValue), (val) -> this.convertValue(column, val)); + } + + List list = new ArrayList<>(listValue.size()); for (Object val : listValue) { list.add(this.convertValue(column, val)); }