Search in sources :

Example 16 with ConfigurationException

use of org.apache.cayenne.ConfigurationException in project cayenne by apache.

the class UpgradeHandler_V8 method processDataMapDom.

@Override
public void processDataMapDom(UpgradeUnit upgradeUnit) {
    Element dataMap = upgradeUnit.getDocument().getDocumentElement();
    dataMap.setAttribute("xmlns", "http://cayenne.apache.org/schema/8/modelMap");
    dataMap.setAttribute("xsi:schemaLocation", "http://cayenne.apache.org/schema/8/modelMap " + "http://cayenne.apache.org/schema/8/modelMap.xsd");
    dataMap.setAttribute("project-version", getVersion());
    XPath xpath = XPathFactory.newInstance().newXPath();
    NodeList queryNodes;
    try {
        queryNodes = (NodeList) xpath.evaluate("/data-map/query", upgradeUnit.getDocument(), XPathConstants.NODESET);
    } catch (Exception ex) {
        return;
    }
    for (int j = 0; j < queryNodes.getLength(); j++) {
        Element queryElement = (Element) queryNodes.item(j);
        String factory = queryElement.getAttribute("factory");
        if (factory == null || factory.isEmpty()) {
            continue;
        }
        String queryType;
        switch(factory) {
            case "org.apache.cayenne.map.SelectQueryBuilder":
                queryType = QueryDescriptor.SELECT_QUERY;
                break;
            case "org.apache.cayenne.map.SQLTemplateBuilder":
                queryType = QueryDescriptor.SQL_TEMPLATE;
                break;
            case "org.apache.cayenne.map.EjbqlBuilder":
                queryType = QueryDescriptor.EJBQL_QUERY;
                break;
            case "org.apache.cayenne.map.ProcedureQueryBuilder":
                queryType = QueryDescriptor.PROCEDURE_QUERY;
                break;
            default:
                throw new ConfigurationException("Unknown query factory: " + factory);
        }
        queryElement.setAttribute("type", queryType);
        queryElement.removeAttribute("factory");
    }
}
Also used : XPath(javax.xml.xpath.XPath) ConfigurationException(org.apache.cayenne.ConfigurationException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) ConfigurationException(org.apache.cayenne.ConfigurationException)

Aggregations

ConfigurationException (org.apache.cayenne.ConfigurationException)16 URL (java.net.URL)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 ConfigurationTree (org.apache.cayenne.configuration.ConfigurationTree)3 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 InputSource (org.xml.sax.InputSource)3 XMLReader (org.xml.sax.XMLReader)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 TransformerFactory (javax.xml.transform.TransformerFactory)2 DOMSource (javax.xml.transform.dom.DOMSource)2 StreamResult (javax.xml.transform.stream.StreamResult)2 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)2 DataMap (org.apache.cayenne.map.DataMap)2 CompatibilityUpgradeService (org.apache.cayenne.project.compatibility.CompatibilityUpgradeService)2 Document (org.w3c.dom.Document)2 File (java.io.File)1 ObjectInputStream (java.io.ObjectInputStream)1 Driver (java.sql.Driver)1