|
1 | | -/* ================================================================ |
2 | | - * JSQLParser : java based sql parser |
3 | | - * ================================================================ |
4 | | - * |
5 | | - * Project Info: http://jsqlparser.sourceforge.net |
6 | | - * Project Lead: Leonardo Francalanci (leoonardoo@yahoo.it); |
7 | | - * |
8 | | - * (C) Copyright 2004, by Leonardo Francalanci |
9 | | - * |
10 | | - * This library is free software; you can redistribute it and/or modify it under the terms |
11 | | - * of the GNU Lesser General Public License as published by the Free Software Foundation; |
12 | | - * either version 2.1 of the License, or (at your option) any later version. |
13 | | - * |
14 | | - * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
15 | | - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | | - * See the GNU Lesser General Public License for more details. |
17 | | - * |
18 | | - * You should have received a copy of the GNU Lesser General Public License along with this |
19 | | - * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
20 | | - * Boston, MA 02111-1307, USA. |
21 | | - */ |
22 | | - |
23 | | -package net.sf.jsqlparser.expression; |
24 | | - |
25 | | -import net.sf.jsqlparser.expression.operators.relational.ExpressionList; |
26 | | - |
27 | | -/** |
28 | | - * A function as MAX,COUNT... |
29 | | - */ |
30 | | -public class Function implements Expression { |
31 | | - |
32 | | - private String name; |
33 | | - private ExpressionList parameters; |
34 | | - private boolean allColumns = false; |
35 | | - private boolean distinct = false; |
36 | | - private boolean isEscaped = false; |
37 | | - |
38 | | - public void accept(ExpressionVisitor expressionVisitor) { |
39 | | - expressionVisitor.visit(this); |
40 | | - } |
41 | | - |
42 | | - /** |
43 | | - * The name of he function, i.e. "MAX" |
44 | | - * |
45 | | - * @return the name of he function |
46 | | - */ |
47 | | - public String getName() { |
48 | | - return name; |
49 | | - } |
50 | | - |
51 | | - public void setName(String string) { |
52 | | - name = string; |
53 | | - } |
54 | | - |
55 | | - /** |
56 | | - * true if the parameter to the function is "*" |
57 | | - * |
58 | | - * @return true if the parameter to the function is "*" |
59 | | - */ |
60 | | - public boolean isAllColumns() { |
61 | | - return allColumns; |
62 | | - } |
63 | | - |
64 | | - public void setAllColumns(boolean b) { |
65 | | - allColumns = b; |
66 | | - } |
67 | | - |
68 | | - /** |
69 | | - * true if the function is "distinct" |
70 | | - * |
71 | | - * @return true if the function is "distinct" |
72 | | - */ |
73 | | - public boolean isDistinct() { |
74 | | - return distinct; |
75 | | - } |
76 | | - |
77 | | - public void setDistinct(boolean b) { |
78 | | - distinct = b; |
79 | | - } |
80 | | - |
81 | | - /** |
82 | | - * The list of parameters of the function (if any, else null) If the parameter is "*", allColumns is set to true |
83 | | - * |
84 | | - * @return the list of parameters of the function (if any, else null) |
85 | | - */ |
86 | | - public ExpressionList getParameters() { |
87 | | - return parameters; |
88 | | - } |
89 | | - |
90 | | - public void setParameters(ExpressionList list) { |
91 | | - parameters = list; |
92 | | - } |
93 | | - |
94 | | - /** |
95 | | - * Return true if it's in the form "{fn function_body() }" |
96 | | - * |
97 | | - * @return true if it's java-escaped |
98 | | - */ |
99 | | - public boolean isEscaped() { |
100 | | - return isEscaped; |
101 | | - } |
102 | | - |
103 | | - public void setEscaped(boolean isEscaped) { |
104 | | - this.isEscaped = isEscaped; |
105 | | - } |
106 | | - |
107 | | - public String toString() { |
108 | | - String params = ""; |
109 | | - |
110 | | - if (allColumns) { |
111 | | - params = "(*)"; |
112 | | - } else if (parameters != null) { |
113 | | - params = parameters.toString(); |
114 | | - if (isDistinct()) { |
115 | | - params = params.replaceFirst("\\(", "(DISTINCT "); |
116 | | - } |
117 | | - } |
118 | | - |
119 | | - String ans = name + "" + params + ""; |
120 | | - |
121 | | - if (isEscaped) { |
122 | | - ans = "{fn " + ans + "}"; |
123 | | - } |
124 | | - |
125 | | - return ans; |
126 | | - } |
127 | | -} |
| 1 | +/* ================================================================ |
| 2 | + * JSQLParser : java based sql parser |
| 3 | + * ================================================================ |
| 4 | + * |
| 5 | + * Project Info: http://jsqlparser.sourceforge.net |
| 6 | + * Project Lead: Leonardo Francalanci (leoonardoo@yahoo.it); |
| 7 | + * |
| 8 | + * (C) Copyright 2004, by Leonardo Francalanci |
| 9 | + * |
| 10 | + * This library is free software; you can redistribute it and/or modify it under the terms |
| 11 | + * of the GNU Lesser General Public License as published by the Free Software Foundation; |
| 12 | + * either version 2.1 of the License, or (at your option) any later version. |
| 13 | + * |
| 14 | + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 16 | + * See the GNU Lesser General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Lesser General Public License along with this |
| 19 | + * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
| 20 | + * Boston, MA 02111-1307, USA. |
| 21 | + */ |
| 22 | +package net.sf.jsqlparser.expression; |
| 23 | + |
| 24 | +import net.sf.jsqlparser.expression.operators.relational.ExpressionList; |
| 25 | + |
| 26 | +/** |
| 27 | + * A function as MAX,COUNT... |
| 28 | + */ |
| 29 | +public class Function implements Expression { |
| 30 | + |
| 31 | + private String name; |
| 32 | + private ExpressionList parameters; |
| 33 | + private boolean allColumns = false; |
| 34 | + private boolean distinct = false; |
| 35 | + private boolean isEscaped = false; |
| 36 | + |
| 37 | + public void accept(ExpressionVisitor expressionVisitor) { |
| 38 | + expressionVisitor.visit(this); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * The name of he function, i.e. "MAX" |
| 43 | + * |
| 44 | + * @return the name of he function |
| 45 | + */ |
| 46 | + public String getName() { |
| 47 | + return name; |
| 48 | + } |
| 49 | + |
| 50 | + public void setName(String string) { |
| 51 | + name = string; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * true if the parameter to the function is "*" |
| 56 | + * |
| 57 | + * @return true if the parameter to the function is "*" |
| 58 | + */ |
| 59 | + public boolean isAllColumns() { |
| 60 | + return allColumns; |
| 61 | + } |
| 62 | + |
| 63 | + public void setAllColumns(boolean b) { |
| 64 | + allColumns = b; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * true if the function is "distinct" |
| 69 | + * |
| 70 | + * @return true if the function is "distinct" |
| 71 | + */ |
| 72 | + public boolean isDistinct() { |
| 73 | + return distinct; |
| 74 | + } |
| 75 | + |
| 76 | + public void setDistinct(boolean b) { |
| 77 | + distinct = b; |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * The list of parameters of the function (if any, else null) If the |
| 82 | + * parameter is "*", allColumns is set to true |
| 83 | + * |
| 84 | + * @return the list of parameters of the function (if any, else null) |
| 85 | + */ |
| 86 | + public ExpressionList getParameters() { |
| 87 | + return parameters; |
| 88 | + } |
| 89 | + |
| 90 | + public void setParameters(ExpressionList list) { |
| 91 | + parameters = list; |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * Return true if it's in the form "{fn function_body() }" |
| 96 | + * |
| 97 | + * @return true if it's java-escaped |
| 98 | + */ |
| 99 | + public boolean isEscaped() { |
| 100 | + return isEscaped; |
| 101 | + } |
| 102 | + |
| 103 | + public void setEscaped(boolean isEscaped) { |
| 104 | + this.isEscaped = isEscaped; |
| 105 | + } |
| 106 | + |
| 107 | + public String toString() { |
| 108 | + String params; |
| 109 | + |
| 110 | + if (allColumns) { |
| 111 | + params = "(*)"; |
| 112 | + } else if (parameters != null) { |
| 113 | + params = parameters.toString(); |
| 114 | + if (isDistinct()) { |
| 115 | + params = params.replaceFirst("\\(", "(DISTINCT "); |
| 116 | + } |
| 117 | + } else { |
| 118 | + params = "()"; |
| 119 | + } |
| 120 | + |
| 121 | + String ans = name + "" + params + ""; |
| 122 | + |
| 123 | + if (isEscaped) { |
| 124 | + ans = "{fn " + ans + "}"; |
| 125 | + } |
| 126 | + |
| 127 | + return ans; |
| 128 | + } |
| 129 | +} |
0 commit comments