Search in sources :

Example 1 with MetaClass

use of org.apache.ibatis.reflection.MetaClass in project mybatis-3 by mybatis.

the class DefaultResultSetHandler method createResultObject.

private Object createResultObject(ResultSetWrapper rsw, ResultMap resultMap, List<Class<?>> constructorArgTypes, List<Object> constructorArgs, String columnPrefix) throws SQLException {
    final Class<?> resultType = resultMap.getType();
    final MetaClass metaType = MetaClass.forClass(resultType, reflectorFactory);
    final List<ResultMapping> constructorMappings = resultMap.getConstructorResultMappings();
    if (hasTypeHandlerForResultObject(rsw, resultType)) {
        return createPrimitiveResultObject(rsw, resultMap, columnPrefix);
    } else if (!constructorMappings.isEmpty()) {
        return createParameterizedResultObject(rsw, resultType, constructorMappings, constructorArgTypes, constructorArgs, columnPrefix);
    } else if (resultType.isInterface() || metaType.hasDefaultConstructor()) {
        return objectFactory.create(resultType);
    } else if (shouldApplyAutomaticMappings(resultMap, false)) {
        return createByConstructorSignature(rsw, resultType, constructorArgTypes, constructorArgs, columnPrefix);
    }
    throw new ExecutorException("Do not know how to create an instance of " + resultType);
}
Also used : ExecutorException(org.apache.ibatis.executor.ExecutorException) MetaClass(org.apache.ibatis.reflection.MetaClass) ResultMapping(org.apache.ibatis.mapping.ResultMapping)

Example 2 with MetaClass

use of org.apache.ibatis.reflection.MetaClass in project mybatis-3 by mybatis.

the class DefaultResultSetHandler method createRowKeyForUnmappedProperties.

private void createRowKeyForUnmappedProperties(ResultMap resultMap, ResultSetWrapper rsw, CacheKey cacheKey, String columnPrefix) throws SQLException {
    final MetaClass metaType = MetaClass.forClass(resultMap.getType(), reflectorFactory);
    List<String> unmappedColumnNames = rsw.getUnmappedColumnNames(resultMap, columnPrefix);
    for (String column : unmappedColumnNames) {
        String property = column;
        if (columnPrefix != null && !columnPrefix.isEmpty()) {
            // When columnPrefix is specified, ignore columns without the prefix.
            if (column.toUpperCase(Locale.ENGLISH).startsWith(columnPrefix)) {
                property = column.substring(columnPrefix.length());
            } else {
                continue;
            }
        }
        if (metaType.findProperty(property, configuration.isMapUnderscoreToCamelCase()) != null) {
            String value = rsw.getResultSet().getString(column);
            if (value != null) {
                cacheKey.update(column);
                cacheKey.update(value);
            }
        }
    }
}
Also used : MetaClass(org.apache.ibatis.reflection.MetaClass)

Example 3 with MetaClass

use of org.apache.ibatis.reflection.MetaClass in project mybatis-3 by mybatis.

the class XMLConfigBuilder method settingsAsProperties.

private Properties settingsAsProperties(XNode context) {
    if (context == null) {
        return new Properties();
    }
    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;
}
Also used : BuilderException(org.apache.ibatis.builder.BuilderException) MetaClass(org.apache.ibatis.reflection.MetaClass) Properties(java.util.Properties)

Example 4 with MetaClass

use of org.apache.ibatis.reflection.MetaClass in project mybatis-3 by mybatis.

the class MapperBuilderAssistant method resolveResultJavaType.

private Class<?> resolveResultJavaType(Class<?> resultType, String property, Class<?> javaType) {
    if (javaType == null && property != null) {
        try {
            MetaClass metaResultType = MetaClass.forClass(resultType, configuration.getReflectorFactory());
            javaType = metaResultType.getSetterType(property);
        } catch (Exception e) {
        //ignore, following null check statement will deal with the situation
        }
    }
    if (javaType == null) {
        javaType = Object.class;
    }
    return javaType;
}
Also used : MetaClass(org.apache.ibatis.reflection.MetaClass)

Aggregations

MetaClass (org.apache.ibatis.reflection.MetaClass)4 Properties (java.util.Properties)1 BuilderException (org.apache.ibatis.builder.BuilderException)1 ExecutorException (org.apache.ibatis.executor.ExecutorException)1 ResultMapping (org.apache.ibatis.mapping.ResultMapping)1