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.MySqlPartitionByKey; 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.SQLPartitionBy; 25 import hunt.sql.dialect.mysql.ast.MySqlObject; 26 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor; 27 import hunt.sql.visitor.SQLASTVisitor; 28 29 public class MySqlPartitionByKey : SQLPartitionBy , MySqlObject { 30 31 alias cloneTo = SQLPartitionBy.cloneTo; 32 33 private short algorithm = 2; 34 35 public short getAlgorithm() { 36 return algorithm; 37 } 38 39 public void setAlgorithm(short algorithm) { 40 this.algorithm = algorithm; 41 } 42 43 44 override protected void accept0(SQLASTVisitor visitor) { 45 if (cast(MySqlASTVisitor)(visitor) !is null) { 46 accept0(cast(MySqlASTVisitor) visitor); 47 } else { 48 throw new Exception("not support visitor type : " ~ typeof(visitor).stringof); 49 } 50 } 51 52 override 53 public void accept0(MySqlASTVisitor visitor) { 54 if (visitor.visit(this)) { 55 acceptChild(visitor, cast(List!(SQLObject))columns); 56 acceptChild(visitor, partitionsCount); 57 acceptChild(visitor, cast(List!(SQLObject))(getPartitions())); 58 acceptChild(visitor, subPartitionBy); 59 } 60 visitor.endVisit(this); 61 } 62 63 public void cloneTo(MySqlPartitionByKey x) { 64 super.cloneTo(x); 65 foreach(SQLExpr column ; columns) { 66 SQLExpr c2 = column.clone(); 67 c2.setParent(x); 68 x.columns.add(c2); 69 } 70 x.setAlgorithm(algorithm); 71 } 72 73 override public MySqlPartitionByKey clone() { 74 MySqlPartitionByKey x = new MySqlPartitionByKey(); 75 cloneTo(x); 76 return x; 77 } 78 }