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.statement.SQLWhileStatement; 17 18 19 import hunt.collection; 20 21 import hunt.sql.ast.SQLExpr; 22 import hunt.sql.ast.SQLObject; 23 import hunt.sql.ast.SQLStatement; 24 import hunt.sql.ast.SQLStatementImpl; 25 // import hunt.sql.dialect.mysql.ast.statement.MySqlStatementImpl; 26 // import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor; 27 import hunt.sql.visitor.SQLASTVisitor; 28 29 30 public class SQLWhileStatement : SQLStatementImpl { 31 32 //while expr 33 private SQLExpr condition; 34 private List!SQLStatement statements; 35 //while label name 36 private string labelName; 37 38 this() 39 { 40 statements = new ArrayList!SQLStatement(); 41 } 42 43 public string getLabelName() { 44 return labelName; 45 } 46 47 public void setLabelName(string labelName) { 48 this.labelName = labelName; 49 } 50 51 override public void accept0(SQLASTVisitor visitor) { 52 if (visitor.visit(this)) { 53 acceptChild(visitor, condition); 54 acceptChild!SQLStatement(visitor, statements); 55 } 56 visitor.endVisit(this); 57 } 58 59 override 60 public List!SQLObject getChildren() { 61 List!SQLObject children = new ArrayList!SQLObject(); 62 children.add(condition); 63 children.addAll(cast(List!SQLObject)(this.statements)); 64 return children; 65 } 66 67 public List!SQLStatement getStatements() { 68 return statements; 69 } 70 71 public void setStatements(List!SQLStatement statements) { 72 this.statements = statements; 73 } 74 public SQLExpr getCondition() { 75 return condition; 76 } 77 78 public void setCondition(SQLExpr condition) { 79 this.condition = condition; 80 } 81 82 override public SQLWhileStatement clone() { 83 SQLWhileStatement x = new SQLWhileStatement(); 84 85 if (condition !is null) { 86 x.setCondition(condition.clone()); 87 } 88 foreach (SQLStatement stmt ; statements){ 89 SQLStatement stmt2 = stmt.clone(); 90 stmt2.setParent(x); 91 x.statements.add(stmt2); 92 } 93 x.labelName = labelName; 94 return x; 95 } 96 }