com.easy.query.api4j.extension.casewhen.CaseWhen4JBuilder2 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.SQLExpression2;
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 CaseWhen4JBuilder2 {
private final SQLColumnAsSelector sqlColumnAsSelector1;
private final SQLColumnAsSelector sqlColumnAsSelector2;
private final CaseWhenBuilder caseWhenBuilder;
public CaseWhen4JBuilder2(SQLColumnAsSelector sqlColumnAsSelector1,SQLColumnAsSelector sqlColumnAsSelector2){
this.sqlColumnAsSelector1 = sqlColumnAsSelector1;
this.caseWhenBuilder=new CaseWhenBuilder(sqlColumnAsSelector1.getRuntimeContext(),sqlColumnAsSelector1.getExpressionContext());
this.sqlColumnAsSelector2 = sqlColumnAsSelector2;
}
public CaseWhen4JBuilder2 caseWhen(SQLExpression2,SQLWherePredicate> predicateExpression, Object then){
caseWhenBuilder.caseWhen(filter->{
FilterContext filterContext = new FilterContext(filter);
predicateExpression.apply(new SQLWherePredicateImpl<>(new WherePredicateImpl<>(sqlColumnAsSelector1.getTable(),filterContext)),new SQLWherePredicateImpl<>(new WherePredicateImpl<>(sqlColumnAsSelector2.getTable(),filterContext)));
},then);
return this;
}
public CaseWhen4JBuilder2 caseWhen(SQLExpression2,SQLWherePredicate> predicateExpression, Property thenProperty){
caseWhenBuilder.caseWhenColumn(filter->{
FilterContext filterContext = new FilterContext(filter);
predicateExpression.apply(new SQLWherePredicateImpl<>(new WherePredicateImpl<>(sqlColumnAsSelector1.getTable(),filterContext)),new SQLWherePredicateImpl<>(new WherePredicateImpl<>(sqlColumnAsSelector2.getTable(),filterContext)));
},sqlColumnAsSelector1.getTable(), EasyLambdaUtil.getPropertyName(thenProperty));
return this;
}
public CaseWhen4JBuilder2 caseWhen(SQLExpression2,SQLWherePredicate> predicateExpression, EntitySQLTableOwner sqlTableOwner, Property thenProperty){
caseWhenBuilder.caseWhenColumn(filter->{
FilterContext filterContext = new FilterContext(filter);
predicateExpression.apply(new SQLWherePredicateImpl<>(new WherePredicateImpl<>(sqlColumnAsSelector1.getTable(),filterContext)),new SQLWherePredicateImpl<>(new WherePredicateImpl<>(sqlColumnAsSelector2.getTable(),filterContext)));
},sqlTableOwner.getTable(), EasyLambdaUtil.getPropertyName(thenProperty));
return this;
}
public CloneableSQLSegment elseEnd(Object elseValue){
return caseWhenBuilder.elseEnd(elseValue);
}
public CloneableSQLSegment elseEnd(Property elseProperty){
return caseWhenBuilder.elseEndColumn(sqlColumnAsSelector1.getTable(),EasyLambdaUtil.getPropertyName(elseProperty));
}
public CloneableSQLSegment elseEnd(EntitySQLTableOwner sqlTableOwner, Property elseProperty){
return caseWhenBuilder.elseEndColumn(sqlTableOwner.getTable(),EasyLambdaUtil.getPropertyName(elseProperty));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy