|
28 | 28 | */
|
29 | 29 | public class Function implements Expression {
|
30 | 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 |
| - @Override |
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 |
83 |
| - * parameter is "*", allColumns is set to true |
84 |
| - * |
85 |
| - * @return the list of parameters of the function (if any, else null) |
86 |
| - */ |
87 |
| - public ExpressionList getParameters() { |
88 |
| - return parameters; |
89 |
| - } |
90 |
| - |
91 |
| - public void setParameters(ExpressionList list) { |
92 |
| - parameters = list; |
93 |
| - } |
94 |
| - |
95 |
| - /** |
96 |
| - * Return true if it's in the form "{fn function_body() }" |
97 |
| - * |
98 |
| - * @return true if it's java-escaped |
99 |
| - */ |
100 |
| - public boolean isEscaped() { |
101 |
| - return isEscaped; |
102 |
| - } |
103 |
| - |
104 |
| - public void setEscaped(boolean isEscaped) { |
105 |
| - this.isEscaped = isEscaped; |
106 |
| - } |
107 |
| - |
108 |
| - @Override |
109 |
| - public String toString() { |
110 |
| - String params; |
111 |
| - |
112 |
| - if (parameters != null) { |
113 |
| - params = parameters.toString(); |
114 |
| - if (isDistinct()) { |
115 |
| - params = params.replaceFirst("\\(", "(DISTINCT "); |
116 |
| - } else if (isAllColumns()) { |
| 31 | + private String name; |
| 32 | + private ExpressionList parameters; |
| 33 | + private boolean allColumns = false; |
| 34 | + private boolean distinct = false; |
| 35 | + private boolean isEscaped = false; |
| 36 | + private String attribute; |
| 37 | + |
| 38 | + @Override |
| 39 | + public void accept(ExpressionVisitor expressionVisitor) { |
| 40 | + expressionVisitor.visit(this); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * The name of he function, i.e. "MAX" |
| 45 | + * |
| 46 | + * @return the name of he function |
| 47 | + */ |
| 48 | + public String getName() { |
| 49 | + return name; |
| 50 | + } |
| 51 | + |
| 52 | + public void setName(String string) { |
| 53 | + name = string; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * true if the parameter to the function is "*" |
| 58 | + * |
| 59 | + * @return true if the parameter to the function is "*" |
| 60 | + */ |
| 61 | + public boolean isAllColumns() { |
| 62 | + return allColumns; |
| 63 | + } |
| 64 | + |
| 65 | + public void setAllColumns(boolean b) { |
| 66 | + allColumns = b; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * true if the function is "distinct" |
| 71 | + * |
| 72 | + * @return true if the function is "distinct" |
| 73 | + */ |
| 74 | + public boolean isDistinct() { |
| 75 | + return distinct; |
| 76 | + } |
| 77 | + |
| 78 | + public void setDistinct(boolean b) { |
| 79 | + distinct = b; |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * The list of parameters of the function (if any, else null) If the |
| 84 | + * parameter is "*", allColumns is set to true |
| 85 | + * |
| 86 | + * @return the list of parameters of the function (if any, else null) |
| 87 | + */ |
| 88 | + public ExpressionList getParameters() { |
| 89 | + return parameters; |
| 90 | + } |
| 91 | + |
| 92 | + public void setParameters(ExpressionList list) { |
| 93 | + parameters = list; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Return true if it's in the form "{fn function_body() }" |
| 98 | + * |
| 99 | + * @return true if it's java-escaped |
| 100 | + */ |
| 101 | + public boolean isEscaped() { |
| 102 | + return isEscaped; |
| 103 | + } |
| 104 | + |
| 105 | + public void setEscaped(boolean isEscaped) { |
| 106 | + this.isEscaped = isEscaped; |
| 107 | + } |
| 108 | + |
| 109 | + public String getAttribute() { |
| 110 | + return attribute; |
| 111 | + } |
| 112 | + |
| 113 | + public void setAttribute(String attribute) { |
| 114 | + this.attribute = attribute; |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public String toString() { |
| 119 | + String params; |
| 120 | + |
| 121 | + if (parameters != null) { |
| 122 | + params = parameters.toString(); |
| 123 | + if (isDistinct()) { |
| 124 | + params = params.replaceFirst("\\(", "(DISTINCT "); |
| 125 | + } else if (isAllColumns()) { |
117 | 126 | params = params.replaceFirst("\\(", "(ALL ");
|
118 | 127 | }
|
119 |
| - } else if (isAllColumns()) { |
120 |
| - params = "(*)"; |
121 |
| - } else { |
122 |
| - params = "()"; |
123 |
| - } |
| 128 | + } else if (isAllColumns()) { |
| 129 | + params = "(*)"; |
| 130 | + } else { |
| 131 | + params = "()"; |
| 132 | + } |
124 | 133 |
|
125 |
| - String ans = name + "" + params + ""; |
| 134 | + String ans = name + "" + params + ""; |
126 | 135 |
|
127 |
| - if (isEscaped) { |
128 |
| - ans = "{fn " + ans + "}"; |
129 |
| - } |
| 136 | + if (attribute != null) { |
| 137 | + ans += "." + attribute; |
| 138 | + } |
130 | 139 |
|
131 |
| - return ans; |
132 |
| - } |
| 140 | + if (isEscaped) { |
| 141 | + ans = "{fn " + ans + "}"; |
| 142 | + } |
| 143 | + |
| 144 | + return ans; |
| 145 | + } |
133 | 146 | }
|
0 commit comments