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.MySqlKey;
17 
18 import hunt.sql.ast.SQLExpr;
19 import hunt.sql.ast.SQLName;
20 import hunt.sql.ast.statement.SQLSelectOrderByItem;
21 import hunt.sql.ast.statement.SQLTableConstraint;
22 import hunt.sql.ast.statement.SQLUnique;
23 import hunt.sql.ast.statement.SQLUniqueConstraint;
24 import hunt.sql.dialect.mysql.ast.statement.MySqlAlterTableChangeColumn;
25 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor;
26 import hunt.sql.visitor.SQLASTVisitor;
27 import hunt.sql.util.DBType;
28 import hunt.sql.ast.SQLObject;
29 import hunt.collection;
30 
31 public class MySqlKey : SQLUnique /* , SQLUniqueConstraint */, SQLTableConstraint {
32 
33     alias cloneTo = SQLUnique.cloneTo;
34 
35     private string  indexType;
36 
37     private bool hasConstaint;
38 
39     private SQLExpr keyBlockSize;
40 
41     public this(){
42         dbType = DBType.MYSQL.name;
43     }
44 
45     
46     override  protected void accept0(SQLASTVisitor visitor) {
47         if (cast(MySqlASTVisitor)(visitor) !is null) {
48             accept0(cast(MySqlASTVisitor) visitor);
49         }
50     }
51 
52     protected void accept0(MySqlASTVisitor visitor) {
53         if (visitor.visit(this)) {
54             acceptChild(visitor, this.getName());
55             acceptChild!SQLSelectOrderByItem(visitor, this.getColumns());
56             acceptChild(visitor, name);
57         }
58         visitor.endVisit(this);
59     }
60 
61     public string getIndexType() {
62         return indexType;
63     }
64 
65     public void setIndexType(string indexType) {
66         this.indexType = indexType;
67     }
68 
69     public bool isHasConstaint() {
70         return hasConstaint;
71     }
72 
73     public void setHasConstaint(bool hasConstaint) {
74         this.hasConstaint = hasConstaint;
75     }
76 
77     public void cloneTo(MySqlKey x) {
78         super.cloneTo(x);
79         x.indexType = indexType;
80         x.hasConstaint = hasConstaint;
81         if (keyBlockSize !is null) {
82             this.setKeyBlockSize(keyBlockSize.clone());
83         }
84     }
85 
86     override public MySqlKey clone() {
87         MySqlKey x = new MySqlKey();
88         cloneTo(x);
89         return x;
90     }
91 
92     public SQLExpr getKeyBlockSize() {
93         return keyBlockSize;
94     }
95 
96     public void setKeyBlockSize(SQLExpr x) {
97         if (x !is null) {
98             x.setParent(this);
99         }
100         this.keyBlockSize = x;
101     }
102 }