Search in sources :

Example 1 with DefaultResultContext

use of org.apache.ibatis.executor.result.DefaultResultContext in project mybatis-3 by mybatis.

the class DefaultResultSetHandler method handleRowValuesForNestedResultMap.

//
// HANDLE NESTED RESULT MAPS
//
private void handleRowValuesForNestedResultMap(ResultSetWrapper rsw, ResultMap resultMap, ResultHandler<?> resultHandler, RowBounds rowBounds, ResultMapping parentMapping) throws SQLException {
    final DefaultResultContext<Object> resultContext = new DefaultResultContext<Object>();
    skipRows(rsw.getResultSet(), rowBounds);
    Object rowValue = previousRowValue;
    while (shouldProcessMoreRows(resultContext, rowBounds) && rsw.getResultSet().next()) {
        final ResultMap discriminatedResultMap = resolveDiscriminatedResultMap(rsw.getResultSet(), resultMap, null);
        final CacheKey rowKey = createRowKey(discriminatedResultMap, rsw, null);
        Object partialObject = nestedResultObjects.get(rowKey);
        // issue #577 && #542
        if (mappedStatement.isResultOrdered()) {
            if (partialObject == null && rowValue != null) {
                nestedResultObjects.clear();
                storeObject(resultHandler, resultContext, rowValue, parentMapping, rsw.getResultSet());
            }
            rowValue = getRowValue(rsw, discriminatedResultMap, rowKey, null, partialObject);
        } else {
            rowValue = getRowValue(rsw, discriminatedResultMap, rowKey, null, partialObject);
            if (partialObject == null) {
                storeObject(resultHandler, resultContext, rowValue, parentMapping, rsw.getResultSet());
            }
        }
    }
    if (rowValue != null && mappedStatement.isResultOrdered() && shouldProcessMoreRows(resultContext, rowBounds)) {
        storeObject(resultHandler, resultContext, rowValue, parentMapping, rsw.getResultSet());
        previousRowValue = null;
    } else if (rowValue != null) {
        previousRowValue = rowValue;
    }
}
Also used : ResultMap(org.apache.ibatis.mapping.ResultMap) MetaObject(org.apache.ibatis.reflection.MetaObject) DefaultResultContext(org.apache.ibatis.executor.result.DefaultResultContext) CacheKey(org.apache.ibatis.cache.CacheKey)

Example 2 with DefaultResultContext

use of org.apache.ibatis.executor.result.DefaultResultContext in project mybatis-3 by mybatis.

the class DefaultResultSetHandler method handleRowValuesForSimpleResultMap.

private void handleRowValuesForSimpleResultMap(ResultSetWrapper rsw, ResultMap resultMap, ResultHandler<?> resultHandler, RowBounds rowBounds, ResultMapping parentMapping) throws SQLException {
    DefaultResultContext<Object> resultContext = new DefaultResultContext<Object>();
    skipRows(rsw.getResultSet(), rowBounds);
    while (shouldProcessMoreRows(resultContext, rowBounds) && rsw.getResultSet().next()) {
        ResultMap discriminatedResultMap = resolveDiscriminatedResultMap(rsw.getResultSet(), resultMap, null);
        Object rowValue = getRowValue(rsw, discriminatedResultMap);
        storeObject(resultHandler, resultContext, rowValue, parentMapping, rsw.getResultSet());
    }
}
Also used : ResultMap(org.apache.ibatis.mapping.ResultMap) MetaObject(org.apache.ibatis.reflection.MetaObject) DefaultResultContext(org.apache.ibatis.executor.result.DefaultResultContext)

Aggregations

DefaultResultContext (org.apache.ibatis.executor.result.DefaultResultContext)2 ResultMap (org.apache.ibatis.mapping.ResultMap)2 MetaObject (org.apache.ibatis.reflection.MetaObject)2 CacheKey (org.apache.ibatis.cache.CacheKey)1