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.SQLAlterTableAddIndex; 17 18 import hunt.collection; 19 20 import hunt.sql.ast.SQLExpr; 21 import hunt.sql.ast.SQLName; 22 import hunt.sql.ast.SQLObjectImpl; 23 import hunt.sql.dialect.mysql.ast.MySqlKey; 24 import hunt.sql.dialect.mysql.ast.MySqlUnique; 25 import hunt.sql.dialect.mysql.ast.statement.MySqlTableIndex; 26 import hunt.sql.visitor.SQLASTVisitor; 27 import hunt.sql.ast.statement.SQLAlterTableItem; 28 import hunt.sql.ast.statement.SQLSelectOrderByItem; 29 import hunt.sql.ast.SQLObject; 30 31 32 public class SQLAlterTableAddIndex : SQLObjectImpl , SQLAlterTableItem { 33 34 private bool unique; 35 36 private SQLName name; 37 38 private List!SQLSelectOrderByItem items; 39 40 private string type; 41 42 private string using; 43 44 private bool key = false; 45 46 protected SQLExpr comment; 47 48 this() 49 { 50 items = new ArrayList!SQLSelectOrderByItem(); 51 } 52 override protected void accept0(SQLASTVisitor visitor) { 53 if (visitor.visit(this)) { 54 acceptChild(visitor, getName()); 55 acceptChild!SQLSelectOrderByItem(visitor, getItems()); 56 } 57 visitor.endVisit(this); 58 } 59 60 public bool isUnique() { 61 return unique; 62 } 63 64 public void setUnique(bool unique) { 65 this.unique = unique; 66 } 67 68 public List!SQLSelectOrderByItem getItems() { 69 return items; 70 } 71 72 public void addItem(SQLSelectOrderByItem item) { 73 if (item !is null) { 74 item.setParent(this); 75 } 76 this.items.add(item); 77 } 78 79 public SQLName getName() { 80 return name; 81 } 82 83 public void setName(SQLName name) { 84 this.name = name; 85 } 86 87 public string getType() { 88 return type; 89 } 90 91 public void setType(string type) { 92 this.type = type; 93 } 94 95 public string getUsing() { 96 return using; 97 } 98 99 public void setUsing(string using) { 100 this.using = using; 101 } 102 103 public bool isKey() { 104 return key; 105 } 106 107 public void setKey(bool key) { 108 this.key = key; 109 } 110 111 public void cloneTo(MySqlTableIndex x) { 112 if (name !is null) { 113 x.setName(name.clone()); 114 } 115 foreach (SQLSelectOrderByItem item ; items) { 116 SQLSelectOrderByItem item2 = item.clone(); 117 item2.setParent(x); 118 x.getColumns().add(item); 119 } 120 x.setIndexType(type); 121 } 122 123 public void cloneTo(MySqlKey x) { 124 if (name !is null) { 125 x.setName(name.clone()); 126 } 127 foreach (SQLSelectOrderByItem item ; items) { 128 SQLSelectOrderByItem item2 = item.clone(); 129 item2.setParent(x); 130 x.getColumns().add(item); 131 } 132 x.setIndexType(type); 133 } 134 135 public SQLExpr getComment() { 136 return comment; 137 } 138 139 public void setComment(SQLExpr comment) { 140 if (comment !is null) { 141 comment.setParent(this); 142 } 143 this.comment = comment; 144 } 145 }