org.joo.libra.sql.ExpressionNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of joo-libra Show documentation
Show all versions of joo-libra Show documentation
Java Predicate with SQL-like syntax support
package org.joo.libra.sql;
import java.math.BigDecimal;
import org.joo.libra.Predicate;
import org.joo.libra.PredicateContext;
import org.joo.libra.common.HasValue;
import org.joo.libra.logic.AndPredicate;
import org.joo.libra.logic.EqualsPredicate;
import org.joo.libra.logic.NotPredicate;
import org.joo.libra.logic.OrPredicate;
import org.joo.libra.numeric.GreaterEqualPredicate;
import org.joo.libra.numeric.GreaterThanPredicate;
import org.joo.libra.numeric.LessEqualPredicate;
import org.joo.libra.numeric.LessThanPredicate;
import org.joo.libra.sql.antlr.SqlLexer;
import org.joo.libra.text.ContainPredicate;
import org.joo.libra.text.IsEmptyPredicate;
import org.joo.libra.text.MatchPredicate;
public interface ExpressionNode {
public Predicate buildPredicate();
}
abstract class InfixExpressionNode implements ExpressionNode {
private ExpressionNode left;
private ExpressionNode right;
public ExpressionNode getLeft() {
return left;
}
public void setLeft(ExpressionNode left) {
this.left = left;
}
public ExpressionNode getRight() {
return right;
}
public void setRight(ExpressionNode right) {
this.right = right;
}
}
class AndExpressionNode extends InfixExpressionNode {
@Override
public Predicate buildPredicate() {
return new AndPredicate(getLeft().buildPredicate(), getRight().buildPredicate());
}
}
class OrExpressionNode extends InfixExpressionNode {
@Override
public Predicate buildPredicate() {
return new OrPredicate(getLeft().buildPredicate(), getRight().buildPredicate());
}
}
class NotExpressionNode implements ExpressionNode {
private ExpressionNode innerNode;
public ExpressionNode getInnerNode() {
return innerNode;
}
public void setInnerNode(ExpressionNode innerNode) {
this.innerNode = innerNode;
}
@Override
public Predicate buildPredicate() {
return new NotPredicate(innerNode.buildPredicate());
}
}
class ValueExpressionNode implements ExpressionNode, HasValue {
private T value;
@Override
public T getValue(PredicateContext context) {
return value;
}
public void setValue(T value) {
this.value = value;
}
@Override
public Predicate buildPredicate() {
return null;
}
}
class StringExpressionNode extends ValueExpressionNode {
}
class NumberExpressionNode extends ValueExpressionNode {
}
class BooleanExpressionNode extends ValueExpressionNode {
}
class ObjectExpressionNode extends ValueExpressionNode