Skip to content

Commit

Permalink
refactor: 优化
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed May 28, 2024
1 parent 58821fd commit 52c1d05
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
@Getter
@Setter
public class Term implements Serializable,Cloneable {
public class Term implements Serializable, Cloneable {
private static final long serialVersionUID = 1L;

/**
Expand All @@ -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;

/**
Expand All @@ -59,6 +59,17 @@ public class Term implements Serializable,Cloneable {
@Schema(description = "嵌套条件")
private List<Term> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface TableOrViewMetadata extends ObjectMetadata, FeatureSupportedMet
List<RDBColumnMetadata> findColumns();

/**
* 获取当前表或者视图对列
* 获取当前表或者视图的列
*
* @param name 列名或者别名
* @return Optional
Expand All @@ -60,6 +60,18 @@ public interface TableOrViewMetadata extends ObjectMetadata, FeatureSupportedMet
*/
Optional<RDBColumnMetadata> 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()));
}


/**
* 查找列,可查找通过外键关联表对列或者其他表对列
*
Expand Down Expand Up @@ -129,17 +141,17 @@ default void fireEvent(EventType eventType, Consumer<EventContext> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -54,8 +55,12 @@ protected List<Object> convertList(RDBColumnMetadata column, Term term) {
//集合
if (value instanceof Collection) {
Collection<Object> listValue = ((Collection<Object>) value);
List<Object> list = new ArrayList<>(listValue.size());

if (listValue instanceof List) {
return Lists.transform(((List<Object>) listValue), (val) -> this.convertValue(column, val));
}

List<Object> list = new ArrayList<>(listValue.size());
for (Object val : listValue) {
list.add(this.convertValue(column, val));
}
Expand Down

0 comments on commit 52c1d05

Please sign in to comment.