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.ast.statement.SQLColumnReference;
17 
18 import hunt.collection;
19 
20 import hunt.sql.ast.SQLName;
21 import hunt.sql.visitor.SQLASTVisitor;
22 import hunt.sql.ast.statement.SQLConstraintImpl;
23 import hunt.sql.ast.statement.SQLColumnConstraint;
24 import hunt.sql.ast.statement.SQLForeignKeyImpl;
25 
26 public class SQLColumnReference : SQLConstraintImpl , SQLColumnConstraint {
27 
28     private SQLName       table;
29     private List!SQLName columns;
30 
31     private SQLForeignKeyImpl.Match referenceMatch;
32     protected SQLForeignKeyImpl.Option onUpdate;
33     protected SQLForeignKeyImpl.Option onDelete;
34 
35     public this() {
36         columns = new ArrayList!SQLName();
37     }
38 
39     
40     override  protected void accept0(SQLASTVisitor visitor) {
41         if (visitor.visit(this)) {
42             acceptChild(visitor, this.getName());
43         }
44         visitor.endVisit(this);
45     }
46 
47     public SQLName getTable() {
48         return table;
49     }
50 
51     public void setTable(SQLName table) {
52         this.table = table;
53     }
54 
55     public List!SQLName getColumns() {
56         return columns;
57     }
58 
59     public void setColumns(List!SQLName columns) {
60         this.columns = columns;
61     }
62 
63     override public SQLColumnReference clone() {
64         SQLColumnReference x = new SQLColumnReference();
65 
66         super.cloneTo(x);
67 
68         if (table !is null) {
69             x.setTable(table.clone());
70         }
71 
72         foreach (SQLName column ; columns) {
73             SQLName columnCloned = column.clone();
74             columnCloned.setParent(x);
75             x.columns.add(columnCloned);
76         }
77 
78         x.referenceMatch = referenceMatch;
79         x.onUpdate = onUpdate;
80         x.onDelete = onDelete;
81 
82         return x;
83     }
84 
85     public SQLForeignKeyImpl.Match getReferenceMatch() {
86         return referenceMatch;
87     }
88 
89     public void setReferenceMatch(SQLForeignKeyImpl.Match referenceMatch) {
90         this.referenceMatch = referenceMatch;
91     }
92 
93     public SQLForeignKeyImpl.Option getOnUpdate() {
94         return onUpdate;
95     }
96 
97     public void setOnUpdate(SQLForeignKeyImpl.Option onUpdate) {
98         this.onUpdate = onUpdate;
99     }
100 
101     public SQLForeignKeyImpl.Option getOnDelete() {
102         return onDelete;
103     }
104 
105     public void setOnDelete(SQLForeignKeyImpl.Option onDelete) {
106         this.onDelete = onDelete;
107     }
108 }