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.SQLBlockStatement; 17 18 import hunt.collection; 19 20 import hunt.sql.ast.SQLParameter; 21 import hunt.sql.ast.SQLStatement; 22 import hunt.sql.ast.SQLStatementImpl; 23 import hunt.sql.visitor.SQLASTVisitor; 24 import hunt.sql.ast.SQLObject; 25 26 public class SQLBlockStatement : SQLStatementImpl { 27 private string labelName; 28 private string endLabel; 29 private List!SQLParameter parameters; 30 private List!SQLStatement statementList; 31 public SQLStatement exception; 32 private bool endOfCommit; 33 34 public this() { 35 parameters = new ArrayList!SQLParameter(); 36 statementList = new ArrayList!SQLStatement(); 37 } 38 39 public List!SQLStatement getStatementList() { 40 return statementList; 41 } 42 43 public void setStatementList(List!SQLStatement statementList) { 44 this.statementList = statementList; 45 } 46 47 public string getLabelName() { 48 return labelName; 49 } 50 51 public void setLabelName(string labelName) { 52 this.labelName = labelName; 53 } 54 55 override 56 public void accept0(SQLASTVisitor visitor) { 57 if (visitor.visit(this)) { 58 acceptChild!SQLParameter(visitor, parameters); 59 acceptChild!SQLStatement(visitor, statementList); 60 acceptChild(visitor, exception); 61 } 62 visitor.endVisit(this); 63 } 64 65 public List!SQLParameter getParameters() { 66 return parameters; 67 } 68 69 public void setParameters(List!SQLParameter parameters) { 70 this.parameters = parameters; 71 } 72 73 public SQLStatement getException() { 74 return exception; 75 } 76 77 public void setException(SQLStatement exception) { 78 if (exception !is null) { 79 exception.setParent(this); 80 } 81 this.exception = exception; 82 } 83 84 public string getEndLabel() { 85 return endLabel; 86 } 87 88 public void setEndLabel(string endLabel) { 89 this.endLabel = endLabel; 90 } 91 92 override public SQLBlockStatement clone() { 93 SQLBlockStatement x = new SQLBlockStatement(); 94 x.labelName = labelName; 95 x.endLabel = endLabel; 96 97 foreach (SQLParameter p ; parameters) { 98 SQLParameter p2 = p.clone(); 99 p2.setParent(x); 100 x.parameters.add(p2); 101 } 102 103 foreach (SQLStatement stmt ; statementList) { 104 SQLStatement stmt2 = stmt.clone(); 105 stmt2.setParent(x); 106 x.statementList.add(stmt2); 107 } 108 109 if (exception !is null) { 110 x.setException(exception.clone()); 111 } 112 113 return x; 114 } 115 116 public SQLParameter findParameter(long hash) { 117 foreach (SQLParameter param ; this.parameters) { 118 if (param.getName().nameHashCode64() == hash) { 119 return param; 120 } 121 } 122 123 return null; 124 } 125 126 public bool isEndOfCommit() { 127 return endOfCommit; 128 } 129 130 public void setEndOfCommit(bool value) { 131 this.endOfCommit = value; 132 } 133 }