private Object createParameterizedResultObject(
     ResultSetWrapper rsw,
     Class<?> resultType,
     List<ResultMapping> constructorMappings,
     List<Class<?>> constructorArgTypes,
     List<Object> constructorArgs,
     String columnPrefix)
     throws SQLException {
   boolean foundValues = false;
   for (ResultMapping constructorMapping : constructorMappings) {
     final Class<?> parameterType = constructorMapping.getJavaType();
     final String column = constructorMapping.getColumn();
     final Object value;
     if (constructorMapping.getNestedQueryId() != null) {
       value =
           getNestedQueryConstructorValue(rsw.getResultSet(), constructorMapping, columnPrefix);
     } else if (constructorMapping.getNestedResultMapId() != null) {
       final ResultMap resultMap =
           configuration.getResultMap(constructorMapping.getNestedResultMapId());
       value = getRowValue(rsw, resultMap);
     } else {
       final TypeHandler<?> typeHandler = constructorMapping.getTypeHandler();
       value = typeHandler.getResult(rsw.getResultSet(), prependPrefix(column, columnPrefix));
     }
     constructorArgTypes.add(parameterType);
     constructorArgs.add(value);
     foundValues = value != null || foundValues;
   }
   return foundValues
       ? objectFactory.create(resultType, constructorArgTypes, constructorArgs)
       : null;
 }
 private boolean applyAutomaticMappings(
     ResultSetWrapper rsw, ResultMap resultMap, MetaObject metaObject, String columnPrefix)
     throws SQLException {
   final List<String> unmappedColumnNames = rsw.getUnmappedColumnNames(resultMap, columnPrefix);
   boolean foundValues = false;
   for (String columnName : unmappedColumnNames) {
     String propertyName = columnName;
     if (columnPrefix != null && columnPrefix.length() > 0) {
       // When columnPrefix is specified,
       // ignore columns without the prefix.
       if (columnName.toUpperCase(Locale.ENGLISH).startsWith(columnPrefix)) {
         propertyName = columnName.substring(columnPrefix.length());
       } else {
         continue;
       }
     }
     final String property =
         metaObject.findProperty(propertyName, configuration.isMapUnderscoreToCamelCase());
     if (property != null && metaObject.hasSetter(property)) {
       final Class<?> propertyType = metaObject.getSetterType(property);
       if (typeHandlerRegistry.hasTypeHandler(propertyType)) {
         final TypeHandler<?> typeHandler = rsw.getTypeHandler(propertyType, columnName);
         final Object value = typeHandler.getResult(rsw.getResultSet(), columnName);
         if (value != null
             || configuration.isCallSettersOnNulls()) { // issue #377, call setter on nulls
           if (value != null || !propertyType.isPrimitive()) {
             metaObject.setValue(property, value);
           }
           foundValues = true;
         }
       }
     }
   }
   return foundValues;
 }
 private void createRowKeyForMappedProperties(
     ResultMap resultMap,
     ResultSetWrapper rsw,
     CacheKey cacheKey,
     List<ResultMapping> resultMappings,
     String columnPrefix)
     throws SQLException {
   for (ResultMapping resultMapping : resultMappings) {
     if (resultMapping.getNestedResultMapId() != null
         && resultMapping.getResultSet() == null) { // Issue #392
       final ResultMap nestedResultMap =
           configuration.getResultMap(resultMapping.getNestedResultMapId());
       createRowKeyForMappedProperties(
           nestedResultMap,
           rsw,
           cacheKey,
           nestedResultMap.getConstructorResultMappings(),
           prependPrefix(resultMapping.getColumnPrefix(), columnPrefix));
     } else if (resultMapping.getNestedQueryId() == null) {
       final String column = prependPrefix(resultMapping.getColumn(), columnPrefix);
       final TypeHandler<?> th = resultMapping.getTypeHandler();
       List<String> mappedColumnNames = rsw.getMappedColumnNames(resultMap, columnPrefix);
       if (column != null
           && mappedColumnNames.contains(column.toUpperCase(Locale.ENGLISH))) { // Issue #114
         final Object value = th.getResult(rsw.getResultSet(), column);
         if (value != null) {
           cacheKey.update(column);
           cacheKey.update(value);
         }
       }
     }
   }
 }
 private Object prepareSimpleKeyParameter(
     ResultSet rs, ResultMapping resultMapping, Class<?> parameterType, String columnPrefix)
     throws SQLException {
   final TypeHandler<?> typeHandler;
   if (typeHandlerRegistry.hasTypeHandler(parameterType)) {
     typeHandler = typeHandlerRegistry.getTypeHandler(parameterType);
   } else {
     typeHandler = typeHandlerRegistry.getUnknownTypeHandler();
   }
   return typeHandler.getResult(rs, prependPrefix(resultMapping.getColumn(), columnPrefix));
 }
 private Object createPrimitiveResultObject(
     ResultSetWrapper rsw, ResultMap resultMap, String columnPrefix) throws SQLException {
   final Class<?> resultType = resultMap.getType();
   final String columnName;
   if (resultMap.getResultMappings().size() > 0) {
     final List<ResultMapping> resultMappingList = resultMap.getResultMappings();
     final ResultMapping mapping = resultMappingList.get(0);
     columnName = prependPrefix(mapping.getColumn(), columnPrefix);
   } else {
     columnName = rsw.getColumnNames().get(0);
   }
   final TypeHandler<?> typeHandler = rsw.getTypeHandler(resultType, columnName);
   return typeHandler.getResult(rsw.getResultSet(), columnName);
 }
 private Object prepareCompositeKeyParameter(
     ResultSet rs, ResultMapping resultMapping, Class<?> parameterType, String columnPrefix)
     throws SQLException {
   final Object parameterObject = instantiateParameterObject(parameterType);
   final MetaObject metaObject = configuration.newMetaObject(parameterObject);
   boolean foundValues = false;
   for (ResultMapping innerResultMapping : resultMapping.getComposites()) {
     final Class<?> propType = metaObject.getSetterType(innerResultMapping.getProperty());
     final TypeHandler<?> typeHandler = typeHandlerRegistry.getTypeHandler(propType);
     final Object propValue =
         typeHandler.getResult(rs, prependPrefix(innerResultMapping.getColumn(), columnPrefix));
     if (propValue != null) { // issue #353 & #560 do not execute nested query if key is null
       metaObject.setValue(innerResultMapping.getProperty(), propValue);
       foundValues = true;
     }
   }
   return foundValues ? parameterObject : null;
 }
 public void handleOutputParameters(CallableStatement cs) throws SQLException {
   final Object parameterObject = parameterHandler.getParameterObject();
   final MetaObject metaParam = configuration.newMetaObject(parameterObject);
   final List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
   for (int i = 0; i < parameterMappings.size(); i++) {
     final ParameterMapping parameterMapping = parameterMappings.get(i);
     if (parameterMapping.getMode() == ParameterMode.OUT
         || parameterMapping.getMode() == ParameterMode.INOUT) {
       if (ResultSet.class.equals(parameterMapping.getJavaType())) {
         handleRefCursorOutputParameter(
             (ResultSet) cs.getObject(i + 1), parameterMapping, metaParam);
       } else {
         final TypeHandler<?> typeHandler = parameterMapping.getTypeHandler();
         metaParam.setValue(parameterMapping.getProperty(), typeHandler.getResult(cs, i + 1));
       }
     }
   }
 }
 private Object getPropertyMappingValue(
     ResultSet rs,
     MetaObject metaResultObject,
     ResultMapping propertyMapping,
     ResultLoaderMap lazyLoader,
     String columnPrefix)
     throws SQLException {
   if (propertyMapping.getNestedQueryId() != null) {
     return getNestedQueryMappingValue(
         rs, metaResultObject, propertyMapping, lazyLoader, columnPrefix);
   } else if (propertyMapping.getResultSet() != null) {
     addPendingChildRelation(rs, metaResultObject, propertyMapping);
     return NO_VALUE;
   } else if (propertyMapping.getNestedResultMapId() != null) {
     // the user added a column attribute to a nested result map, ignore it
     return NO_VALUE;
   } else {
     final TypeHandler<?> typeHandler = propertyMapping.getTypeHandler();
     final String column = prependPrefix(propertyMapping.getColumn(), columnPrefix);
     return typeHandler.getResult(rs, column);
   }
 }
 private Object getDiscriminatorValue(
     ResultSet rs, Discriminator discriminator, String columnPrefix) throws SQLException {
   final ResultMapping resultMapping = discriminator.getResultMapping();
   final TypeHandler<?> typeHandler = resultMapping.getTypeHandler();
   return typeHandler.getResult(rs, prependPrefix(resultMapping.getColumn(), columnPrefix));
 }