List of usage examples for org.apache.ibatis.reflection MetaClass hasSetter
public boolean hasSetter(String name)
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)."); }/*from ww w .j av a 2 s. c o m*/ } 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:com.baomidou.mybatisplus.MybatisXMLConfigBuilder.java
License:Apache License
private Properties settingsAsProperties(XNode context) { if (context == null) { return new Properties(); }/*from w ww. j a v a 2s . c om*/ Properties props = context.getChildrenAsProperties(); // Check that all settings are known to the configuration class MetaClass metaConfig = MetaClass.forClass(Configuration.class, localReflectorFactory); 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; }
From source file:com.ibatis.sqlmap.engine.builder.XmlSqlMapParser.java
License:Apache License
@NodeEvent("/sqlMap/resultMap/result") public void sqlMapresultMapresult(XNode context) throws Exception { String nullValue = context.getStringAttribute("nullValue"); if (nullValue != null) { throw new UnsupportedOperationException("Null value subsitution is not supported by iBATIS 3."); }/*w w w .j a v a 2s . c o m*/ String columnIndexProp = context.getStringAttribute("columnIndex"); if (columnIndexProp != null) { throw new UnsupportedOperationException( "Numerical column indices are not supported. Use the column name instead."); } String propertyName = context.getStringAttribute("property"); String jdbcType = context.getStringAttribute("jdbcType"); String javaType = context.getStringAttribute("javaType"); String columnName = context.getStringAttribute("column"); String statementName = context.getStringAttribute("select"); String resultMapName = context.getStringAttribute("resultMap"); String callback = context.getStringAttribute("typeHandler"); Class javaClass = null; try { if (javaType != null && javaType.length() > 0) { javaClass = config.getTypeAliasRegistry().resolveAlias(javaType); } } catch (Exception e) { throw new RuntimeException("Error setting java type on result discriminator mapping. Cause: " + e); } if (javaClass == null && !Map.class.isAssignableFrom(resultMapBuilder.type()) && !config.getTypeHandlerRegistry().hasTypeHandler(resultMapBuilder.type())) { javaClass = MetaClass.forClass(resultMapBuilder.type()).getSetterType(propertyName); } if (javaClass == null && statementName != null) { javaClass = List.class; } JdbcType jdbcTypeEnum = null; if (jdbcType != null) { jdbcTypeEnum = JdbcType.valueOf(jdbcType); } TypeHandler typeHandler = null; if (javaClass != null) { typeHandler = config.getTypeHandlerRegistry().getTypeHandler(javaClass, jdbcTypeEnum); } try { if (callback != null && callback.length() > 0) { Object o = config.getTypeAliasRegistry().resolveAlias(callback).newInstance(); if (o instanceof TypeHandlerCallback) { typeHandler = new TypeHandlerCallbackAdapter((TypeHandlerCallback) o); } } } catch (Exception e) { throw new RuntimeException("Error occurred during custom type handler configuration. Cause: " + e, e); } if (typeHandler == null && config.getTypeHandlerRegistry().hasTypeHandler(resultMapBuilder.type())) { typeHandler = config.getTypeHandlerRegistry().getTypeHandler(resultMapBuilder.type()); } if (typeHandler == null) { Class resultClass = resultMapBuilder.type(); if (resultClass != null && !Map.class.isAssignableFrom(resultClass)) { MetaClass metaResultClass = MetaClass.forClass(resultClass); Class resultType = null; if (metaResultClass.hasGetter(propertyName)) { resultType = metaResultClass.getGetterType(propertyName); } else if (metaResultClass.hasSetter(propertyName)) { resultType = metaResultClass.getSetterType(propertyName); } if (resultType != null) { typeHandler = config.getTypeHandlerRegistry().getTypeHandler(resultType); } } else { typeHandler = config.getTypeHandlerRegistry().getUnknownTypeHandler(); } } List<ResultMapping> composites = parseCompositeColumnName(columnName); if (composites.size() > 0) { ResultMapping first = composites.get(0); columnName = first.getColumn(); } ResultMapping.Builder resultMappingBuilder = new ResultMapping.Builder(config, propertyName, columnName, typeHandler); resultMappingBuilder.javaType(javaClass); resultMappingBuilder.nestedQueryId(statementName); resultMappingBuilder.nestedResultMapId(resultMapName); resultMappingBuilder.jdbcType(jdbcTypeEnum); resultMappingBuilder.composites(composites); if (groupByProperties != null && groupByProperties.contains(propertyName)) { List<ResultFlag> flags = new ArrayList<ResultFlag>(); resultMappingBuilder.flags(flags); } resultMappingList.add(resultMappingBuilder.build()); }
From source file:com.ibatis.sqlmap.engine.builder.XmlSqlMapParser.java
License:Apache License
@NodeEvent("/sqlMap/parameterMap/parameter") public void sqlMapparameterMapparameter(XNode context) throws Exception { String nullValue = context.getStringAttribute("nullValue"); if (nullValue != null) { throw new UnsupportedOperationException("Null value subsitution is not supported by iBATIS 3."); }//from ww w . j ava2 s .com String propertyName = context.getStringAttribute("property"); String jdbcType = context.getStringAttribute("jdbcType"); String javaType = context.getStringAttribute("javaType"); String resultMap = context.getStringAttribute("resultMap"); String mode = context.getStringAttribute("mode"); String callback = context.getStringAttribute("typeHandler"); String numericScaleProp = context.getStringAttribute("numericScale"); Class javaClass = null; try { if (javaType != null && javaType.length() > 0) { javaClass = config.getTypeAliasRegistry().resolveAlias(javaType); } } catch (Exception e) { throw new RuntimeException("Error setting javaType on parameter mapping. Cause: " + e); } JdbcType jdbcTypeEnum = null; if (jdbcType != null) { jdbcTypeEnum = JdbcType.valueOf(jdbcType); } TypeHandler typeHandler = null; if (javaClass != null) { typeHandler = config.getTypeHandlerRegistry().getTypeHandler(javaClass, jdbcTypeEnum); } if (callback != null) { Object o = config.getTypeAliasRegistry().resolveAlias(callback).newInstance(); if (o instanceof TypeHandlerCallback) { typeHandler = new TypeHandlerCallbackAdapter((TypeHandlerCallback) o); } } if (typeHandler == null && config.getTypeHandlerRegistry().hasTypeHandler(parameterMapBuilder.type())) { typeHandler = config.getTypeHandlerRegistry().getTypeHandler(parameterMapBuilder.type()); } if (typeHandler == null) { Class parameterClass = parameterMapBuilder.type(); if (parameterClass != null && !Map.class.isAssignableFrom(parameterClass)) { MetaClass metaParamClass = MetaClass.forClass(parameterClass); Class paramType = null; if (metaParamClass.hasGetter(propertyName)) { paramType = metaParamClass.getGetterType(propertyName); } else if (metaParamClass.hasSetter(propertyName)) { paramType = metaParamClass.getSetterType(propertyName); } if (paramType != null) { typeHandler = config.getTypeHandlerRegistry().getTypeHandler(paramType); } } else { typeHandler = config.getTypeHandlerRegistry().getUnknownTypeHandler(); } } ParameterMode paramModeEnum = ParameterMode.IN; if (mode != null) { paramModeEnum = ParameterMode.valueOf(mode); } Integer numericScale = null; if (numericScaleProp != null) { numericScale = new Integer(numericScaleProp); } ParameterMapping.Builder parameterMappingBuilder = new ParameterMapping.Builder(config, propertyName, typeHandler); parameterMappingBuilder.javaType(javaClass); parameterMappingBuilder.jdbcType(jdbcTypeEnum); parameterMappingBuilder.mode(paramModeEnum); parameterMappingBuilder.numericScale(numericScale); parameterMappingBuilder.resultMapId(resultMap); parameterMappingList.add(parameterMappingBuilder.build()); }
From source file:com.mybatisX.core.MybatisXMLConfigBuilder.java
License:Apache License
private Properties settingsAsPropertiess(XNode context) { if (context == null) { return new Properties(); }/* w w w. j a v a 2 s .c o m*/ Properties props = context.getChildrenAsProperties(); // Check that all settings are known to the configuration class MetaClass metaConfig = MetaClass.forClass(Configuration.class, localReflectorFactory); 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; }
From source file:org.alfresco.ibatis.HierarchicalXMLConfigBuilder.java
License:Open Source 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)."); }//from w w w. j a v a 2 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"))); } }