|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * JSQLParser library |
| 4 | + * %% |
| 5 | + * Copyright (C) 2004 - 2015 JSQLParser |
| 6 | + * %% |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Lesser General Public License as |
| 9 | + * published by the Free Software Foundation, either version 2.1 of the |
| 10 | + * License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Lesser Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Lesser Public |
| 18 | + * License along with this program. If not, see |
| 19 | + * <http://www.gnu.org/licenses/lgpl-2.1.html>. |
| 20 | + * #L% |
| 21 | + */ |
| 22 | +package net.sf.jsqlparser.expression; |
| 23 | + |
| 24 | +import java.util.List; |
| 25 | +import net.sf.jsqlparser.expression.operators.relational.ExpressionList; |
| 26 | +import net.sf.jsqlparser.statement.select.OrderByElement; |
| 27 | + |
| 28 | +/** |
| 29 | + * |
| 30 | + * @author toben |
| 31 | + */ |
| 32 | +public class WithinGroupExpression implements Expression { |
| 33 | + |
| 34 | + private String name; |
| 35 | + |
| 36 | + public String getName() { |
| 37 | + return name; |
| 38 | + } |
| 39 | + |
| 40 | + public void setName(String name) { |
| 41 | + this.name = name; |
| 42 | + } |
| 43 | + |
| 44 | + private List<OrderByElement> orderByElements; |
| 45 | + |
| 46 | + public List<OrderByElement> getOrderByElements() { |
| 47 | + return orderByElements; |
| 48 | + } |
| 49 | + |
| 50 | + public void setOrderByElements(List<OrderByElement> orderByElements) { |
| 51 | + this.orderByElements = orderByElements; |
| 52 | + } |
| 53 | + |
| 54 | + private ExpressionList exprList; |
| 55 | + |
| 56 | + public ExpressionList getExprList() { |
| 57 | + return exprList; |
| 58 | + } |
| 59 | + |
| 60 | + public void setExprList(ExpressionList exprList) { |
| 61 | + this.exprList = exprList; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public void accept(ExpressionVisitor visitor) { |
| 66 | + visitor.visit(this); |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public String toString() { |
| 71 | + StringBuilder b = new StringBuilder(); |
| 72 | + |
| 73 | + b.append(name); |
| 74 | + b.append(exprList.toString()); |
| 75 | + b.append(" WITHIN GROUP ("); |
| 76 | + |
| 77 | + b.append("ORDER BY "); |
| 78 | + for (int i = 0; i < orderByElements.size(); i++) { |
| 79 | + if (i > 0) { |
| 80 | + b.append(", "); |
| 81 | + } |
| 82 | + b.append(orderByElements.get(i).toString()); |
| 83 | + } |
| 84 | + |
| 85 | + b.append(")"); |
| 86 | + |
| 87 | + return b.toString(); |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments