mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
feat: 添加查询列和查询条件相互转换的适配器。
This commit is contained in:
parent
c5e2301e39
commit
80d63bdc04
@ -0,0 +1,42 @@
|
|||||||
|
package com.mybatisflex.core.query;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.dialect.IDialect;
|
||||||
|
import com.mybatisflex.core.exception.FlexAssert;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link QueryColumn} 适配器,用于将 {@link QueryCondition} 转换为 {@link QueryColumn}。
|
||||||
|
*
|
||||||
|
* @author 王帅
|
||||||
|
* @since 2024-09-29
|
||||||
|
*/
|
||||||
|
public class QueryColumnAdapter extends QueryColumn implements HasParamsColumn {
|
||||||
|
|
||||||
|
private final QueryCondition condition;
|
||||||
|
|
||||||
|
public QueryColumnAdapter(QueryCondition condition) {
|
||||||
|
FlexAssert.notNull(condition, "condition");
|
||||||
|
this.condition = condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryCondition getCondition() {
|
||||||
|
return condition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object[] getParamValues() {
|
||||||
|
return WrapperUtil.getValues(condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String toSelectSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||||
|
return condition.toSql(queryTables, dialect) + WrapperUtil.buildColumnAlias(alias, dialect);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String toConditionSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||||
|
return condition.toSql(queryTables, dialect);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
package com.mybatisflex.core.query;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.dialect.IDialect;
|
||||||
|
import com.mybatisflex.core.exception.FlexAssert;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link QueryCondition} 适配器,用于将 {@link QueryColumn} 转换为 {@link QueryCondition}。
|
||||||
|
*
|
||||||
|
* @author 王帅
|
||||||
|
* @since 2024-09-29
|
||||||
|
*/
|
||||||
|
public class QueryConditionAdapter extends QueryCondition {
|
||||||
|
|
||||||
|
public QueryConditionAdapter(QueryColumn column) {
|
||||||
|
FlexAssert.notNull(column, "column");
|
||||||
|
super.column = column;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValue() {
|
||||||
|
return column instanceof HasParamsColumn ? ((HasParamsColumn) column).getParamValues() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toSql(List<QueryTable> queryTables, IDialect dialect) {
|
||||||
|
return column.toConditionSql(queryTables, dialect);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user