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