forked from JSQLParser/JSqlParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTableFunction.java
170 lines (138 loc) · 3.92 KB
/
TableFunction.java
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
/*-
* #%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 net.sf.jsqlparser.expression.Alias;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.Function;
@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 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(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;
return this;
}
@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(" ");
}
builder.append(function.toString());
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();
}
}