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.MySqlInsertStatement; 17 18 19 import hunt.collection; 20 import hunt.sql.ast.SQLObject; 21 22 import hunt.sql.ast.SQLExpr; 23 import hunt.sql.ast.statement.SQLInsertStatement; 24 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor; 25 import hunt.sql.dialect.mysql.visitor.MySqlOutputVisitor; 26 import hunt.sql.visitor.SQLASTVisitor; 27 import hunt.sql.util.DBType; 28 import hunt.sql.ast.SQLObjectImpl; 29 import hunt.util.StringBuilder; 30 31 public class MySqlInsertStatement : SQLInsertStatement { 32 33 alias cloneTo = SQLInsertStatement.cloneTo; 34 35 private bool lowPriority = false; 36 private bool delayed = false; 37 private bool highPriority = false; 38 private bool ignore = false; 39 private bool rollbackOnFail = false; 40 41 private List!(SQLExpr) duplicateKeyUpdate; 42 43 this() { 44 duplicateKeyUpdate = new ArrayList!(SQLExpr)(); 45 dbType = DBType.MYSQL.name; 46 } 47 48 public void cloneTo(MySqlInsertStatement x) { 49 super.cloneTo(x); 50 x.lowPriority = lowPriority; 51 x.delayed = delayed; 52 x.highPriority = highPriority; 53 x.ignore = ignore; 54 x.rollbackOnFail = rollbackOnFail; 55 56 foreach(SQLExpr e ; duplicateKeyUpdate) { 57 SQLExpr e2 = e.clone(); 58 e2.setParent(x); 59 x.duplicateKeyUpdate.add(e2); 60 } 61 } 62 63 public List!(SQLExpr) getDuplicateKeyUpdate() { 64 return duplicateKeyUpdate; 65 } 66 67 public bool isLowPriority() { 68 return lowPriority; 69 } 70 71 public void setLowPriority(bool lowPriority) { 72 this.lowPriority = lowPriority; 73 } 74 75 public bool isDelayed() { 76 return delayed; 77 } 78 79 public void setDelayed(bool delayed) { 80 this.delayed = delayed; 81 } 82 83 public bool isHighPriority() { 84 return highPriority; 85 } 86 87 public void setHighPriority(bool highPriority) { 88 this.highPriority = highPriority; 89 } 90 91 public bool isIgnore() { 92 return ignore; 93 } 94 95 public void setIgnore(bool ignore) { 96 this.ignore = ignore; 97 } 98 99 public bool isRollbackOnFail() { 100 return rollbackOnFail; 101 } 102 103 public void setRollbackOnFail(bool rollbackOnFail) { 104 this.rollbackOnFail = rollbackOnFail; 105 } 106 107 108 override protected void accept0(SQLASTVisitor visitor) { 109 if (cast(MySqlASTVisitor)(visitor) !is null) { 110 accept0(cast(MySqlASTVisitor) visitor); 111 } else { 112 super.accept0(visitor); 113 } 114 } 115 116 override public void output(StringBuilder buf) { 117 new MySqlOutputVisitor(buf).visit(this); 118 } 119 120 protected void accept0(MySqlASTVisitor visitor) { 121 if (visitor.visit(this)) { 122 this.acceptChild(visitor, getTableSource()); 123 this.acceptChild!SQLExpr(visitor, getColumns()); 124 this.acceptChild!ValuesClause(visitor, getValuesList()); 125 this.acceptChild(visitor, getQuery()); 126 this.acceptChild!SQLExpr(visitor, getDuplicateKeyUpdate()); 127 } 128 129 visitor.endVisit(this); 130 } 131 132 override public SQLInsertStatement clone() { 133 MySqlInsertStatement x = new MySqlInsertStatement(); 134 cloneTo(x); 135 return x; 136 } 137 }