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