⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqltranslation.java

📁 opennms得相关源码 请大家看看
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public void setIPServiceMappingTranslation() {        m_selectModifier = "";        m_selectList.clear();        m_selectList.add(addColumnToStatement("ipAddr"));        m_selectList.add(addColumnToStatement("serviceName"));        // ");    }    /**     * This method should be called if you want to put constraints on the node,     * interface or service that is returned in the rule. This is useful to see     * if a particular node, interface, or service matches in the rule, and is     * primarily used to filter notices. A subselect is built containing joins     * constrained by node, interface, and service if they are not null or     * blank. This select is then anded with the filter rule to get the complete     * SQL statement.     *      * @param nodeId     *            a node id to constrain against     * @param ipaddr     *            an ipaddress to constrain against     * @param service     *            a service name to constrain against     */    public void setConstraintTranslation(long nodeId, String ipaddr, String service) {        m_selectModifier = "DISTINCT";        m_selectList.clear();        String ipAddrColumn = addColumnToStatement("ipAddr");        m_selectList.add(ipAddrColumn);        StringBuffer constraint = new StringBuffer();        boolean needAnd = false;        if (nodeId != 0) {            if (needAnd)                constraint.append(" AND ");            String nodeIDColumn = addColumnToStatement("nodeID");            constraint.append(nodeIDColumn).append(" = ").append(nodeId);            needAnd = true;        }        if (ipaddr != null && !ipaddr.equals("")) {            if (needAnd)                constraint.append(" AND ");            constraint.append(ipAddrColumn).append(" = '").append(ipaddr).append('\'');            needAnd = true;        }        if (service != null && !service.equals("")) {            String serviceColumn = addColumnToStatement("serviceName");            if (needAnd)                constraint.append(" AND ");            constraint.append(serviceColumn).append(" = '").append(service).append('\'');            needAnd = true;        }        m_where.append(constraint).append(") AND (");    }    public void setInterfaceWithServiceTranslation() {        m_selectModifier = "DISTINCT";        m_selectList.clear();        m_selectList.add(addColumnToStatement("ipAddr"));        m_selectList.add(addColumnToStatement("serviceName"));        m_selectList.add(addColumnToStatement("nodeID"));    }    public void outStart(Start node) {        // finish the where clause by putting in the join clauses to        // the ipinterface table, separating them from the rest of the        // where clause        //        m_where.append(")" + constructJoin());    }    public void caseAAndRule(AAndRule node) {        node.getRule().apply(this);        m_where.append(" AND ");        node.getExpr().apply(this);    }    public void caseAOrRule(AOrRule node) {        node.getRule().apply(this);        m_where.append(" OR ");        node.getExpr().apply(this);    }    public void inAExprParensExpr(AExprParensExpr node) {        m_where.append("( ");    }    public void outAExprParensExpr(AExprParensExpr node) {        m_where.append(" )");    }    public void inAIdentExprPart(AIdentExprPart node) {        m_where.append(validateIdent(node.getIdent().getText()));    }    public void caseAGtrThanExprPart(AGtrThanExprPart node) {        m_where.append(validateIdent(node.getIdent().getText()));        m_where.append(" > ");        node.getCompareRight().apply(this);    }    public void caseALessThanExprPart(ALessThanExprPart node) {        m_where.append(validateIdent(node.getIdent().getText()));        m_where.append(" < ");        node.getCompareRight().apply(this);    }    public void caseAGtrThanEqualExprPart(AGtrThanEqualExprPart node) {        m_where.append(validateIdent(node.getIdent().getText()));        m_where.append(" >= ");        node.getCompareRight().apply(this);    }    public void caseALessThanEqualExprPart(ALessThanEqualExprPart node) {        m_where.append(validateIdent(node.getIdent().getText()));        m_where.append(" <= ");        node.getCompareRight().apply(this);    }    public void caseACompareExprPart(ACompareExprPart node) {        m_where.append(validateIdent(node.getIdent().getText()));        m_where.append(" = ");        node.getCompareRight().apply(this);    }    public void caseANotEqualExprPart(ANotEqualExprPart node) {        m_where.append(validateIdent(node.getIdent().getText()));        m_where.append(" <> ");        node.getCompareRight().apply(this);    }    public void inANotExprPart(ANotExprPart node) {        m_where.append("NOT ");    }    public void caseAIntegerCompareRight(AIntegerCompareRight node) {        inAIntegerCompareRight(node);        m_where.append(node.getInteger().getText());        outAIntegerCompareRight(node);    }    public void caseAStringCompareRight(AStringCompareRight node) {        inAStringCompareRight(node);        if (node.getQuotedString() != null) {            node.getQuotedString().apply(this);            m_where.append(convertString(node.getQuotedString().getText()));        }        outAStringCompareRight(node);    }    public void caseALikeExprPart(ALikeExprPart node) {        inALikeExprPart(node);        if (node.getIdent() != null) {            node.getIdent().apply(this);            m_where.append(validateIdent(node.getIdent().getText()));        }        if (node.getLike() != null) {            node.getLike().apply(this);            m_where.append(" LIKE ");        }        if (node.getQuotedString() != null) {            node.getQuotedString().apply(this);            m_where.append(convertString(node.getQuotedString().getText()));        }        outALikeExprPart(node);    }    public void caseATildelikeExprPart(ATildelikeExprPart node) {        inATildelikeExprPart(node);        if (node.getIdent() != null) {            node.getIdent().apply(this);            m_where.append(validateIdent(node.getIdent().getText()));        }        if (node.getTildelike() != null) {            node.getTildelike().apply(this);            m_where.append(" ~ ");        }        if (node.getQuotedString() != null) {            node.getQuotedString().apply(this);            m_where.append(convertString(node.getQuotedString().getText()));        }        outATildelikeExprPart(node);    }    public void caseAIplikeExprPart(AIplikeExprPart node) {        StringBuffer iplikeMethodCall = new StringBuffer("iplike(");        inAIplikeExprPart(node);        if (node.getIdent() != null) {            node.getIdent().apply(this);            iplikeMethodCall.append(validateIdent(node.getIdent().getText()));        }        if (node.getIplike() != null) {            node.getIplike().apply(this);        }        if (node.getIpIdent() != null) {            node.getIpIdent().apply(this);            iplikeMethodCall.append(", '" + m_ipaddr + "')");        }        m_where.append(iplikeMethodCall.toString());        outAIplikeExprPart(node);    }    public void caseAIpaddrIpIdent(AIpaddrIpIdent node) {        m_ipaddr = new StringBuffer();        inAIpaddrIpIdent(node);        if (node.getOct1() != null) {            node.getOct1().apply(this);        }        if (node.getDot1() != null) {            node.getDot1().apply(this);            m_ipaddr.append(node.getDot1().getText());        }        if (node.getOct2() != null) {            node.getOct2().apply(this);        }        if (node.getDot2() != null) {            node.getDot2().apply(this);            m_ipaddr.append(node.getDot2().getText());        }        if (node.getOct3() != null) {            node.getOct3().apply(this);        }        if (node.getDot3() != null) {            node.getDot3().apply(this);            m_ipaddr.append(node.getDot3().getText());        }        if (node.getOct4() != null) {            node.getOct4().apply(this);        }        outAIpaddrIpIdent(node);    }    public void caseAStarOctet(AStarOctet node) {        inAStarOctet(node);        if (node.getStar() != null) {            node.getStar().apply(this);            m_ipaddr.append(node.getStar().getText());        }        outAStarOctet(node);    }    public void caseAOctetListOctet(AOctetListOctet node) {        inAOctetListOctet(node);        if (node.getOctetList() != null) {            node.getOctetList().apply(this);            // validate the list            //            StringTokenizer tokens = new StringTokenizer(node.getOctetList().getText(), ",");            while (tokens.hasMoreTokens()) {                checkIPNum(tokens.nextToken());            }            // append it to the address            //            m_ipaddr.append(node.getOctetList().getText());        }        outAOctetListOctet(node);    }    public void caseAOctetRangeOctet(AOctetRangeOctet node) {        inAOctetRangeOctet(node);        if (node.getOctetRange() != null) {            node.getOctetRange().apply(this);            // validate the list            //            StringTokenizer tokens = new StringTokenizer(node.getOctetRange().getText(), "-");            while (tokens.hasMoreTokens()) {                checkIPNum(tokens.nextToken());            }            // append it to the address            //            m_ipaddr.append(node.getOctetRange().getText());        }        outAOctetRangeOctet(node);    }    public void caseAOctetRangeListOctet(AOctetRangeListOctet node) {        inAOctetRangeListOctet(node);        if (node.getOctetRangeList() != null) {            node.getOctetRangeList().apply(this);            // validate the list            //            StringTokenizer listTokens = new StringTokenizer(node.getOctetRangeList().getText(), ",");            StringTokenizer rangeTokens = new StringTokenizer(listTokens.nextToken());            // check the range numbers            //            while (rangeTokens.hasMoreTokens()) {                checkIPNum(rangeTokens.nextToken());            }            // check the list numbers            //            while (listTokens.hasMoreTokens()) {                checkIPNum(listTokens.nextToken());            }            // append it to the address            //            m_ipaddr.append(node.getOctetRangeList().getText());        }        outAOctetRangeListOctet(node);    }    public void caseAIntegerOctet(AIntegerOctet node) {        inAIntegerOctet(node);        if (node.getInteger() != null) {            node.getInteger().apply(this);            checkIPNum(node.getInteger().toString().trim());            m_ipaddr.append(node.getInteger().getText());        }        outAIntegerOctet(node);    }    /**     * This method returns the complete sql statement for the filter that was     * parsed. The SQL statement is the result of the select, from, and where     * components assembled from the code.     *      */    public String getStatement() {        // don't walk tree if there is no tree to walk        if (m_node == null)            return null;        // this will walk the tree and build the rest of the sql statement        //        m_node.apply(this);        return buildSelectClause() + m_from.toString() + m_where.toString();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -