Search in sources :

Example 1 with ResultLoader

use of org.apache.ibatis.executor.loader.ResultLoader in project mybatis-3 by mybatis.

the class DefaultResultSetHandler method getNestedQueryConstructorValue.

//
// NESTED QUERY
//
private Object getNestedQueryConstructorValue(ResultSet rs, ResultMapping constructorMapping, String columnPrefix) throws SQLException {
    final String nestedQueryId = constructorMapping.getNestedQueryId();
    final MappedStatement nestedQuery = configuration.getMappedStatement(nestedQueryId);
    final Class<?> nestedQueryParameterType = nestedQuery.getParameterMap().getType();
    final Object nestedQueryParameterObject = prepareParameterForNestedQuery(rs, constructorMapping, nestedQueryParameterType, columnPrefix);
    Object value = null;
    if (nestedQueryParameterObject != null) {
        final BoundSql nestedBoundSql = nestedQuery.getBoundSql(nestedQueryParameterObject);
        final CacheKey key = executor.createCacheKey(nestedQuery, nestedQueryParameterObject, RowBounds.DEFAULT, nestedBoundSql);
        final Class<?> targetType = constructorMapping.getJavaType();
        final ResultLoader resultLoader = new ResultLoader(configuration, executor, nestedQuery, nestedQueryParameterObject, targetType, key, nestedBoundSql);
        value = resultLoader.loadResult();
    }
    return value;
}
Also used : ResultLoader(org.apache.ibatis.executor.loader.ResultLoader) BoundSql(org.apache.ibatis.mapping.BoundSql) MetaObject(org.apache.ibatis.reflection.MetaObject) MappedStatement(org.apache.ibatis.mapping.MappedStatement) CacheKey(org.apache.ibatis.cache.CacheKey)

Example 2 with ResultLoader

use of org.apache.ibatis.executor.loader.ResultLoader in project mybatis-3 by mybatis.

the class DefaultResultSetHandler method getNestedQueryMappingValue.

private Object getNestedQueryMappingValue(ResultSet rs, MetaObject metaResultObject, ResultMapping propertyMapping, ResultLoaderMap lazyLoader, String columnPrefix) throws SQLException {
    final String nestedQueryId = propertyMapping.getNestedQueryId();
    final String property = propertyMapping.getProperty();
    final MappedStatement nestedQuery = configuration.getMappedStatement(nestedQueryId);
    final Class<?> nestedQueryParameterType = nestedQuery.getParameterMap().getType();
    final Object nestedQueryParameterObject = prepareParameterForNestedQuery(rs, propertyMapping, nestedQueryParameterType, columnPrefix);
    Object value = null;
    if (nestedQueryParameterObject != null) {
        final BoundSql nestedBoundSql = nestedQuery.getBoundSql(nestedQueryParameterObject);
        final CacheKey key = executor.createCacheKey(nestedQuery, nestedQueryParameterObject, RowBounds.DEFAULT, nestedBoundSql);
        final Class<?> targetType = propertyMapping.getJavaType();
        if (executor.isCached(nestedQuery, key)) {
            executor.deferLoad(nestedQuery, metaResultObject, property, key, targetType);
            value = DEFERED;
        } else {
            final ResultLoader resultLoader = new ResultLoader(configuration, executor, nestedQuery, nestedQueryParameterObject, targetType, key, nestedBoundSql);
            if (propertyMapping.isLazy()) {
                lazyLoader.addLoader(property, metaResultObject, resultLoader);
                value = DEFERED;
            } else {
                value = resultLoader.loadResult();
            }
        }
    }
    return value;
}
Also used : ResultLoader(org.apache.ibatis.executor.loader.ResultLoader) BoundSql(org.apache.ibatis.mapping.BoundSql) MetaObject(org.apache.ibatis.reflection.MetaObject) MappedStatement(org.apache.ibatis.mapping.MappedStatement) CacheKey(org.apache.ibatis.cache.CacheKey)

Aggregations

CacheKey (org.apache.ibatis.cache.CacheKey)2 ResultLoader (org.apache.ibatis.executor.loader.ResultLoader)2 BoundSql (org.apache.ibatis.mapping.BoundSql)2 MappedStatement (org.apache.ibatis.mapping.MappedStatement)2 MetaObject (org.apache.ibatis.reflection.MetaObject)2