|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * JSQLParser library |
| 4 | + * %% |
| 5 | + * Copyright (C) 2004 - 2014 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.util; |
| 23 | + |
| 24 | +import net.sf.jsqlparser.expression.Expression; |
| 25 | +import net.sf.jsqlparser.statement.select.PlainSelect; |
| 26 | +import net.sf.jsqlparser.statement.select.Select; |
| 27 | +import net.sf.jsqlparser.statement.select.SelectExpressionItem; |
| 28 | +import net.sf.jsqlparser.statement.select.SelectVisitor; |
| 29 | +import net.sf.jsqlparser.statement.select.SetOperationList; |
| 30 | +import net.sf.jsqlparser.statement.select.WithItem; |
| 31 | + |
| 32 | +/** |
| 33 | + * Utility function for select statements. |
| 34 | + * |
| 35 | + * @author toben |
| 36 | + */ |
| 37 | +public final class SelectUtils { |
| 38 | + |
| 39 | + private SelectUtils() { |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Adds an expression to select statements. E.g. a simple column is an expression. |
| 44 | + * |
| 45 | + * @param select |
| 46 | + * @param expr |
| 47 | + */ |
| 48 | + public static void addExpression(Select select, final Expression expr) { |
| 49 | + select.getSelectBody().accept(new SelectVisitor() { |
| 50 | + |
| 51 | + @Override |
| 52 | + public void visit(PlainSelect plainSelect) { |
| 53 | + plainSelect.getSelectItems().add(new SelectExpressionItem(expr)); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public void visit(SetOperationList setOpList) { |
| 58 | + throw new UnsupportedOperationException("Not supported yet."); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public void visit(WithItem withItem) { |
| 63 | + throw new UnsupportedOperationException("Not supported yet."); |
| 64 | + } |
| 65 | + }); |
| 66 | + } |
| 67 | +} |
0 commit comments