6、Configuration构建之setting节点解析

来源:互联网 发布:查九牧卫浴型号软件 编辑:程序博客网 时间:2024/06/06 03:27

setting元素的判断

对于setting元素会先进行判读,是否有非法的值

private Properties settingsAsProperties(XNode context) {        if (context == null) {            return new Properties();        }        //得到配置文件setting节点下的所有属性        Properties props = context.getChildrenAsProperties();        // 通过反射工具得到Configuration对象        MetaClass metaConfig = MetaClass.forClass(Configuration.class, localReflectorFactory);        //如果setting节点下的属性有Configuration对象未包含的属性则报错        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).");            }        }        return props;    }

加载Vfs

对于完成判断的setting元素会先对vfs进行复制

    private void loadCustomVfs(Properties props) throws ClassNotFoundException {        String value = props.getProperty("vfsImpl");        if (value != null) {            String[] clazzes = value.split(",");            for (String clazz : clazzes) {                if (!clazz.isEmpty()) {                    @SuppressWarnings("unchecked")                    Class<? extends VFS> vfsImpl = (Class<? extends VFS>) Resources.classForName(clazz);                    configuration.setVfsImpl(vfsImpl);                }            }        }    }

其他setting元素的赋值

其他setting元素的赋值,并不会立即执行,在其他节点解析后才会调用settingsElement(settings);

 private void settingsElement(Properties props) throws Exception {        configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));        configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));        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"), false));        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.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), 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.setUseActualParamName(booleanValueOf(props.getProperty("useActualParamName"), true));        configuration.setReturnInstanceForEmptyRow(booleanValueOf(props.getProperty("returnInstanceForEmptyRow"), false));        configuration.setLogPrefix(props.getProperty("logPrefix"));        @SuppressWarnings("unchecked")        Class<? extends Log> logImpl = (Class<? extends Log>) resolveClass(props.getProperty("logImpl"));        configuration.setLogImpl(logImpl);        configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));    }
原创粉丝点击