com.rapleaf.jack.queries.WhereConstraint Maven / Gradle / Ivy
package com.rapleaf.jack.queries;
import java.util.List;
import com.rapleaf.jack.queries.where_operators.IWhereOperator;
public class WhereConstraint implements QueryCondition {
enum Logic {
AND, OR
}
private final Column column;
private final IWhereOperator operator;
private Logic logic;
// constructor for model query
public WhereConstraint(Enum field, IWhereOperator operator) {
this.column = Column.fromField(null, field, null);
this.operator = operator;
this.logic = null;
}
// constructor for generic query
public WhereConstraint(Column column, IWhereOperator operator, Logic logic) {
this.column = column;
this.operator = operator;
this.logic = logic;
}
void setLogic(Logic logic) {
this.logic = logic;
}
public Enum getField() {
return column.getField();
}
public boolean isId() {
return column.getField() == null;
}
public IWhereOperator getOperator() {
return operator;
}
public Logic getLogic() {
return logic;
}
public List getParameters() {
return operator.getParameters();
}
@Override
public String getSqlStatement() {
return (logic != null ? logic.toString() + " " : "") + "`" + column.getSqlKeyword() + "` " + operator.getSqlStatement();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy