/* ================================================================
* JSQLParser : java based sql parser
* ================================================================
*
* Project Info: http://jsqlparser.sourceforge.net
* Project Lead: Leonardo Francalanci (leoonardoo@yahoo.it);
*
* (C) Copyright 2004, by Leonardo Francalanci
*
* This library 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 library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
package net.sf.jsqlparser.expression;
import java.util.List;
import net.sf.jsqlparser.statement.select.PlainSelect;
/**
* CASE/WHEN expression.
*
* Syntax:
* <code>
* CASE
* WHEN condition THEN expression
* [WHEN condition THEN expression]...
* [ELSE expression]
* END
* </code>
*
* or <br>
*
* <code>
* CASE expression
* WHEN condition THEN expression
* [WHEN condition THEN expression]...
* [ELSE expression]
* END
* </code>
*
* 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<WhenClause> whenClauses;
private Expression elseExpression;
private String commentCase;
private String commentElse;
private String commentEnd;
/* (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<WhenClause> getWhenClauses() {
return whenClauses;
}
/**
* @param whenClauses The whenClauses to set.
*/
public void setWhenClauses(List<WhenClause> whenClauses) {
this.whenClauses = whenClauses;
}
@Override
public String toString() {
return (getCommentCase() != null ? getCommentCase() + " " : "") + "CASE "
+ ((switchExpression != null) ? switchExpression + " " : "")
+ PlainSelect.getStringList(whenClauses, false, false) + " "
+ ((elseExpression != null) ? (getCommentElse() != null ? getCommentElse() + " " : "")
+ "ELSE " + elseExpression + " " : "")
+ (getCommentEnd() != null ? getCommentEnd() + " " : "") + "END";
}
/**
* @return the commentCase
*/
public String getCommentCase() {
return commentCase;
}
/**
* @param commentCase the commentCase to set
*/
public void setCommentCase(String commentCase) {
this.commentCase = commentCase;
}
/**
* @return the commentElse
*/
public String getCommentElse() {
return commentElse;
}
/**
* @param commentElse the commentElse to set
*/
public void setCommentElse(String commentElse) {
this.commentElse = commentElse;
}
/**
* @return the commentEnd
*/
public String getCommentEnd() {
return commentEnd;
}
/**
* @param commentEnd the commentEnd to set
*/
public void setCommentEnd(String commentEnd) {
this.commentEnd = commentEnd;
}
}