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.postgresql.ast.stmt.PGDeleteStatement;
17 
18 
19 import hunt.collection;
20 
21 import hunt.sql.ast.SQLName;
22 import hunt.sql.ast.statement.SQLDeleteStatement;
23 import hunt.sql.ast.statement.SQLWithSubqueryClause;
24 import hunt.sql.dialect.postgresql.visitor.PGASTVisitor;
25 import hunt.sql.visitor.SQLASTVisitor;
26 import hunt.sql.util.DBType;
27 import hunt.sql.dialect.postgresql.ast.stmt.PGSQLStatement;
28 
29 public class PGDeleteStatement : SQLDeleteStatement , PGSQLStatement {
30 
31     private bool       returning;
32 
33     public this() {
34         super (DBType.POSTGRESQL.name);
35     }
36 
37     public bool isReturning() {
38         return returning;
39     }
40 
41     public void setReturning(bool returning) {
42         this.returning = returning;
43     }
44 
45     override public string getAlias() {
46         if (tableSource is null) {
47             return null;
48         }
49         return tableSource.getAlias();
50     }
51 
52     override public void setAlias(string alias_p) {
53         this.tableSource.setAlias(alias_p);
54     }
55 
56     override  protected void accept0(SQLASTVisitor visitor) {
57         // accept0(cast(PGASTVisitor) visitor);
58         if (cast(PGASTVisitor)(visitor) !is null) {
59             accept0(cast(PGASTVisitor) visitor);
60         } else {
61             super.accept0(visitor);
62         }
63     }
64 
65     override
66     public void accept0(PGASTVisitor visitor) {
67         if (visitor.visit(this)) {
68             acceptChild(visitor, _with);
69             acceptChild(visitor, tableSource);
70             acceptChild(visitor, using);
71             acceptChild(visitor, where);
72         }
73 
74         visitor.endVisit(this);
75     }
76 
77     override public PGDeleteStatement clone() {
78         PGDeleteStatement x = new PGDeleteStatement();
79         cloneTo(x);
80 
81         x.returning = returning;
82 
83         return x;
84     }
85 }