
net.sf.jsqlparser.expression.CaseExpression 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 - 2013 JSQLParser
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package net.sf.jsqlparser.expression;
import java.util.List;
import net.sf.jsqlparser.statement.select.PlainSelect;
/**
* CASE/WHEN expression.
*
* Syntax:
*
* CASE
* WHEN condition THEN expression
* [WHEN condition THEN expression]...
* [ELSE expression]
* END
*
*
*
* or
*
*
*
* CASE expression
* WHEN condition THEN expression
* [WHEN condition THEN expression]...
* [ELSE expression]
* END
*
*
* See also: https://aurora.vcu.edu/db2help/db2s0/frame3.htm#casexp
* http://sybooks.sybase.com/onlinebooks/group-as/asg1251e /commands/
*
* @ebt-link;pt=5954?target=%25N%15_52628_START_RESTART_N%25
*
*
* @author Havard Rast Blok
*/
public class CaseExpression implements Expression {
private Expression switchExpression;
private List whenClauses;
private Expression elseExpression;
/*
* (non-Javadoc)
*
* @see net.sf.jsqlparser.expression.Expression#accept(net.sf.jsqlparser.expression.ExpressionVisitor)
*/
@Override
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}
/**
* @return Returns the switchExpression.
*/
public Expression getSwitchExpression() {
return switchExpression;
}
/**
* @param switchExpression The switchExpression to set.
*/
public void setSwitchExpression(Expression switchExpression) {
this.switchExpression = switchExpression;
}
/**
* @return Returns the elseExpression.
*/
public Expression getElseExpression() {
return elseExpression;
}
/**
* @param elseExpression The elseExpression to set.
*/
public void setElseExpression(Expression elseExpression) {
this.elseExpression = elseExpression;
}
/**
* @return Returns the whenClauses.
*/
public List getWhenClauses() {
return whenClauses;
}
/**
* @param whenClauses The whenClauses to set.
*/
public void setWhenClauses(List whenClauses) {
this.whenClauses = whenClauses;
}
@Override
public String toString() {
return "CASE " + ((switchExpression != null) ? switchExpression + " " : "")
+ PlainSelect.getStringList(whenClauses, false, false) + " "
+ ((elseExpression != null) ? "ELSE " + elseExpression + " " : "") + "END";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy