Example usage for org.apache.ibatis.builder BuilderException BuilderException

List of usage examples for org.apache.ibatis.builder BuilderException BuilderException

Introduction

In this page you can find the example usage for org.apache.ibatis.builder BuilderException BuilderException.

Prototype

public BuilderException(Throwable cause) 

Source Link

Usage

From source file:cc.oit.dao.impl.mybatis.session.XMLConfigBuilder.java

License:Apache License

public Configuration parse() {
    if (parsed) {
        throw new BuilderException("Each XMLConfigBuilder can only be used once.");
    }// ww w .j ava 2  s.co  m
    parsed = true;
    parseConfiguration(parser.evalNode("/configuration"));
    return (Configuration) configuration;
}

From source file:cc.oit.dao.impl.mybatis.session.XMLConfigBuilder.java

License:Apache License

private void propertiesElement(XNode context) throws Exception {
    if (context != null) {
        Properties defaults = context.getChildrenAsProperties();
        String resource = context.getStringAttribute("resource");
        String url = context.getStringAttribute("url");
        if (resource != null && url != null) {
            throw new BuilderException(
                    "The properties element cannot specify both a URL and a resource based property file reference.  Please specify one or the other.");
        }/* w w  w  .j a v  a2  s  . co m*/
        if (resource != null) {
            defaults.putAll(Resources.getResourceAsProperties(resource));
        } else if (url != null) {
            defaults.putAll(Resources.getUrlAsProperties(url));
        }
        Properties vars = configuration.getVariables();
        if (vars != null) {
            defaults.putAll(vars);
        }
        parser.setVariables(defaults);
        configuration.setVariables(defaults);
    }
}

From source file:cc.oit.dao.impl.mybatis.session.XMLConfigBuilder.java

License:Apache License

private void settingsElement(XNode context) throws Exception {
    if (context != null) {
        Properties props = context.getChildrenAsProperties();
        // Check that all settings are known to the configuration class
        MetaClass metaConfig = MetaClass.forClass(Configuration.class);
        for (Object key : props.keySet()) {
            if (!metaConfig.hasSetter(String.valueOf(key))) {
                throw new BuilderException("The setting " + key
                        + " is not known.  Make sure you spelled it correctly (case sensitive).");
            }/*w  ww .  j  a  va2  s.c  om*/
        }
        configuration.setAutoMappingBehavior(
                AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
        configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
        configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
        configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
        configuration
                .setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
        configuration.setMultipleResultSetsEnabled(
                booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
        configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
        configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
        configuration.setDefaultExecutorType(
                ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
        configuration
                .setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
        configuration.setMapUnderscoreToCamelCase(
                booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
        configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
        configuration
                .setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
        configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
        configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"),
                "equals,clone,hashCode,toString"));
        configuration.setSafeResultHandlerEnabled(
                booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
        configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
        configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
        configuration.setLogPrefix(props.getProperty("logPrefix"));
        configuration.setLogImpl(resolveClass(props.getProperty("logImpl")));
        configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
    }
}

From source file:cc.oit.dao.impl.mybatis.session.XMLConfigBuilder.java

License:Apache License

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);/*from w ww.  j  a v a 2 s . c  om*/
        return factory;
    }
    throw new BuilderException("Environment declaration requires a TransactionFactory.");
}

From source file:cc.oit.dao.impl.mybatis.session.XMLConfigBuilder.java

License:Apache License

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);/*from   ww  w. ja  v a2  s. c om*/
        return factory;
    }
    throw new BuilderException("Environment declaration requires a DataSourceFactory.");
}

From source file:cc.oit.dao.impl.mybatis.session.XMLConfigBuilder.java

License:Apache License

private void mapperElement(XNode parent) throws Exception {
    if (parent != null) {
        for (XNode child : parent.getChildren()) {
            if ("package".equals(child.getName())) {
                String mapperPackage = child.getStringAttribute("name");
                configuration.addMappers(mapperPackage);
            } else {
                String resource = child.getStringAttribute("resource");
                String url = child.getStringAttribute("url");
                String mapperClass = child.getStringAttribute("class");
                if (resource != null && url == null && mapperClass == null) {
                    ErrorContext.instance().resource(resource);
                    InputStream inputStream = Resources.getResourceAsStream(resource);
                    XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, resource,
                            configuration.getSqlFragments());
                    mapperParser.parse();
                } else if (resource == null && url != null && mapperClass == null) {
                    ErrorContext.instance().resource(url);
                    InputStream inputStream = Resources.getUrlAsStream(url);
                    XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, url,
                            configuration.getSqlFragments());
                    mapperParser.parse();
                } else if (resource == null && url == null && mapperClass != null) {
                    Class<?> mapperInterface = Resources.classForName(mapperClass);
                    configuration.addMapper(mapperInterface);
                } else {
                    throw new BuilderException(
                            "A mapper element may only specify a url, resource or class, but not more than one.");
                }//from ww  w  .j ava2s.  c  o m
            }
        }
    }
}

From source file:cc.oit.dao.impl.mybatis.session.XMLConfigBuilder.java

License:Apache License

private boolean isSpecifiedEnvironment(String id) {
    if (environment == null) {
        throw new BuilderException("No environment specified.");
    } else if (id == null) {
        throw new BuilderException("Environment requires an id attribute.");
    } else if (environment.equals(id)) {
        return true;
    }/*from www.  j  av a  2  s  .  c om*/
    return false;
}

From source file:com.appleframework.orm.mybatis.pagehelper.sqlsource.PageProviderSqlSource.java

License:Open Source License

/**
 * 3.4.0?// w w w .ja v a2  s  .co m
 *
 * @param parameterObject
 * @return
 */
private SqlSource createSqlSource340(Object parameterObject) {
    try {
        Class<?>[] parameterTypes = providerMethod.getParameterTypes();
        String sql;
        if (parameterTypes.length == 0) {
            sql = (String) providerMethod.invoke(providerType.newInstance());
        } else if (parameterTypes.length == 1 && (parameterObject == null
                || parameterTypes[0].isAssignableFrom(parameterObject.getClass()))) {
            sql = (String) providerMethod.invoke(providerType.newInstance(), parameterObject);
        } else if (parameterObject instanceof Map) {
            @SuppressWarnings("unchecked")
            Map<String, Object> params = (Map<String, Object>) parameterObject;
            sql = (String) providerMethod.invoke(providerType.newInstance(),
                    extractProviderMethodArguments(params, providerMethodArgumentNames));
        } else {
            throw new BuilderException("Error invoking SqlProvider method (" + providerType.getName() + "."
                    + providerMethod.getName() + "). Cannot invoke a method that holds "
                    + (parameterTypes.length == 1 ? "named argument(@Param)" : "multiple arguments")
                    + " using a specifying parameterObject. In this case, please specify a 'java.util.Map' object.");
        }
        Class<?> parameterType = parameterObject == null ? Object.class : parameterObject.getClass();
        StaticSqlSource sqlSource = (StaticSqlSource) sqlSourceParser.parse(sql, parameterType,
                new HashMap<String, Object>());
        return new OrderByStaticSqlSource(sqlSource);
        //return sqlSourceParser.parse(sql, parameterType, new HashMap<String, Object>());
    } catch (BuilderException e) {
        throw e;
    } catch (Exception e) {
        throw new BuilderException("Error invoking SqlProvider method (" + providerType.getName() + "."
                + providerMethod.getName() + ").  Cause: " + e, e);
    }
}

From source file:com.baomidou.mybatisplus.MybatisMapperAnnotationBuilder.java

License:Apache License

private void parseCacheRef() {
    CacheNamespaceRef cacheDomainRef = type.getAnnotation(CacheNamespaceRef.class);
    if (cacheDomainRef != null) {
        Class<?> refType = cacheDomainRef.value();
        String refName = cacheDomainRef.name();
        if (refType == void.class && refName.isEmpty()) {
            throw new BuilderException(
                    "Should be specified either value() or name() attribute in the @CacheNamespaceRef");
        }//from   www . ja va 2s . c  om
        if (refType != void.class && !refName.isEmpty()) {
            throw new BuilderException(
                    "Cannot use both value() and name() attribute in the @CacheNamespaceRef");
        }
        String namespace = (refType != void.class) ? refType.getName() : refName;
        assistant.useCacheRef(namespace);
    }
}

From source file:com.baomidou.mybatisplus.MybatisMapperAnnotationBuilder.java

License:Apache License

private boolean hasNestedSelect(Result result) {
    if (result.one().select().length() > 0 && result.many().select().length() > 0) {
        throw new BuilderException("Cannot use both @One and @Many annotations in the same @Result");
    }/*from www  .  jav a2s .c  o m*/
    return result.one().select().length() > 0 || result.many().select().length() > 0;
}