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.MysqlForeignKey;
17 
18 import hunt.sql.ast.SQLName;
19 import hunt.sql.ast.statement.SQLForeignKeyImpl;
20 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor;
21 import hunt.sql.visitor.SQLASTVisitor;
22 import hunt.sql.util.DBType;
23 import hunt.collection;
24 import hunt.sql.ast.SQLObject;
25 
26 public class MysqlForeignKey : SQLForeignKeyImpl {
27     private SQLName  indexName;
28     private bool  hasConstraint;
29     private Match    referenceMatch;
30     protected Option onUpdate;
31     protected Option onDelete;
32 
33     public this() {
34         dbType = DBType.MYSQL.name;
35     }
36 
37     public SQLName getIndexName() {
38         return indexName;
39     }
40 
41     public void setIndexName(SQLName indexName) {
42         this.indexName = indexName;
43     }
44 
45     public bool isHasConstraint() {
46         return hasConstraint;
47     }
48 
49     public void setHasConstraint(bool hasConstraint) {
50         this.hasConstraint = hasConstraint;
51     }
52 
53     
54     override  protected void accept0(SQLASTVisitor visitor) {
55         if (cast(MySqlASTVisitor)(visitor) !is null) {
56             accept0(cast(MySqlASTVisitor) visitor);
57         }
58     }
59 
60     protected void accept0(MySqlASTVisitor visitor) {
61         if (visitor.visit(this)) {
62             acceptChild(visitor, this.getName());
63             acceptChild(visitor, this.getReferencedTableName());
64             acceptChild!SQLName(visitor, this.getReferencingColumns());
65             acceptChild!SQLName(visitor, this.getReferencedColumns());
66 
67             acceptChild(visitor, indexName);
68         }
69         visitor.endVisit(this);
70     }
71 
72     override public MysqlForeignKey clone() {
73         MysqlForeignKey x = new MysqlForeignKey();
74         cloneTo(x);
75 
76         x.referenceMatch = referenceMatch;
77         x.onUpdate = onUpdate;
78         x.onDelete = onDelete;
79 
80         return x;
81     }
82 
83     public Match getReferenceMatch() {
84         return referenceMatch;
85     }
86 
87     public void setReferenceMatch(Match referenceMatch) {
88         this.referenceMatch = referenceMatch;
89     }
90 
91     public Option getOnUpdate() {
92         return onUpdate;
93     }
94 
95     public void setOnUpdate(Option onUpdate) {
96         this.onUpdate = onUpdate;
97     }
98 
99     public Option getOnDelete() {
100         return onDelete;
101     }
102 
103     public void setOnDelete(Option onDelete) {
104         this.onDelete = onDelete;
105     }
106 
107 }