-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathTableFunction.java
More file actions
221 lines (181 loc) · 5.62 KB
/
TableFunction.java
File metadata and controls
221 lines (181 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2019 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement.select;
import java.util.List;
import net.sf.jsqlparser.expression.Alias;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.Function;
import net.sf.jsqlparser.expression.operators.relational.ParenthesedExpressionList;
@SuppressWarnings({"PMD.UncommentedEmptyMethodBody"})
public class TableFunction extends Function implements FromItem {
private String prefix = null;
private Alias alias = null;
private Pivot pivot = null;
private UnPivot unPivot = null;
private Function function;
private ParenthesedExpressionList<Function> rowsFromFunctions;
private String withClause = null;
public TableFunction(Function function) {
this.function = function;
}
public TableFunction(String prefix, Function function) {
this.prefix = prefix;
this.function = function;
}
public TableFunction(Function function, String withClause) {
this.function = function;
this.withClause = withClause;
}
public TableFunction(String prefix, Function function, String withClause) {
this.prefix = prefix;
this.function = function;
this.withClause = withClause;
}
public TableFunction(ParenthesedExpressionList<Function> rowsFromFunctions) {
this.rowsFromFunctions = rowsFromFunctions;
}
public TableFunction(String prefix, ParenthesedExpressionList<Function> rowsFromFunctions) {
this.prefix = prefix;
this.rowsFromFunctions = rowsFromFunctions;
}
public TableFunction(ParenthesedExpressionList<Function> rowsFromFunctions, String withClause) {
this.rowsFromFunctions = rowsFromFunctions;
this.withClause = withClause;
}
public TableFunction(String prefix, ParenthesedExpressionList<Function> rowsFromFunctions,
String withClause) {
this.prefix = prefix;
this.rowsFromFunctions = rowsFromFunctions;
this.withClause = withClause;
}
public TableFunction(String prefix, String name, Expression... parameters) {
this.prefix = prefix;
this.function = new Function(name, parameters);
}
public TableFunction(String name, Expression... parameters) {
this(null, name, parameters);
}
public Function getFunction() {
return function;
}
public TableFunction setFunction(Function function) {
this.function = function;
this.rowsFromFunctions = null;
return this;
}
public ParenthesedExpressionList<Function> getRowsFromFunctions() {
return rowsFromFunctions;
}
public TableFunction setRowsFromFunctions(
ParenthesedExpressionList<Function> rowsFromFunctions) {
this.rowsFromFunctions = rowsFromFunctions;
this.function = null;
return this;
}
public boolean isRowsFrom() {
return rowsFromFunctions != null;
}
public List<Function> getFunctions() {
if (rowsFromFunctions != null) {
return rowsFromFunctions;
}
return function != null ? List.of(function) : null;
}
@Deprecated
public Function getExpression() {
return getFunction();
}
public String getPrefix() {
return prefix;
}
public TableFunction setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
public String getWithClause() {
return withClause;
}
public void setWithClause(String withClause) {
this.withClause = withClause;
}
public TableFunction withWithClause(String withClause) {
this.withClause = withClause;
return this;
}
@Override
public <T, S> T accept(FromItemVisitor<T> fromItemVisitor, S context) {
return fromItemVisitor.visit(this, context);
}
@Override
public Alias getAlias() {
return alias;
}
@Override
public void setAlias(Alias alias) {
this.alias = alias;
}
@Override
public TableFunction withAlias(Alias alias) {
return (TableFunction) FromItem.super.withAlias(alias);
}
@Override
public Pivot getPivot() {
return pivot;
}
@Override
public void setPivot(Pivot pivot) {
this.pivot = pivot;
}
@Override
public TableFunction withPivot(Pivot pivot) {
return (TableFunction) FromItem.super.withPivot(pivot);
}
@Override
public UnPivot getUnPivot() {
return unPivot;
}
@Override
public void setUnPivot(UnPivot unPivot) {
this.unPivot = unPivot;
}
@Override
public TableFunction withUnPivot(UnPivot unpivot) {
return (TableFunction) FromItem.super.withUnPivot(unpivot);
}
@Override
public SampleClause getSampleClause() {
return null;
}
@Override
public FromItem setSampleClause(SampleClause sampleClause) {
return null;
}
public StringBuilder appendTo(StringBuilder builder) {
if (prefix != null) {
builder.append(prefix).append(" ");
}
if (rowsFromFunctions != null) {
builder.append("ROWS FROM ").append(rowsFromFunctions);
} else {
builder.append(function);
}
if (withClause != null) {
builder.append(" WITH ").append(withClause);
}
if (alias != null) {
builder.append(alias);
}
return builder;
}
@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}
}