Package com.mysql.clusterj.jdbc.antlr.node

Examples of com.mysql.clusterj.jdbc.antlr.node.WhereNode


        // get the root of the tree
        int tokenType = root.getType();
        // perform command-specific actions
        String tableName = "";
        CommonTree tableNode;
        WhereNode whereNode;
        List<String> columnNames = new ArrayList<String>();
        Dictionary dictionary;
        DomainTypeHandlerImpl<?> domainTypeHandler;
        QueryDomainTypeImpl<?> queryDomainType = null;
        switch (tokenType) {
            case MySQL51Parser.INSERT:
                tableNode = (CommonTree)root.getFirstChildWithType(MySQL51Parser.TABLE);
                tableName = getTableName(tableNode);
                getSession();
                dictionary = session.getDictionary();
                domainTypeHandler = getDomainTypeHandler(tableName, dictionary);
                CommonTree insertValuesNode = (CommonTree)root.getFirstChildWithType(MySQL51Parser.INSERT_VALUES);
                CommonTree columnsNode = (CommonTree)insertValuesNode.getFirstChildWithType(MySQL51Parser.COLUMNS);
                List<CommonTree> fields = columnsNode.getChildren();
                for (CommonTree field: fields) {
                    columnNames.add(getColumnName(field));
                }
                if (logger.isDetailEnabled()) logger.detail(
                        "StatementInterceptorImpl.preProcess parse result INSERT INTO " + tableName
                        + " COLUMNS " + columnNames);
                result = new SQLExecutor.Insert(domainTypeHandler, columnNames);
                break;
            case MySQL51Parser.SELECT:
                CommonTree fromNode = (CommonTree)root.getFirstChildWithType(MySQL51Parser.FROM);
                if (fromNode == null) {
                    // no from clause; cannot handle this case so return a do-nothing ParsedSQL
                    result = new SQLExecutor.Noop();
                    break;
                }
                try {
                    // this currently handles only FROM clauses with a single table
                    tableNode = (CommonTree) fromNode.getFirstChildWithType(MySQL51Parser.TABLE);
                    tableName = getTableName(tableNode);
                } catch (Exception e) {
                    // trouble with the FROM clause; log the SQL statement and the parser output
                    logger.info("Problem with FROM clause in SQL statement: " + preparedSql);
                    logger.info(walk(root));
                    result = new SQLExecutor.Noop();
                    break;
                }
                getSession();
                dictionary = session.getDictionary();
                domainTypeHandler = getDomainTypeHandler(tableName, dictionary);
                columnsNode = (CommonTree)root.getFirstChildWithType(MySQL51Parser.COLUMNS);
                List<CommonTree> selectExprNodes = columnsNode.getChildren();
                for (CommonTree selectExprNode: selectExprNodes) {
                    columnNames.add(getColumnName(getFieldNode(selectExprNode)));
                }
                String whereType = "empty";
                if (logger.isDetailEnabled()) logger.detail(
                        "SELECT FROM " + tableName
                        + " COLUMNS " + columnNames);
                // we need to distinguish three cases:
                // - no where clause (select all rows)
                // - where clause that cannot be executed by clusterj
                // - where clause that can be executed by clusterj
                whereNode = ((SelectNode)root).getWhereNode();
                queryDomainType = (QueryDomainTypeImpl<?>) session.createQueryDomainType(domainTypeHandler);
                if (whereNode == null) {
                    // no where clause (select all rows)
                    result = new SQLExecutor.Select(domainTypeHandler, columnNames, queryDomainType);
                } else {
                    // create a predicate from the tree
                    Predicate predicate = whereNode.getPredicate(queryDomainType);
                    if (predicate != null) {
                        // where clause that can be executed by clusterj
                        queryDomainType.where(predicate);
                        result = new SQLExecutor.Select(domainTypeHandler, columnNames, queryDomainType);
                        whereType = "clusterj";
                    } else {
                        // where clause that cannot be executed by clusterj
                        result = new SQLExecutor.Noop();
                        whereType = "non-clusterj";
                    }
                    if (logger.isDetailEnabled()) logger.detail(walk(root));
                }
                if (logger.isDetailEnabled()) {
                    logger.detail(
                        "SELECT FROM " + tableName
                        + " COLUMNS " + columnNames + " whereType " + whereType);
                    logger.detail(walk(root));
                }
                break;
            case MySQL51Parser.DELETE:
                tableNode = (CommonTree)root.getFirstChildWithType(MySQL51Parser.TABLE);
                tableName = getTableName(tableNode);
                getSession();
                dictionary = session.getDictionary();
                domainTypeHandler = getDomainTypeHandler(tableName, dictionary);
                whereNode = ((WhereNode)root.getFirstChildWithType(MySQL51Parser.WHERE));
                int numberOfParameters = 0;
                if (whereNode == null) {
                    // no where clause (delete all rows)
                    result = new SQLExecutor.Delete(domainTypeHandler);
                    whereType = "empty";
                } else {
                    // create a predicate from the tree
                    queryDomainType = (QueryDomainTypeImpl<?>) session.createQueryDomainType(domainTypeHandler);
                    Predicate predicate = whereNode.getPredicate(queryDomainType);
                    if (predicate != null) {
                        // where clause that can be executed by clusterj
                        queryDomainType.where(predicate);
                        numberOfParameters = whereNode.getNumberOfParameters();
                        result = new SQLExecutor.Delete(domainTypeHandler, queryDomainType, numberOfParameters);
                        whereType = "clusterj";
                    } else {
                        // where clause that cannot be executed by clusterj
                        result = new SQLExecutor.Noop();
View Full Code Here

TOP

Related Classes of com.mysql.clusterj.jdbc.antlr.node.WhereNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.