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.statement.MySqlDeleteStatement; 17 18 19 import hunt.collection; 20 21 import hunt.sql.ast.SQLCommentHint; 22 import hunt.sql.ast.SQLName; 23 import hunt.sql.ast.SQLOrderBy; 24 import hunt.sql.ast.statement.SQLDeleteStatement; 25 import hunt.sql.ast.statement.SQLTableSource; 26 import hunt.sql.ast.SQLLimit; 27 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor; 28 import hunt.sql.dialect.mysql.visitor.MySqlOutputVisitor; 29 import hunt.sql.visitor.SQLASTVisitor; 30 import hunt.sql.util.DBType; 31 import hunt.util.StringBuilder; 32 33 public class MySqlDeleteStatement : SQLDeleteStatement { 34 35 private bool lowPriority = false; 36 private bool quick = false; 37 private bool ignore = false; 38 private SQLOrderBy orderBy; 39 private SQLLimit limit; 40 private List!(SQLCommentHint) hints; 41 // for petadata 42 private bool forceAllPartitions = false; 43 private SQLName forcePartition; 44 45 public this(){ 46 super(DBType.MYSQL.name); 47 } 48 49 override public MySqlDeleteStatement clone() { 50 MySqlDeleteStatement x = new MySqlDeleteStatement(); 51 cloneTo(x); 52 53 x.lowPriority = lowPriority; 54 x.quick = quick; 55 x.ignore = ignore; 56 57 if (using !is null) { 58 x.setUsing(using.clone()); 59 } 60 if (orderBy !is null) { 61 x.setOrderBy(orderBy.clone()); 62 } 63 if (limit !is null) { 64 x.setLimit(limit.clone()); 65 } 66 67 return x; 68 } 69 70 public List!(SQLCommentHint) getHints() { 71 if (hints is null) { 72 hints = new ArrayList!(SQLCommentHint)(); 73 } 74 return hints; 75 } 76 77 public int getHintsSize() { 78 if (hints is null) { 79 return 0; 80 } 81 82 return hints.size(); 83 } 84 85 public bool isLowPriority() { 86 return lowPriority; 87 } 88 89 public void setLowPriority(bool lowPriority) { 90 this.lowPriority = lowPriority; 91 } 92 93 public bool isQuick() { 94 return quick; 95 } 96 97 public void setQuick(bool quick) { 98 this.quick = quick; 99 } 100 101 public bool isIgnore() { 102 return ignore; 103 } 104 105 public void setIgnore(bool ignore) { 106 this.ignore = ignore; 107 } 108 109 public SQLOrderBy getOrderBy() { 110 return orderBy; 111 } 112 113 public void setOrderBy(SQLOrderBy orderBy) { 114 this.orderBy = orderBy; 115 } 116 117 public SQLLimit getLimit() { 118 return limit; 119 } 120 121 public void setLimit(SQLLimit limit) { 122 if (limit !is null) { 123 limit.setParent(this); 124 } 125 this.limit = limit; 126 } 127 128 129 override protected void accept0(SQLASTVisitor visitor) { 130 if (cast(MySqlASTVisitor)(visitor) !is null) { 131 accept0(cast(MySqlASTVisitor) visitor); 132 } else { 133 super.accept0(visitor); 134 } 135 } 136 137 override public void output(StringBuilder buf) { 138 new MySqlOutputVisitor(buf).visit(this); 139 } 140 141 protected void accept0(MySqlASTVisitor visitor) { 142 if (visitor.visit(this)) { 143 acceptChild(visitor, tableSource); 144 acceptChild(visitor, where); 145 acceptChild(visitor, from); 146 acceptChild(visitor, using); 147 acceptChild(visitor, orderBy); 148 acceptChild(visitor, limit); 149 } 150 151 visitor.endVisit(this); 152 } 153 154 public bool isForceAllPartitions() { 155 return forceAllPartitions; 156 } 157 158 public void setForceAllPartitions(bool forceAllPartitions) { 159 this.forceAllPartitions = forceAllPartitions; 160 } 161 162 public SQLName getForcePartition() { 163 return forcePartition; 164 } 165 166 public void setForcePartition(SQLName x) { 167 if (x !is null) { 168 x.setParent(this); 169 } 170 this.forcePartition = x; 171 } 172 }