Search in sources :

Example 1 with Statement

use of org.apache.synapse.mediators.db.Statement in project wso2-synapse by wso2.

the class AbstractDBMediatorFactory method processStatements.

protected void processStatements(OMElement elem, AbstractDBMediator mediator) {
    Iterator iter = elem.getChildrenWithName(STMNT_Q);
    while (iter.hasNext()) {
        OMElement stmntElt = (OMElement) iter.next();
        Statement statement = new Statement(getValue(stmntElt, SQL_Q));
        Iterator paramIter = stmntElt.getChildrenWithName(PARAM_Q);
        while (paramIter.hasNext()) {
            OMElement paramElt = (OMElement) paramIter.next();
            String xpath = getAttribute(paramElt, ATT_EXPRN);
            String value = getAttribute(paramElt, ATT_VALUE);
            if (xpath != null || value != null) {
                SynapseXPath xp = null;
                if (xpath != null) {
                    try {
                        xp = SynapseXPathFactory.getSynapseXPath(paramElt, ATT_EXPRN);
                    } catch (JaxenException e) {
                        handleException("Invalid XPath specified for the source attribute : " + xpath);
                    }
                }
                statement.addParameter(value, xp, getAttribute(paramElt, ATT_TYPE));
            }
        }
        Iterator resultIter = stmntElt.getChildrenWithName(RESULT_Q);
        while (resultIter.hasNext()) {
            OMElement resultElt = (OMElement) resultIter.next();
            if (getAttribute(resultElt, ATT_NAME) == null || getAttribute(resultElt, ATT_COLUMN) == null) {
                handleException("Invalid result element found missing either name and column [DBLookup] mediator");
            }
            statement.addResult(getAttribute(resultElt, ATT_NAME), getAttribute(resultElt, ATT_COLUMN));
        }
        mediator.addStatement(statement);
    }
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) Statement(org.apache.synapse.mediators.db.Statement) JaxenException(org.jaxen.JaxenException) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement)

Example 2 with Statement

use of org.apache.synapse.mediators.db.Statement in project wso2-synapse by wso2.

the class AbstractDBMediatorSerializer method serializeDBInformation.

protected void serializeDBInformation(AbstractDBMediator mediator, OMElement dbParent) {
    OMElement connElt = fac.createOMElement("connection", synNS);
    connElt.addChild(createPoolElement(mediator));
    dbParent.addChild(connElt);
    // process statements
    for (Statement statement : mediator.getStatementList()) {
        dbParent.addChild(createStatementElement(statement));
    }
}
Also used : Statement(org.apache.synapse.mediators.db.Statement) OMElement(org.apache.axiom.om.OMElement)

Example 3 with Statement

use of org.apache.synapse.mediators.db.Statement in project wso2-synapse by wso2.

the class AbstractDBMediatorSerializer method createStatementElement.

private OMNode createStatementElement(Statement statement) {
    OMElement stmntElt = fac.createOMElement(AbstractDBMediatorFactory.STMNT_Q.getLocalPart(), synNS);
    OMElement sqlElt = fac.createOMElement(AbstractDBMediatorFactory.SQL_Q.getLocalPart(), synNS);
    OMText sqlText = fac.createOMText(statement.getRawStatement(), XMLStreamConstants.CDATA);
    sqlElt.addChild(sqlText);
    stmntElt.addChild(sqlElt);
    // serialize parameters of the statement
    for (Statement.Parameter param : statement.getParameters()) {
        OMElement paramElt = createStatementParamElement(param);
        stmntElt.addChild(paramElt);
    }
    // serialize any optional results of the statement
    for (String name : statement.getResultsMap().keySet()) {
        String columnStr = statement.getResultsMap().get(name);
        OMElement resultElt = fac.createOMElement(AbstractDBMediatorFactory.RESULT_Q.getLocalPart(), synNS);
        resultElt.addAttribute(fac.createOMAttribute("name", nullNS, name));
        resultElt.addAttribute(fac.createOMAttribute("column", nullNS, columnStr));
        stmntElt.addChild(resultElt);
    }
    return stmntElt;
}
Also used : Statement(org.apache.synapse.mediators.db.Statement) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Aggregations

OMElement (org.apache.axiom.om.OMElement)3 Statement (org.apache.synapse.mediators.db.Statement)3 Iterator (java.util.Iterator)1 OMText (org.apache.axiom.om.OMText)1 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)1 JaxenException (org.jaxen.JaxenException)1