Author: cbegin Date: Sun Dec 18 07:20:43 2005 New Revision: 357470 URL: http://svn.apache.org/viewcvs?rev=357470&view=rev Log: Fixed IBATIS-213 SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/BasicResultMap.java Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/BasicResultMap.java URL: http://svn.apache.org/viewcvs/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/BasicResultMap.java?rev=357470&r1=357469&r2=357470&view=diff ============================================================================== --- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/BasicResultMap.java (original) +++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/BasicResultMap.java Sun Dec 18 07:20:43 2005 @@ -235,6 +235,9 @@ if (discriminator != null) { BasicResultMapping mapping = (BasicResultMapping)discriminator.getResultMapping(); Object value = getPrimitiveResultMappingValue(rs, mapping); + if (value == null) { + value = doNullMapping(value, mapping); + } subMap = discriminator.getSubMap(String.valueOf(value)); if (subMap == null) { subMap = this; @@ -307,10 +310,16 @@ Class type = p.getPropertyTypeForSetter(resultClass, mapping.getPropertyName()); columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, type); } + foundData = foundData || columnValues[i] != null; } else if (mapping.getNestedResultMapName() == null) { columnValues[i] = getPrimitiveResultMappingValue(rs, mapping); + if (columnValues[i] == null) { + columnValues[i] = doNullMapping(columnValues[i], mapping); + } + else { + foundData = true; + } } - foundData = foundData || columnValues[i] != null; } request.setRowDataFound(foundData); @@ -551,15 +560,26 @@ } else { value = typeHandler.getResult(rs, columnName); } - if (value == null && nullValue != null) { - value = typeHandler.valueOf(nullValue); - } } else { throw new SqlMapException("No type handler could be found to map the property '" + mapping.getPropertyName() + "' to the column '" + mapping.getColumnName() + "'. One or both of the types, or the combination of types is not supported."); } return value; } - -} - + protected Object doNullMapping(Object value, BasicResultMapping mapping) throws SqlMapException { + if ( value == null ) { + TypeHandler typeHandler = mapping.getTypeHandler(); + if (typeHandler != null) { + String nullValue = mapping.getNullValue(); + if ( nullValue != null ) + value = typeHandler.valueOf(nullValue); + return value; + } else { + throw new SqlMapException("No type handler could be found to map the property '" + mapping.getPropertyName() + "' to the column '" + mapping.getColumnName() + "'. One or both of the types, or the combination of types is not supported."); + } + } + else { + return value; + } + } +} \ No newline at end of file