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.SQLAlterTableRename; 17 18 import hunt.sql.ast.SQLExpr; 19 import hunt.sql.ast.SQLName; 20 import hunt.sql.ast.SQLObjectImpl; 21 import hunt.sql.ast.expr.SQLIdentifierExpr; 22 import hunt.sql.visitor.SQLASTVisitor; 23 import hunt.sql.ast.statement.SQLAlterTableItem; 24 import hunt.sql.ast.statement.SQLExprTableSource; 25 26 public class SQLAlterTableRename : SQLObjectImpl , SQLAlterTableItem { 27 28 protected SQLExprTableSource to; 29 30 public this() { 31 32 } 33 34 public this(SQLExpr to) { 35 this.setTo(to); 36 } 37 38 public this(string to) { 39 this.setTo(to); 40 } 41 42 public SQLExprTableSource getTo() { 43 return to; 44 } 45 46 public SQLName getToName() { 47 if (to is null) { 48 return null; 49 } 50 51 SQLExpr expr = to.expr; 52 53 if ( cast(SQLName)expr !is null) { 54 return cast(SQLName) expr; 55 } 56 57 return null; 58 } 59 60 public void setTo(SQLExprTableSource to) { 61 if (to !is null) { 62 to.setParent(this); 63 } 64 this.to = to; 65 } 66 67 public void setTo(string to) { 68 this.setTo(new SQLIdentifierExpr(to)); 69 } 70 71 public void setTo(SQLExpr to) { 72 this.setTo(new SQLExprTableSource(to)); 73 } 74 75 override protected void accept0(SQLASTVisitor visitor) { 76 if (visitor.visit(this)) { 77 acceptChild(visitor, to); 78 } 79 visitor.endVisit(this); 80 } 81 82 }