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

cn.patterncat.helper.sql.builder.JpaSpecBuilder Maven / Gradle / Ivy

There is a newer version: 0.0.7
Show newest version
package cn.patterncat.helper.sql.builder;

import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.domain.Specifications;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

/**
 * Created by patterncat on 2018-04-17.
 */
public class JpaSpecBuilder {

    private Specifications specs;

    private JpaSpecBuilder() {
        Specification start = (Root root, CriteriaQuery query, CriteriaBuilder cb) -> cb.isTrue(cb.literal(true));
        this.specs = Specifications.where(start);
    }

    public static  JpaSpecBuilder newInstance(){
        return new JpaSpecBuilder<>();
    }

    public JpaSpecBuilder or(final Specification spec) {
        specs = specs.or(spec);
        return this;
    }

    public JpaSpecBuilder and(final Specification spec) {
        specs = specs.and(spec);
        return this;
    }

    public Specification build() {
        return specs;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy