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.SQLUnionQueryTableSource;
17 
18 import hunt.sql.visitor.SQLASTVisitor;
19 import hunt.sql.ast.statement.SQLTableSourceImpl;
20 import hunt.sql.ast.statement.SQLUnionQuery;
21 import hunt.collection;
22 import hunt.util.StringBuilder;
23 
24 public class SQLUnionQueryTableSource : SQLTableSourceImpl {
25 
26     private SQLUnionQuery _union;
27 
28     public this(){
29 
30     }
31 
32     public this(string _alias){
33         super(_alias);
34     }
35 
36     public this(SQLUnionQuery _union, string _alias){
37         super(_alias);
38         this.setUnion(_union);
39     }
40 
41     public this(SQLUnionQuery _union){
42         this.setUnion(_union);
43     }
44 
45     
46     override  protected void accept0(SQLASTVisitor visitor) {
47         if (visitor.visit(this)) {
48             acceptChild(visitor, _union);
49         }
50         visitor.endVisit(this);
51     }
52 
53     override public void output(StringBuilder buf) {
54         buf.append("(");
55         this._union.output(buf);
56         buf.append(")");
57     }
58 
59     public SQLUnionQuery getUnion() {
60         return _union;
61     }
62 
63     public void setUnion(SQLUnionQuery _union) {
64         if (_union !is null) {
65             _union.setParent(this);
66         }
67         this._union = _union;
68     }
69 }