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.SQLAllExpr; 17 18 import hunt.sql.ast.SQLExprImpl; 19 import hunt.sql.ast.SQLObject; 20 import hunt.sql.ast.statement.SQLSelect; 21 import hunt.sql.visitor.SQLASTVisitor; 22 import hunt.collection; 23 import hunt.util.StringBuilder; 24 25 26 public class SQLAllExpr : SQLExprImpl { 27 28 public SQLSelect subQuery; 29 30 public this(){ 31 32 } 33 34 public this(SQLSelect select){ 35 setSubQuery(select); 36 } 37 38 override public SQLAllExpr clone() { 39 SQLAllExpr x = new SQLAllExpr(); 40 if (subQuery !is null) { 41 x.setSubQuery(subQuery.clone()); 42 } 43 return x; 44 } 45 46 public SQLSelect getSubQuery() { 47 return this.subQuery; 48 } 49 50 public void setSubQuery(SQLSelect subQuery) { 51 if (subQuery !is null) { 52 subQuery.setParent(this); 53 } 54 this.subQuery = subQuery; 55 } 56 57 override public void output(StringBuilder buf) { 58 this.subQuery.output(buf); 59 } 60 61 override protected void accept0(SQLASTVisitor visitor) { 62 if (visitor.visit(this)) { 63 acceptChild(visitor, this.subQuery); 64 } 65 66 visitor.endVisit(this); 67 } 68 69 override public List!SQLObject getChildren() { 70 return Collections.singletonList!SQLObject(this.subQuery); 71 } 72 73 override 74 public size_t toHash() @trusted nothrow { 75 int prime = 31; 76 size_t result = 1; 77 result = prime * result + ((subQuery is null) ? 0 : (cast(Object)subQuery).toHash()); 78 return result; 79 } 80 81 override 82 public bool opEquals(Object obj) { 83 if (this is obj) { 84 return true; 85 } 86 if (obj is null) { 87 return false; 88 } 89 if (typeid(this) != typeid(obj)) { 90 return false; 91 } 92 SQLAllExpr other = cast(SQLAllExpr) obj; 93 if (subQuery is null) { 94 if (other.subQuery !is null) { 95 return false; 96 } 97 } else if (!(cast(Object)(subQuery)).opEquals(cast(Object)(other.subQuery))) { 98 return false; 99 } 100 return true; 101 } 102 103 }