de.ec.sql.ConditionPart Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sqlbuilder Show documentation
Show all versions of sqlbuilder Show documentation
Java builder to create SQL statements
package de.ec.sql;
import org.apache.commons.lang3.StringUtils;
import lombok.AccessLevel;
import lombok.Getter;
@Getter(AccessLevel.PROTECTED)
public class ConditionPart> implements QueryPart {
public enum Operator implements QueryPart {
EQUALS("="),
LIKE("LIKE"),
IN("IN"),
IS_NULL("IS NULL"),
IS_NOT_NULL("IS NOT NULL"),
GE(">="),
GT(">"),
LE("<="),
LT("<=");
private String string;
private Operator(final String string) {
this.string = string;
}
@Override
public String string(final QueryOptions options) {
return options.cased(string);
}
}
private final Conditionable conditionable;
private final String name;
private Object value;
private Object[] values;
private Operator operator;
private boolean not;
private boolean column;
private boolean expression;
protected ConditionPart(final Conditionable conditionable, final String name) {
this.conditionable = conditionable;
this.name = name;
}
public ConditionPart not() {
this.not = true;
return this;
}
public ConditionValue eq() {
return new ConditionValue<>(this, Operator.EQUALS);
}
public ConditionValue ge() {
return new ConditionValue<>(this, Operator.GE);
}
public ConditionValue gt() {
return new ConditionValue<>(this, Operator.GT);
}
public ConditionValue le() {
return new ConditionValue<>(this, Operator.LE);
}
public ConditionValue lt() {
return new ConditionValue<>(this, Operator.LT);
}
public ConditionValue like() {
return new ConditionValue<>(this, Operator.LIKE);
}
public ConditionValues in() {
return new ConditionValues<>(this);
}
@SuppressWarnings("unchecked")
protected T condition(final ConditionValue conditionValue) {
this.operator = conditionValue.getOperator();
this.value = conditionValue.getValue();
this.column = conditionValue.isColumn();
this.expression = conditionValue.isExpression();
return (T) conditionable;
}
@SuppressWarnings("unchecked")
protected T condition(final ConditionValues conditionValues) {
this.values = conditionValues.getValues();
this.operator = Operator.IN;
return (T) conditionable;
}
public T eq(final Object value) {
return op(value, Operator.EQUALS);
}
public T ge(final Object value) {
return op(value, Operator.GE);
}
public T gt(final Object value) {
return op(value, Operator.GT);
}
public T le(final Object value) {
return op(value, Operator.LE);
}
public T lt(final Object value) {
return op(value, Operator.LT);
}
public T like(final Object value) {
return op(value, Operator.LIKE);
}
public T isNull() {
return op(null, Operator.IS_NULL);
}
public T in(final Object... values) {
return in().values(values);
}
public T in(final Iterable