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.SQLSelectGroupByClause;
17 
18 
19 import hunt.collection;
20 
21 import hunt.sql.ast.SQLExpr;
22 import hunt.sql.ast.SQLObjectImpl;
23 import hunt.sql.visitor.SQLASTVisitor;
24 import hunt.sql.ast.SQLObject;
25 
26 public class SQLSelectGroupByClause : SQLObjectImpl {
27 
28     private  List!SQLExpr items;
29     private SQLExpr             having;
30     private bool             withRollUp = false;
31     private bool             withCube = false;
32 
33     public this(){
34         items = new ArrayList!SQLExpr();
35     }
36 
37     override  protected void accept0(SQLASTVisitor visitor) {
38         if (visitor.visit(this)) {
39             acceptChild!SQLExpr(visitor, this.items);
40             acceptChild(visitor, this.having);
41         }
42 
43         visitor.endVisit(this);
44     }
45     
46     public bool isWithRollUp() {
47         return withRollUp;
48     }
49 
50     public void setWithRollUp(bool withRollUp) {
51         this.withRollUp = withRollUp;
52     }
53     
54     
55     public bool isWithCube() {
56         return withCube;
57     }
58 
59     public void setWithCube(bool withCube) {
60         this.withCube = withCube;
61     }
62 
63     public SQLExpr getHaving() {
64         return this.having;
65     }
66 
67     public void setHaving(SQLExpr having) {
68         if (having !is null) {
69             having.setParent(this);
70         }
71         
72         this.having = having;
73     }
74 
75     public List!SQLExpr getItems() {
76         return this.items;
77     }
78 
79     public void addItem(SQLExpr sqlExpr) {
80         if (sqlExpr !is null) {
81             sqlExpr.setParent(this);
82             this.items.add(sqlExpr);
83         }
84     }
85 
86     override public SQLSelectGroupByClause clone() {
87         SQLSelectGroupByClause x = new SQLSelectGroupByClause();
88         foreach (SQLExpr item ; items) {
89             SQLExpr item2 = item.clone();
90             item2.setParent(x);
91             x.items.add(item2);
92         }
93         if (having !is null) {
94             x.setHaving(having.clone());
95         }
96         x.withRollUp = withRollUp;
97         x.withCube = withCube;
98         return x;
99     }
100 }