All Downloads are FREE. Search and download functionalities are using the official Maven repository.

x7.core.bean.condition.RefreshCondition Maven / Gradle / Ivy

There is a newer version: 2.2.7.RELEASE
Show newest version
package x7.core.bean.condition;

import x7.core.bean.*;
import x7.core.util.JsonX;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;


public class RefreshCondition {

    private T obj;
    private CriteriaCondition condition;
    private List refreshList = new ArrayList<>();
    private String sourceStript;//FIXME fetch

    private transient Class clz;
    private transient  CriteriaBuilder builder;

    public Class getClz() {
        return clz;
    }

    public void setClz(Class clz) {
        this.clz = clz;
        if (this.obj != null && this.obj.getClass() != clz){
            this.obj = (T)JsonX.toObject(this.obj,clz);
        }
    }

    public T getObj() {
        return obj;
    }

    public void setObj(T obj) {
        this.obj = obj;
    }

    public List getRefreshList() {
        return refreshList;
    }

    public void setRefreshList(List refreshList) {
        this.refreshList = refreshList;
    }

    public String getSourceStript() {
        return sourceStript;
    }

    public void setSourceStript(String sourceStript) {
        this.sourceStript = sourceStript;
    }

    public CriteriaCondition getCondition() {

        if (Objects.nonNull(this.builder)) {
            this.condition = builder.get();
        }

        return this.condition;
    }

    public void setCondition(CriteriaCondition condition) {
        this.condition = condition;
    }

    public RefreshCondition(){
        CriteriaBuilder builder = CriteriaBuilder.buildCondition();
        this.builder = builder;
    }

    public RefreshCondition(T t){

        this.obj = t;
        CriteriaBuilder builder = CriteriaBuilder.buildCondition();
        this.builder = builder;

    }


    public CriteriaBuilder.ConditionBuilder  and(){

        return this.builder.and();
    }

    /**
     *
     * String sqlX = "propertyA = propertyA + propertyB + 1"
     * @return RefreshCondition
     */
    public RefreshCondition refresh(String sqlX){

        if (Objects.isNull(sqlX))
            return this;

        Criteria.X x = new Criteria.X();
        x.setPredicate(Predicate.X);
        x.setValue(sqlX);
        this.refreshList.add(x);

        return this;
    }

    public RefreshCondition refresh(String property, Object value){

        if (Objects.isNull(value))
            return this;

        Criteria.X x = new Criteria.X();
        x.setPredicate(Predicate.EQ);
        x.setKey(property);
        x.setValue(value);
        this.refreshList.add(x);

        return this;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy