xyz.erupt.jpa.dao.EruptLambdaQuery Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of erupt-jpa Show documentation
Show all versions of erupt-jpa Show documentation
EruptProcess database impl
package xyz.erupt.jpa.dao;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.RandomStringUtils;
import xyz.erupt.jpa.constant.SqlLang;
import xyz.erupt.linq.lambda.LambdaInfo;
import xyz.erupt.linq.lambda.LambdaSee;
import xyz.erupt.linq.lambda.SFunction;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author YuePeng
* date 2024/3/30 23:23
*/
public class EruptLambdaQuery {
private final QuerySchema querySchema = new QuerySchema();
private final EntityManager entityManager;
private final Class eruptClass;
public EruptLambdaQuery(EntityManager entityManager, Class eruptClass) {
this.entityManager = entityManager;
this.eruptClass = eruptClass;
}
public EruptLambdaQuery isNull(SFunction field) {
querySchema.getWheres().add(LambdaSee.field(field) + " is null");
return this;
}
public EruptLambdaQuery isNotNull(SFunction field) {
querySchema.getWheres().add(LambdaSee.field(field) + " is not null");
return this;
}
public EruptLambdaQuery eq(SFunction field, Object val) {
String placeholder = this.genePlaceholder();
querySchema.getWheres().add(geneField(field) + " = :" + placeholder);
querySchema.getParams().put(placeholder, val);
return this;
}
public EruptLambdaQuery ne(SFunction field, Object val) {
String placeholder = this.genePlaceholder();
querySchema.getWheres().add(LambdaSee.field(field) + " <> :" + placeholder);
querySchema.getParams().put(placeholder, val);
return this;
}
public EruptLambdaQuery gt(SFunction field, Object val) {
String placeholder = this.genePlaceholder();
querySchema.getWheres().add(geneField(field) + " > :" + placeholder);
querySchema.getParams().put(placeholder, val);
return this;
}
public EruptLambdaQuery lt(SFunction field, Object val) {
String placeholder = this.genePlaceholder();
querySchema.getWheres().add(geneField(field) + " < :" + placeholder);
querySchema.getParams().put(placeholder, val);
return this;
}
public EruptLambdaQuery ge(SFunction field, Object val) {
String placeholder = this.genePlaceholder();
querySchema.getWheres().add(geneField(field) + " >= :" + placeholder);
querySchema.getParams().put(placeholder, val);
return this;
}
public EruptLambdaQuery le(SFunction field, Object val) {
String placeholder = this.genePlaceholder();
querySchema.getWheres().add(geneField(field) + " <= :" + placeholder);
querySchema.getParams().put(placeholder, val);
return this;
}
public EruptLambdaQuery between(SFunction field, Object val1, Object val2) {
String l = this.genePlaceholder();
String r = this.genePlaceholder();
querySchema.getWheres().add(LambdaSee.field(field) + " between :" + l + " and " + ":" + r);
querySchema.getParams().put(l, val1);
querySchema.getParams().put(r, val2);
return this;
}
public EruptLambdaQuery in(SFunction field, List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy