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.clause.MySqlCaseStatement; 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.statement.SQLIfStatement; 25 import hunt.sql.dialect.mysql.ast.MySqlObjectImpl; 26 import hunt.sql.dialect.mysql.ast.statement.MySqlStatementImpl; 27 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor; 28 29 public class MySqlCaseStatement : MySqlStatementImpl{ 30 31 alias accept0 = MySqlStatementImpl.accept0; 32 //case expr 33 private SQLExpr condition; 34 //when statement list 35 private List!MySqlWhenStatement whenList; 36 //else statement 37 private SQLIfStatement.Else elseItem; 38 39 this() 40 { 41 whenList = new ArrayList!(MySqlCaseStatement.MySqlWhenStatement)(); 42 } 43 44 public SQLExpr getCondition() { 45 return condition; 46 } 47 48 public void setCondition(SQLExpr condition) { 49 this.condition = condition; 50 } 51 52 public List!(MySqlWhenStatement) getWhenList() { 53 return whenList; 54 } 55 56 public void setWhenList(List!(MySqlWhenStatement) whenList) { 57 this.whenList = whenList; 58 } 59 60 public void addWhenStatement(MySqlWhenStatement stmt) 61 { 62 this.whenList.add(stmt); 63 } 64 65 public SQLIfStatement.Else getElseItem() { 66 return elseItem; 67 } 68 69 public void setElseItem(SQLIfStatement.Else elseItem) { 70 this.elseItem = elseItem; 71 } 72 73 override 74 public void accept0(MySqlASTVisitor visitor) { 75 // TODO Auto-generated method stub 76 if (visitor.visit(this)) { 77 acceptChild(visitor, condition); 78 acceptChild!MySqlWhenStatement(visitor, whenList); 79 acceptChild(visitor, elseItem); 80 } 81 visitor.endVisit(this); 82 } 83 84 override 85 public List!(SQLObject) getChildren() { 86 List!(SQLObject) children = new ArrayList!(SQLObject)(); 87 children.addAll(cast(List!SQLObject)(children)); 88 children.addAll(cast(List!SQLObject)(whenList)); 89 children.addAll(cast(List!SQLObject)(whenList)); 90 if (elseItem !is null) { 91 children.add(elseItem); 92 } 93 return children; 94 } 95 96 97 public static class MySqlWhenStatement : MySqlObjectImpl { 98 99 alias accept0 = MySqlObjectImpl.accept0; 100 101 private SQLExpr condition; 102 private List!(SQLStatement) statements; 103 104 this() 105 { 106 statements = new ArrayList!(SQLStatement)(); 107 } 108 109 override 110 public void accept0(MySqlASTVisitor visitor) { 111 if (visitor.visit(this)) { 112 acceptChild(visitor, condition); 113 acceptChild!SQLStatement(visitor, statements); 114 } 115 visitor.endVisit(this); 116 } 117 118 public SQLExpr getCondition() { 119 return condition; 120 } 121 122 public void setCondition(SQLExpr condition) { 123 this.condition = condition; 124 } 125 126 public List!(SQLStatement) getStatements() { 127 return statements; 128 } 129 130 public void setStatements(List!(SQLStatement) statements) { 131 this.statements = statements; 132 } 133 134 } 135 136 }