001package gudusoft.gsqlparser.stmt; 002 003import gudusoft.gsqlparser.EDbObjectType; 004import gudusoft.gsqlparser.EDbVendor; 005import gudusoft.gsqlparser.ESqlStatementType; 006import gudusoft.gsqlparser.TCustomSqlStatement; 007import gudusoft.gsqlparser.nodes.*; 008 009 010public class TRenameStmt extends TCustomSqlStatement { 011 012 private TObjectName oldName; 013 private TObjectName newName; 014 private EDbObjectType objectType = EDbObjectType.table; 015 016 private TPTNodeList<TObjectNameList> renamedObjectList; 017 018 /** 019 * The list of the table name need to be renamed. 020 * {{oldTableName, newTableName},...} 021 * Each element in this list include a pair of old and new table name. 022 * The first element in TObjectNameList is old table name, the second element in TObjectNameList is the new table name. 023 * @return list of the table name 024 */ 025 public TPTNodeList<TObjectNameList> getRenamedObjectList() { 026 return renamedObjectList; 027 } 028 029 public TRenameStmt(EDbVendor dbvendor) { 030 super(dbvendor); 031 sqlstatementtype = ESqlStatementType.sstrename; 032 } 033 034 public TObjectName getNewName() { 035 return newName; 036 } 037 038 public EDbObjectType getObjectType() { 039 return objectType; 040 } 041 042 public TObjectName getOldName() { 043 return oldName; 044 } 045 046 public int doParseStatement(TCustomSqlStatement psql) { 047 if (rootNode == null) return -1; 048 super.doParseStatement(psql); 049 050 TDummy dummy = (TDummy)rootNode; 051 objectType = dummy.objectType; 052 053 if (dummy.objectNameListTPTNodeList != null){ 054 renamedObjectList = dummy.objectNameListTPTNodeList; 055 for(int k=0; k<renamedObjectList.size();k++){ 056 renamedObjectList.getElement(k).getObjectName(0).setDbObjectType(objectType); 057 renamedObjectList.getElement(k).getObjectName(1).setDbObjectType(objectType); 058 } 059 oldName = renamedObjectList.getElement(0).getObjectName(0); 060 newName = renamedObjectList.getElement(0).getObjectName(1); 061 }else{ 062 oldName = (TObjectName)(dummy.node1); 063 newName = (TObjectName)(dummy.node2); 064 oldName.setDbObjectType(this.dbvendor, objectType); 065 newName.setDbObjectType(this.dbvendor, objectType); 066 } 067 068 return 0; 069 } 070 071 public void accept(TParseTreeVisitor v){ 072 v.preVisit(this); 073 v.postVisit(this); 074 } 075 076 public void setOldName(TObjectName oldName) { 077 this.oldName = oldName; 078 } 079 080 public void setNewName(TObjectName newName) { 081 this.newName = newName; 082 } 083 084 public void setObjectType(EDbObjectType objectType) { 085 this.objectType = objectType; 086 } 087 088 public void acceptChildren(TParseTreeVisitor v){ 089 v.preVisit(this); 090 v.postVisit(this); 091 } 092 093}