diff --git a/src/main/java/net/sf/jsqlparser/expression/AnalyticExpression.java b/src/main/java/net/sf/jsqlparser/expression/AnalyticExpression.java index d46c9e963..2e191a81e 100644 --- a/src/main/java/net/sf/jsqlparser/expression/AnalyticExpression.java +++ b/src/main/java/net/sf/jsqlparser/expression/AnalyticExpression.java @@ -26,7 +26,6 @@ import java.util.List; import net.sf.jsqlparser.expression.operators.relational.ExpressionList; -import net.sf.jsqlparser.statement.select.PlainSelect; /** * Analytic function. The name of the function is variable but the parameters following the special @@ -38,14 +37,13 @@ */ public class AnalyticExpression extends ASTNodeAccessImpl implements Expression { - private ExpressionList partitionExpressionList; - private List orderByElements; + private final OrderByClause orderBy = new OrderByClause(); + private final PartitionByClause partitionBy = new PartitionByClause(); private String name; private Expression expression; private Expression offset; private Expression defaultValue; private boolean allColumns = false; - private WindowElement windowElement; private KeepExpression keep = null; private AnalyticType type = AnalyticType.OVER; private boolean distinct = false; @@ -56,11 +54,11 @@ public void accept(ExpressionVisitor expressionVisitor) { } public List getOrderByElements() { - return orderByElements; + return orderBy.getOrderByElements(); } public void setOrderByElements(List orderByElements) { - this.orderByElements = orderByElements; + orderBy.setOrderByElements(orderByElements); } public KeepExpression getKeep() { @@ -72,11 +70,11 @@ public void setKeep(KeepExpression keep) { } public ExpressionList getPartitionExpressionList() { - return partitionExpressionList; + return partitionBy.getPartitionExpressionList(); } public void setPartitionExpressionList(ExpressionList partitionExpressionList) { - this.partitionExpressionList = partitionExpressionList; + partitionBy.setPartitionExpressionList(partitionExpressionList); } public String getName() { @@ -112,11 +110,11 @@ public void setDefaultValue(Expression defaultValue) { } public WindowElement getWindowElement() { - return windowElement; + return orderBy.getWindowElement(); } public void setWindowElement(WindowElement windowElement) { - this.windowElement = windowElement; + orderBy.setWindowElement(windowElement); } public AnalyticType getType() { @@ -168,8 +166,8 @@ public String toString() { } b.append(" ("); - toStringPartitionBy(b); - toStringOrderByElements(b); + partitionBy.toStringPartitionBy(b); + orderBy.toStringOrderByElements(b); b.append(")"); @@ -184,29 +182,4 @@ public void setAllColumns(boolean allColumns) { this.allColumns = allColumns; } - private void toStringPartitionBy(StringBuilder b) { - if (partitionExpressionList != null && !partitionExpressionList.getExpressions().isEmpty()) { - b.append("PARTITION BY "); - b.append(PlainSelect. - getStringList(partitionExpressionList.getExpressions(), true, false)); - b.append(" "); - } - } - - private void toStringOrderByElements(StringBuilder b) { - if (orderByElements != null && !orderByElements.isEmpty()) { - b.append("ORDER BY "); - for (int i = 0; i < orderByElements.size(); i++) { - if (i > 0) { - b.append(", "); - } - b.append(orderByElements.get(i).toString()); - } - - if (windowElement != null) { - b.append(' '); - b.append(windowElement); - } - } - } } diff --git a/src/main/java/net/sf/jsqlparser/expression/OrderByClause.java b/src/main/java/net/sf/jsqlparser/expression/OrderByClause.java new file mode 100644 index 000000000..2bfad00a8 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/OrderByClause.java @@ -0,0 +1,64 @@ +/* + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2018 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 net.sf.jsqlparser.statement.select.OrderByElement; + +import java.util.List; + +public class OrderByClause { + private List orderByElements; + private WindowElement windowElement; + + public List getOrderByElements() { + return orderByElements; + } + + public void setOrderByElements(List orderByElements) { + this.orderByElements = orderByElements; + } + + public WindowElement getWindowElement() { + return windowElement; + } + + public void setWindowElement(WindowElement windowElement) { + this.windowElement = windowElement; + } + + void toStringOrderByElements(StringBuilder b) { + if (orderByElements != null && !orderByElements.isEmpty()) { + b.append("ORDER BY "); + for (int i = 0; i < orderByElements.size(); i++) { + if (i > 0) { + b.append(", "); + } + b.append(orderByElements.get(i).toString()); + } + + if (windowElement != null) { + b.append(' '); + b.append(windowElement); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/net/sf/jsqlparser/expression/PartitionByClause.java b/src/main/java/net/sf/jsqlparser/expression/PartitionByClause.java new file mode 100644 index 000000000..fb26c8e42 --- /dev/null +++ b/src/main/java/net/sf/jsqlparser/expression/PartitionByClause.java @@ -0,0 +1,46 @@ +/* + * #%L + * JSQLParser library + * %% + * Copyright (C) 2004 - 2018 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 net.sf.jsqlparser.expression.operators.relational.ExpressionList; +import net.sf.jsqlparser.statement.select.PlainSelect; + +public class PartitionByClause { + ExpressionList partitionExpressionList; + + public ExpressionList getPartitionExpressionList() { + return partitionExpressionList; + } + + public void setPartitionExpressionList(ExpressionList partitionExpressionList) { + this.partitionExpressionList = partitionExpressionList; + } + + void toStringPartitionBy(StringBuilder b) { + if (partitionExpressionList != null && !partitionExpressionList.getExpressions().isEmpty()) { + b.append("PARTITION BY "); + b.append(PlainSelect. + getStringList(partitionExpressionList.getExpressions(), true, false)); + b.append(" "); + } + } +} \ No newline at end of file