001package gudusoft.gsqlparser.stmt.db2;
002
003import gudusoft.gsqlparser.*;
004import gudusoft.gsqlparser.nodes.*;
005import gudusoft.gsqlparser.stmt.TStoredProcedureSqlStatement;
006
007/**
008 * DB2 create procedure
009 * @deprecated As of v2.5.1.7, replaced by {@link gudusoft.gsqlparser.stmt.TCreateProcedureStmt}
010 */
011public class TDb2CreateProcedure extends TStoredProcedureSqlStatement{
012     public TDb2CreateProcedure (EDbVendor dbvendor){
013        super(dbvendor);
014        sqlstatementtype = ESqlStatementType.sstcreateprocedure ;
015        }
016
017
018    void buildsql() {
019    }
020
021    void clear() {
022    }
023
024    String getasprettytext() {
025        return "";
026    }
027
028    void iterate(TVisitorAbs pvisitor) {
029    }
030
031    public TObjectName getStoredProcedureName(){
032        return procedureName;
033    }
034
035    private TObjectName procedureName = null;
036
037    public TObjectName getProcedureName() {
038        return procedureName;
039    }
040
041
042    public int doParseStatement(TCustomSqlStatement psql) {
043        if (rootNode == null) return -1;
044        TCreateProcedureSqlNode createProcedureNode = (TCreateProcedureSqlNode)rootNode;
045        TCompoundSqlNode compoundSqlNode = createProcedureNode.getCompoundSqls();
046
047        super.doParseStatement(psql);
048
049        procedureName = createProcedureNode.getProcedureName();
050        this.setParameterDeclarations(createProcedureNode.getParameters());
051
052        // push parameterDeclarations into symbolTable
053        if (this.getParameterDeclarations() != null){
054            for(int i=0;i< this.getParameterDeclarations().size();i++){
055               this.getTopStatement().getSymbolTable().push( new TSymbolTableItem(TObjectName.ttobjParameter,this, this.getParameterDeclarations().getParameterDeclarationItem(i)));
056            }
057        }
058
059        if (compoundSqlNode != null){
060            if (compoundSqlNode.getDeclareStmts() != null){
061               compoundSqlNode.getDeclareStmts().doParse(this,ESqlClause.unknown);
062
063                // push variable declare into symbolTable, and add to declareStatements
064                for(int i=0;i<compoundSqlNode.getDeclareStmts().size();i++){
065                   this.getTopStatement().getSymbolTable().push( new TSymbolTableItem(TObjectName.ttobjVariable,this,compoundSqlNode.getDeclareStmts().getStatementSqlNode(i).getStmt() ));
066                   this.getDeclareStatements().add(compoundSqlNode.getDeclareStmts().getStatementSqlNode(i).getStmt());
067                }
068            }
069
070            if (compoundSqlNode.getStmts() != null){
071               compoundSqlNode.getStmts().doParse(this,ESqlClause.unknown);
072
073                for(int i= 0; i<compoundSqlNode.getStmts().size();i++){
074                  this.getBodyStatements().add(compoundSqlNode.getStmts().getStatementSqlNode(i).getStmt());
075                }
076            }
077    
078            if (compoundSqlNode.getDeclareStmts() != null){
079                // pop variable declare from symbolTable
080                for(int i=0;i<compoundSqlNode.getDeclareStmts().size();i++){
081                   this.getTopStatement().getSymbolTable().pop();
082                }
083            }
084        }
085
086        // pop parameterDeclarations from symbolTable
087        if (this.getParameterDeclarations() != null){
088            for(int i=0;i< this.getParameterDeclarations().size();i++){
089               this.getTopStatement().getSymbolTable().pop();
090            }
091        }
092
093       return 0;
094   }
095
096    public void accept(TParseTreeVisitor v){
097        v.preVisit(this);
098
099        v.postVisit(this);
100    }
101
102    public void acceptChildren(TParseTreeVisitor v){
103        v.preVisit(this);
104
105        if (this.getParameterDeclarations() != null) getParameterDeclarations().accept(v);
106        if (this.getDeclareStatements().size() > 0) this.getDeclareStatements().accept(v);
107        if ( this.getBodyStatements().size() > 0) getBodyStatements().accept(v);
108
109        v.postVisit(this);
110    }
111
112    public void setProcedureName(TObjectName procedureName) {
113        this.procedureName = procedureName;
114    }
115}