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.SQLReplaceStatement; 17 18 import hunt.sql.ast.SQLExpr; 19 import hunt.sql.ast.SQLName; 20 import hunt.sql.ast.SQLStatementImpl; 21 import hunt.sql.ast.expr.SQLQueryExpr; 22 import hunt.sql.visitor.SQLASTVisitor; 23 import hunt.sql.ast.statement.SQLExprTableSource; 24 import hunt.sql.ast.SQLObjectImpl; 25 import hunt.sql.ast.SQLObject; 26 27 28 import hunt.collection; 29 30 public class SQLReplaceStatement : SQLStatementImpl { 31 protected bool lowPriority = false; 32 protected bool delayed = false; 33 34 protected SQLExprTableSource tableSource; 35 protected List!SQLExpr columns; 36 protected List!ValuesClause valuesList; 37 protected SQLQueryExpr query; 38 39 this() 40 { 41 columns = new ArrayList!SQLExpr(); 42 valuesList = new ArrayList!ValuesClause(); 43 } 44 45 public SQLName getTableName() { 46 if (tableSource is null) { 47 return null; 48 } 49 50 return cast(SQLName) tableSource.getExpr(); 51 } 52 53 public void setTableName(SQLName tableName) { 54 this.setTableSource(new SQLExprTableSource(tableName)); 55 } 56 57 public SQLExprTableSource getTableSource() { 58 return tableSource; 59 } 60 61 public void setTableSource(SQLExprTableSource tableSource) { 62 if (tableSource !is null) { 63 tableSource.setParent(this); 64 } 65 this.tableSource = tableSource; 66 } 67 68 public List!SQLExpr getColumns() { 69 return columns; 70 } 71 72 public void addColumn(SQLExpr column) { 73 if (column !is null) { 74 column.setParent(this); 75 } 76 this.columns.add(column); 77 } 78 79 public bool isLowPriority() { 80 return lowPriority; 81 } 82 83 public void setLowPriority(bool lowPriority) { 84 this.lowPriority = lowPriority; 85 } 86 87 public bool isDelayed() { 88 return delayed; 89 } 90 91 public void setDelayed(bool delayed) { 92 this.delayed = delayed; 93 } 94 95 public SQLQueryExpr getQuery() { 96 return query; 97 } 98 99 public void setQuery(SQLQueryExpr query) { 100 if (query !is null) { 101 query.setParent(this); 102 } 103 this.query = query; 104 } 105 106 public List!ValuesClause getValuesList() { 107 return valuesList; 108 } 109 110 111 override protected void accept0(SQLASTVisitor visitor) { 112 if (visitor.visit(this)) { 113 acceptChild(visitor, tableSource); 114 acceptChild!SQLExpr(visitor, columns); 115 acceptChild!ValuesClause(visitor, valuesList); 116 acceptChild(visitor, query); 117 } 118 visitor.endVisit(this); 119 } 120 }