com.easy.query.api4j.extension.casewhen.CaseWhen4JBuilder Maven / Gradle / Ivy
package com.easy.query.api4j.extension.casewhen;
import com.easy.query.api4j.sql.SQLColumnAsSelector;
import com.easy.query.api4j.sql.SQLWherePredicate;
import com.easy.query.api4j.sql.impl.SQLWherePredicateImpl;
import com.easy.query.api4j.util.EasyLambdaUtil;
import com.easy.query.core.expression.lambda.Property;
import com.easy.query.core.expression.lambda.SQLExpression1;
import com.easy.query.core.expression.parser.core.EntitySQLTableOwner;
import com.easy.query.core.expression.parser.core.base.core.FilterContext;
import com.easy.query.core.expression.parser.core.base.impl.WherePredicateImpl;
import com.easy.query.core.expression.segment.CloneableSQLSegment;
import com.easy.query.core.extension.casewhen.CaseWhenBuilder;
/**
* create time 2023/7/3 08:42
* 文件说明
*
* @author xuejiaming
*/
public class CaseWhen4JBuilder {
private final SQLColumnAsSelector sqlColumnAsSelector;
private final CaseWhenBuilder caseWhenBuilder;
public CaseWhen4JBuilder(SQLColumnAsSelector sqlColumnAsSelector) {
this.sqlColumnAsSelector = sqlColumnAsSelector;
this.caseWhenBuilder = new CaseWhenBuilder(sqlColumnAsSelector.getRuntimeContext(), sqlColumnAsSelector.getExpressionContext());
}
public CaseWhen4JBuilder caseWhen(SQLExpression1> predicateExpression, Object then) {
caseWhenBuilder.caseWhen(filter -> {
predicateExpression.apply(new SQLWherePredicateImpl<>(new WherePredicateImpl<>(sqlColumnAsSelector.getTable(), new FilterContext(filter))));
}, then);
return this;
}
public CaseWhen4JBuilder caseWhen(SQLExpression1> predicateExpression, Property thenProperty) {
caseWhenBuilder.caseWhenColumn(filter -> {
predicateExpression.apply(new SQLWherePredicateImpl<>(new WherePredicateImpl<>(sqlColumnAsSelector.getTable(), new FilterContext(filter))));
}, sqlColumnAsSelector.getTable(), EasyLambdaUtil.getPropertyName(thenProperty));
return this;
}
public CaseWhen4JBuilder caseWhen(SQLExpression1> predicateExpression, EntitySQLTableOwner tableOwner, Property thenProperty) {
caseWhenBuilder.caseWhenColumn(filter -> {
predicateExpression.apply(new SQLWherePredicateImpl<>(new WherePredicateImpl<>(sqlColumnAsSelector.getTable(), new FilterContext(filter))));
}, tableOwner.getTable(), EasyLambdaUtil.getPropertyName(thenProperty));
return this;
}
public CloneableSQLSegment elseEnd(Object elseValue) {
return caseWhenBuilder.elseEnd(elseValue);
}
public CloneableSQLSegment elseEnd(Property elseProperty) {
return caseWhenBuilder.elseEndColumn(sqlColumnAsSelector.getTable(), EasyLambdaUtil.getPropertyName(elseProperty));
}
public CloneableSQLSegment elseEnd(EntitySQLTableOwner tableOwner, Property elseProperty) {
return caseWhenBuilder.elseEndColumn(tableOwner.getTable(), EasyLambdaUtil.getPropertyName(elseProperty));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy