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