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.SQLSelectStatement; 17 18 import hunt.sql.ast.SQLCommentHint; 19 import hunt.sql.ast.SQLExpr; 20 import hunt.sql.ast.SQLObject; 21 import hunt.sql.ast.SQLStatementImpl; 22 import hunt.sql.visitor.SQLASTVisitor; 23 import hunt.sql.ast.statement.SQLSelect; 24 25 import hunt.collection; 26 import hunt.util.StringBuilder; 27 28 public class SQLSelectStatement : SQLStatementImpl { 29 30 protected SQLSelect select; 31 32 public this(){ 33 34 } 35 36 public this(string dbType){ 37 super (dbType); 38 } 39 40 public this(SQLSelect select){ 41 this.setSelect(select); 42 } 43 44 public this(SQLSelect select, string dbType){ 45 this(dbType); 46 this.setSelect(select); 47 } 48 49 public SQLSelect getSelect() { 50 return this.select; 51 } 52 53 public void setSelect(SQLSelect select) { 54 if (select !is null) { 55 select.setParent(this); 56 } 57 this.select = select; 58 } 59 60 override public void output(StringBuilder buf) { 61 this.select.output(buf); 62 } 63 64 override protected void accept0(SQLASTVisitor visitor) { 65 if (visitor.visit(this)) { 66 acceptChild(visitor, this.select); 67 } 68 visitor.endVisit(this); 69 } 70 71 override public SQLSelectStatement clone() { 72 SQLSelectStatement x = new SQLSelectStatement(); 73 if (select !is null) { 74 x.setSelect(select.clone()); 75 } 76 if (headHints !is null) { 77 foreach (SQLCommentHint h ; headHints) { 78 SQLCommentHint h2 = h.clone(); 79 h2.setParent(x); 80 x.headHints.add(h2); 81 } 82 } 83 return x; 84 } 85 86 override 87 public List!SQLObject getChildren() { 88 return Collections.singletonList!SQLObject(select); 89 } 90 91 public bool addWhere(SQLExpr where) { 92 return select.addWhere(where); 93 } 94 }