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.MySqlSubPartitionByList; 17 18 19 import hunt.collection; 20 import hunt.sql.ast.SQLObject; 21 22 import hunt.sql.ast.SQLExpr; 23 import hunt.sql.ast.SQLName; 24 import hunt.sql.ast.SQLSubPartitionBy; 25 import hunt.sql.ast.statement.SQLColumnDefinition; 26 import hunt.sql.dialect.mysql.ast.MySqlObject; 27 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor; 28 import hunt.sql.visitor.SQLASTVisitor; 29 30 public class MySqlSubPartitionByList : SQLSubPartitionBy , MySqlObject { 31 alias cloneTo = SQLSubPartitionBy.cloneTo; 32 private SQLExpr expr; 33 34 private List!(SQLColumnDefinition) columns; 35 36 this() 37 { 38 columns = new ArrayList!(SQLColumnDefinition)(); 39 } 40 41 42 override protected void accept0(SQLASTVisitor visitor) { 43 if (cast(MySqlASTVisitor)(visitor) !is null) { 44 accept0(cast(MySqlASTVisitor) visitor); 45 } else { 46 throw new Exception("not support visitor type : " ~ typeof(visitor).stringof); 47 } 48 } 49 50 override 51 public void accept0(MySqlASTVisitor visitor) { 52 if (visitor.visit(this)) { 53 acceptChild(visitor, expr); 54 acceptChild!SQLColumnDefinition(visitor, columns); 55 acceptChild(visitor, subPartitionsCount); 56 } 57 visitor.endVisit(this); 58 } 59 60 public SQLExpr getExpr() { 61 return expr; 62 } 63 64 public void setExpr(SQLExpr expr) { 65 if (expr !is null) { 66 expr.setParent(this); 67 } 68 this.expr = expr; 69 } 70 71 public List!(SQLColumnDefinition) getColumns() { 72 return columns; 73 } 74 75 public void addColumn(SQLColumnDefinition column) { 76 if (column !is null) { 77 column.setParent(this); 78 } 79 this.columns.add(column); 80 } 81 82 public void cloneTo(MySqlSubPartitionByList x) { 83 super.cloneTo(x); 84 if (expr !is null) { 85 x.setExpr(expr.clone()); 86 } 87 foreach(SQLColumnDefinition column ; columns) { 88 SQLColumnDefinition c2 = column.clone(); 89 c2.setParent(x); 90 x.columns.add(c2); 91 } 92 } 93 94 override public MySqlSubPartitionByList clone() { 95 MySqlSubPartitionByList x = new MySqlSubPartitionByList(); 96 cloneTo(x); 97 return x; 98 } 99 }