1 /*
2 * Copyright 2015-2018 HuntLabs.cn
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */16 modulehunt.sql.visitor.functions.Greatest;
17 18 // import hunt.sql.visitor.SQLEvalVisitor.EVAL_VALUE;19 20 importhunt.sql.ast.SQLExpr;
21 importhunt.sql.ast.expr.SQLMethodInvokeExpr;
22 importhunt.sql.visitor.SQLEvalVisitor;
23 importhunt.sql.visitor.SQLEvalVisitorUtils;
24 importhunt.sql.visitor.functions.Function;
25 26 importstd.concurrency : initOnce;
27 28 publicclassGreatest : Function {
29 30 staticGreatestinstance() {
31 __gsharedGreatestinst;
32 returninitOnce!inst(newGreatest());
33 }
34 35 // public static Greatest instance;36 37 // static this()38 // {39 // instance = new Greatest();40 // }41 42 publicObjecteval(SQLEvalVisitorvisitor, SQLMethodInvokeExprx) {
43 Objectresult = null;
44 foreach(SQLExpritem ; x.getParameters()) {
45 item.accept(visitor);
46 47 ObjectitemValue = item.getAttributes().get(SQLEvalVisitor.EVAL_VALUE);
48 if (resultisnull) {
49 result = itemValue;
50 } else {
51 if (SQLEvalVisitorUtils.gt(itemValue, result)) {
52 result = itemValue;
53 }
54 }
55 }
56 57 returnresult;
58 }
59 }