001package gudusoft.gsqlparser.stmt.mdx;
002
003import gudusoft.gsqlparser.TCustomSqlStatement;
004import gudusoft.gsqlparser.EDbVendor;
005import gudusoft.gsqlparser.ESqlStatementType;
006import gudusoft.gsqlparser.nodes.TPTNodeList;
007import gudusoft.gsqlparser.nodes.TParseTreeVisitor;
008import gudusoft.gsqlparser.nodes.mdx.*;
009
010/**
011 * MDX, select statement.
012 *
013 */
014public class TMdxSelect extends TCustomSqlStatement {
015
016    private TMdxSelectNode selectNode;
017    private TMdxSelect subQuery;
018    private TMdxCreateMeasure withMeasure;
019
020    public TMdxSelect(EDbVendor dbvendor) {
021        super(dbvendor);
022        sqlstatementtype = ESqlStatementType.sstmdxselect;
023    }
024
025    public TMdxCreateMeasure getWithMeasure() {
026        return withMeasure;
027    }
028
029    public int doParseStatement(TCustomSqlStatement psql) {
030        if (rootNode == null) return -1;
031        super.doParseStatement(psql);
032        selectNode = (TMdxSelectNode)rootNode;
033
034        if (selectNode.getMeasureNode() != null){
035            withMeasure = new TMdxCreateMeasure(EDbVendor.dbvmdx);
036            withMeasure.rootNode = selectNode.getMeasureNode();
037            withMeasure.doParseStatement(this);
038        }
039
040        if (selectNode.getSubQuery() != null){
041            subQuery = new TMdxSelect(EDbVendor.dbvmdx);
042            subQuery.rootNode = selectNode.getSubQuery();
043            subQuery.doParseStatement(this);
044        }
045
046        return 0;
047    }
048
049    public TPTNodeList<TMdxWithNode> getWiths(){
050        return selectNode.getWiths();
051    }
052
053    /**
054     * list of query axis clause in the select list
055     *
056     * @return list of query axis clause
057     */
058    public TPTNodeList <TMdxAxisNode> getAxes(){
059        return selectNode.getAxes();
060    }
061
062    public TMdxIdentifierNode getCube(){
063        return selectNode.getCube();
064    }
065
066    public TMdxSelect getSubQuery(){
067        return subQuery;
068    }
069
070    public TMdxWhereNode getWhere(){
071        return selectNode.getWhere();
072    }
073
074    public TPTNodeList <TMdxExpNode> getCellProps(){
075        return selectNode.getCellProps();
076    }
077
078    public void accept(TParseTreeVisitor v){
079        v.preVisit(this);
080
081        v.postVisit(this);
082    }
083
084    public void acceptChildren(TParseTreeVisitor v){
085        v.preVisit(this);
086
087        if (getWiths() != null){
088            getWiths().acceptChildren(v);
089        }
090
091        if (getAxes() != null){
092            getAxes().acceptChildren(v);
093        }
094
095        if (getSubQuery() != null){
096            getSubQuery().acceptChildren(v);
097        }else if (getCube() != null){
098            getCube().acceptChildren(v);
099        }
100
101        if (getWhere() != null){
102            getWhere().acceptChildren(v);
103        }
104
105        if (getCellProps() != null){
106            getCellProps().acceptChildren(v);
107        }
108
109        v.postVisit(this);
110    }
111}