Search in sources :

Example 1 with QuerySQL

use of org.teiid.test.client.QuerySQL in project teiid by teiid.

the class XMLQueryVisitationStrategy method parseXMLQueryFile.

/**
 * Consume an XML Query File and produce a Map containing queries, with
 * queryNames/IDs as Keys.
 * <br>
 * @param queryFile the XML file object that is to be parsed
 * @return the List containing quers.
 * @exception JDOMException if there is an error consuming the message.
 */
public List parseXMLQueryFile(String queryScenarioID, File queryFile, String querySetID) throws IOException, JDOMException {
    List<QueryTest> queries = new LinkedList();
    // HashMap queryMap = new HashMap();
    SAXBuilder builder = SAXBuilderHelper.createSAXBuilder(false);
    Document queryDocument = builder.build(queryFile);
    List queryElements = queryDocument.getRootElement().getChildren(TagNames.Elements.QUERY);
    Iterator iter = queryElements.iterator();
    while (iter.hasNext()) {
        Element queryElement = (Element) iter.next();
        String queryName = queryElement.getAttributeValue(TagNames.Attributes.NAME);
        if (queryElement.getChild(TagNames.Elements.EXCEPTION) == null) {
            String uniqueID = querySetID + "_" + queryName;
            List<Element> parmChildren = queryElement.getChildren(TagNames.Elements.SQL);
            if (parmChildren == null || parmChildren.isEmpty()) {
                TestLogger.logDebug("=======  Single QueryTest ");
                QuerySQL sql = createQuerySQL(queryElement);
                QueryTest q = new QueryTest(queryScenarioID, uniqueID, querySetID, new QuerySQL[] { sql }, false);
                queries.add(q);
            } else {
                TestLogger.logDebug("=======  QueryTest has multiple sql statements");
                QuerySQL[] querysql = new QuerySQL[parmChildren.size()];
                int c = 0;
                final Iterator<Element> sqliter = parmChildren.iterator();
                while (sqliter.hasNext()) {
                    final Element sqlElement = (Element) sqliter.next();
                    QuerySQL sql = createQuerySQL(sqlElement);
                    querysql[c] = sql;
                    c++;
                }
                QueryTest q = new QueryTest(queryScenarioID, uniqueID, querySetID, querysql, false);
                queries.add(q);
            }
        // queryMap.put(queryName, query);
        } else {
            Element exceptionElement = queryElement.getChild(TagNames.Elements.EXCEPTION);
            String exceptionType = exceptionElement.getChild(TagNames.Elements.CLASS).getTextTrim();
            String uniqueID = querySetID + "_" + queryName;
            QuerySQL sql = new QuerySQL(exceptionType, null);
            QueryTest q = new QueryTest(queryScenarioID, uniqueID, querySetID, new QuerySQL[] { sql }, true);
            queries.add(q);
        // queryMap.put(queryName, exceptionType);
        }
    }
    return queries;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) QueryTest(org.teiid.test.client.QueryTest) Element(org.jdom.Element) Document(org.jdom.Document) QuerySQL(org.teiid.test.client.QuerySQL)

Example 2 with QuerySQL

use of org.teiid.test.client.QuerySQL in project teiid by teiid.

the class XMLQueryVisitationStrategy method createQuerySQL.

private QuerySQL createQuerySQL(Element queryElement) {
    String query = queryElement.getTextTrim();
    Object[] parms = getParms(queryElement);
    QuerySQL sql = new QuerySQL(query, parms);
    String updateCnt = queryElement.getAttributeValue(TagNames.Attributes.UPDATE_CNT);
    if (updateCnt != null && updateCnt.trim().length() > 0) {
        int cnt = Integer.parseInt(updateCnt);
        sql.setUpdateCnt(cnt);
    }
    String rowCnt = queryElement.getAttributeValue(TagNames.Attributes.TABLE_ROW_COUNT);
    if (rowCnt != null && rowCnt.trim().length() > 0) {
        int cnt = Integer.parseInt(rowCnt);
        sql.setRowCnt(cnt);
    }
    return sql;
}
Also used : QuerySQL(org.teiid.test.client.QuerySQL)

Aggregations

QuerySQL (org.teiid.test.client.QuerySQL)2 Document (org.jdom.Document)1 Element (org.jdom.Element)1 SAXBuilder (org.jdom.input.SAXBuilder)1 QueryTest (org.teiid.test.client.QueryTest)1