Search in sources :

Example 11 with BuilderException

use of org.apache.ibatis.builder.BuilderException in project mybatis-3 by mybatis.

the class XMLConfigBuilder method transactionManagerElement.

private TransactionFactory transactionManagerElement(XNode context) throws Exception {
    if (context != null) {
        String type = context.getStringAttribute("type");
        Properties props = context.getChildrenAsProperties();
        TransactionFactory factory = (TransactionFactory) resolveClass(type).newInstance();
        factory.setProperties(props);
        return factory;
    }
    throw new BuilderException("Environment declaration requires a TransactionFactory.");
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) Properties(java.util.Properties)

Example 12 with BuilderException

use of org.apache.ibatis.builder.BuilderException in project mybatis-3 by mybatis.

the class XMLConfigBuilder method dataSourceElement.

private DataSourceFactory dataSourceElement(XNode context) throws Exception {
    if (context != null) {
        String type = context.getStringAttribute("type");
        Properties props = context.getChildrenAsProperties();
        DataSourceFactory factory = (DataSourceFactory) resolveClass(type).newInstance();
        factory.setProperties(props);
        return factory;
    }
    throw new BuilderException("Environment declaration requires a DataSourceFactory.");
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) DataSourceFactory(org.apache.ibatis.datasource.DataSourceFactory) Properties(java.util.Properties)

Example 13 with BuilderException

use of org.apache.ibatis.builder.BuilderException in project mybatis-3 by mybatis.

the class XMLIncludeTransformer method getVariablesContext.

/**
   * Read placholders and their values from include node definition. 
   * @param node Include node instance
   * @param inheritedVariablesContext Current context used for replace variables in new variables values
   * @return variables context from include instance (no inherited values)
   */
private Properties getVariablesContext(Node node, Properties inheritedVariablesContext) {
    Map<String, String> declaredProperties = null;
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node n = children.item(i);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            String name = getStringAttribute(n, "name");
            // Replace variables inside
            String value = PropertyParser.parse(getStringAttribute(n, "value"), inheritedVariablesContext);
            if (declaredProperties == null) {
                declaredProperties = new HashMap<String, String>();
            }
            if (declaredProperties.put(name, value) != null) {
                throw new BuilderException("Variable " + name + " defined twice in the same include definition");
            }
        }
    }
    if (declaredProperties == null) {
        return inheritedVariablesContext;
    } else {
        Properties newProperties = new Properties();
        newProperties.putAll(inheritedVariablesContext);
        newProperties.putAll(declaredProperties);
        return newProperties;
    }
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) XNode(org.apache.ibatis.parsing.XNode) Properties(java.util.Properties)

Example 14 with BuilderException

use of org.apache.ibatis.builder.BuilderException in project mybatis-3 by mybatis.

the class XMLMapperBuilder method configurationElement.

private void configurationElement(XNode context) {
    try {
        String namespace = context.getStringAttribute("namespace");
        if (namespace == null || namespace.equals("")) {
            throw new BuilderException("Mapper's namespace cannot be empty");
        }
        builderAssistant.setCurrentNamespace(namespace);
        cacheRefElement(context.evalNode("cache-ref"));
        cacheElement(context.evalNode("cache"));
        parameterMapElement(context.evalNodes("/mapper/parameterMap"));
        resultMapElements(context.evalNodes("/mapper/resultMap"));
        sqlElement(context.evalNodes("/mapper/sql"));
        buildStatementFromContext(context.evalNodes("select|insert|update|delete"));
    } catch (Exception e) {
        throw new BuilderException("Error parsing Mapper XML. Cause: " + e, e);
    }
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) IncompleteElementException(org.apache.ibatis.builder.IncompleteElementException) BuilderException(org.apache.ibatis.builder.BuilderException)

Aggregations

BuilderException (org.apache.ibatis.builder.BuilderException)14 Properties (java.util.Properties)6 XNode (org.apache.ibatis.parsing.XNode)4 IncompleteElementException (org.apache.ibatis.builder.IncompleteElementException)2 NodeList (org.w3c.dom.NodeList)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 CacheNamespaceRef (org.apache.ibatis.annotations.CacheNamespaceRef)1 BindingException (org.apache.ibatis.binding.BindingException)1 DataSourceFactory (org.apache.ibatis.datasource.DataSourceFactory)1 MetaClass (org.apache.ibatis.reflection.MetaClass)1 TransactionFactory (org.apache.ibatis.transaction.TransactionFactory)1 Node (org.w3c.dom.Node)1 ErrorHandler (org.xml.sax.ErrorHandler)1