net.sf.jsqlparser.expression.operators.relational.IsNullExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsqlparser Show documentation
Show all versions of jsqlparser Show documentation
JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes.
The generated hierarchy can be navigated using the Visitor Pattern.
The newest version!
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.expression.operators.relational;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.schema.Column;
public class IsNullExpression extends ASTNodeAccessImpl implements Expression {
private Expression leftExpression;
private boolean not = false;
private boolean useIsNull = false;
private boolean useNotNull = false;
public IsNullExpression() {}
public IsNullExpression(Expression leftExpression) {
this.leftExpression = leftExpression;
}
public IsNullExpression(String columnName, boolean not) {
this.leftExpression = new Column(columnName);
this.not = not;
}
public Expression getLeftExpression() {
return leftExpression;
}
public void setLeftExpression(Expression expression) {
leftExpression = expression;
}
public boolean isNot() {
return not;
}
public void setNot(boolean b) {
not = b;
}
public boolean isUseIsNull() {
return useIsNull;
}
public void setUseIsNull(boolean useIsNull) {
this.useIsNull = useIsNull;
}
public boolean isUseNotNull() {
return useNotNull;
}
public IsNullExpression setUseNotNull(boolean useNotNull) {
this.useNotNull = useNotNull;
return this;
}
@Override
public T accept(ExpressionVisitor expressionVisitor, S context) {
return expressionVisitor.visit(this, context);
}
@Override
public String toString() {
if (useNotNull) {
return leftExpression + " NOTNULL";
} else if (useIsNull) {
return leftExpression + (not ? " NOT" : "") + " ISNULL";
} else {
return leftExpression + " IS " + (not ? "NOT " : "") + "NULL";
}
}
public IsNullExpression withUseIsNull(boolean useIsNull) {
this.setUseIsNull(useIsNull);
return this;
}
public IsNullExpression withLeftExpression(Expression leftExpression) {
this.setLeftExpression(leftExpression);
return this;
}
public IsNullExpression withNot(boolean not) {
this.setNot(not);
return this;
}
public E getLeftExpression(Class type) {
return type.cast(getLeftExpression());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy