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 module hunt.sql.ast.expr.SQLFlashbackExpr; 17 18 import hunt.sql.ast.SQLExpr; 19 import hunt.sql.ast.SQLExprImpl; 20 import hunt.sql.ast.SQLObject; 21 import hunt.sql.visitor.SQLASTVisitor; 22 import hunt.collection; 23 24 /** 25 * Created by wenshao on 14/06/2017. 26 */ 27 public class SQLFlashbackExpr : SQLExprImpl { 28 private Type type; 29 private SQLExpr expr; 30 31 public this() { 32 33 } 34 35 public this(Type type, SQLExpr expr) { 36 this.type = type; 37 this.setExpr(expr); 38 } 39 40 public Type getType() { 41 return type; 42 } 43 44 public void setType(Type type) { 45 this.type = type; 46 } 47 48 public SQLExpr getExpr() { 49 return expr; 50 } 51 52 public void setExpr(SQLExpr expr) { 53 if (expr !is null) { 54 expr.setParent(this); 55 } 56 this.expr = expr; 57 } 58 59 override protected void accept0(SQLASTVisitor visitor) { 60 if (visitor.visit(this)) { 61 acceptChild(visitor, expr); 62 } 63 visitor.endVisit(this); 64 } 65 66 override 67 public List!SQLObject getChildren() { 68 return Collections.singletonList!SQLObject(expr); 69 } 70 71 override public SQLFlashbackExpr clone() { 72 SQLFlashbackExpr x = new SQLFlashbackExpr(); 73 x.type = this.type; 74 if (expr !is null) { 75 x.setExpr(expr.clone()); 76 } 77 return x; 78 } 79 80 override 81 public bool opEquals(Object o) { 82 if (this == o) return true; 83 if (o is null || typeid(this) != typeid(o)) return false; 84 85 SQLFlashbackExpr that = cast(SQLFlashbackExpr) o; 86 87 if (type != that.type) return false; 88 return expr !is null ? (cast(Object)(expr)).opEquals(cast(Object)(that.expr)) : that.expr is null; 89 } 90 91 override 92 public size_t toHash() @trusted nothrow { 93 size_t result = hashOf(type); 94 result = 31 * result + (expr !is null ? (cast(Object)expr).toHash() : 0); 95 return result; 96 } 97 98 public static struct Type { 99 enum Type SCN = Type(""); 100 enum Type TIMESTAMP = Type(""); 101 102 private string _name; 103 104 this(string name) 105 { 106 _name = name; 107 } 108 109 @property string name() 110 { 111 return _name; 112 } 113 114 bool opEquals(const Type h) nothrow { 115 return _name == h._name ; 116 } 117 118 bool opEquals(ref const Type h) nothrow { 119 return _name == h._name ; 120 } 121 } 122 }