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.MySqlUpdateStatement; 17 18 import hunt.sql.ast.SQLExpr; 19 import hunt.sql.ast.SQLName; 20 import hunt.sql.ast.SQLOrderBy; 21 import hunt.sql.ast.statement.SQLUpdateStatement; 22 import hunt.sql.ast.SQLLimit; 23 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor; 24 import hunt.sql.visitor.SQLASTVisitor; 25 import hunt.sql.util.DBType; 26 import hunt.sql.dialect.mysql.ast.statement.MySqlStatement; 27 import hunt.collection; 28 import hunt.sql.ast.SQLObject; 29 import hunt.sql.ast.statement.SQLUpdateSetItem; 30 31 public class MySqlUpdateStatement : SQLUpdateStatement , MySqlStatement { 32 private SQLLimit limit; 33 34 private bool lowPriority = false; 35 private bool ignore = false; 36 private bool commitOnSuccess = false; 37 private bool rollBackOnFail = false; 38 private bool queryOnPk = false; 39 private SQLExpr targetAffectRow; 40 41 // for petadata 42 private bool forceAllPartitions = false; 43 private SQLName forcePartition; 44 45 public this(){ 46 super(DBType.MYSQL.name); 47 } 48 49 public SQLLimit getLimit() { 50 return limit; 51 } 52 53 public void setLimit(SQLLimit limit) { 54 if (limit !is null) { 55 limit.setParent(this); 56 } 57 this.limit = limit; 58 } 59 60 61 override protected void accept0(SQLASTVisitor visitor) { 62 if (cast(MySqlASTVisitor)(visitor) !is null) { 63 accept0(cast(MySqlASTVisitor) visitor); 64 } else { 65 super.accept0(visitor); 66 } 67 } 68 69 public void accept0(MySqlASTVisitor visitor) { 70 if (visitor.visit(this)) { 71 acceptChild(visitor, tableSource); 72 acceptChild!SQLUpdateSetItem(visitor, items); 73 acceptChild(visitor, where); 74 acceptChild(visitor, orderBy); 75 acceptChild(visitor, limit); 76 } 77 visitor.endVisit(this); 78 } 79 80 public bool isLowPriority() { 81 return lowPriority; 82 } 83 84 public void setLowPriority(bool lowPriority) { 85 this.lowPriority = lowPriority; 86 } 87 88 public bool isIgnore() { 89 return ignore; 90 } 91 92 public void setIgnore(bool ignore) { 93 this.ignore = ignore; 94 } 95 96 public bool isCommitOnSuccess() { 97 return commitOnSuccess; 98 } 99 100 public void setCommitOnSuccess(bool commitOnSuccess) { 101 this.commitOnSuccess = commitOnSuccess; 102 } 103 104 public bool isRollBackOnFail() { 105 return rollBackOnFail; 106 } 107 108 public void setRollBackOnFail(bool rollBackOnFail) { 109 this.rollBackOnFail = rollBackOnFail; 110 } 111 112 public bool isQueryOnPk() { 113 return queryOnPk; 114 } 115 116 public void setQueryOnPk(bool queryOnPk) { 117 this.queryOnPk = queryOnPk; 118 } 119 120 public SQLExpr getTargetAffectRow() { 121 return targetAffectRow; 122 } 123 124 public void setTargetAffectRow(SQLExpr targetAffectRow) { 125 if (targetAffectRow !is null) { 126 targetAffectRow.setParent(this); 127 } 128 this.targetAffectRow = targetAffectRow; 129 } 130 131 public bool isForceAllPartitions() { 132 return forceAllPartitions; 133 } 134 135 public void setForceAllPartitions(bool forceAllPartitions) { 136 this.forceAllPartitions = forceAllPartitions; 137 } 138 139 public SQLName getForcePartition() { 140 return forcePartition; 141 } 142 143 public void setForcePartition(SQLName x) { 144 if (x !is null) { 145 x.setParent(this); 146 } 147 this.forcePartition = x; 148 } 149 }