Author: cbegin Date: Thu Jul 17 23:30:03 2008 New Revision: 677835 URL: http://svn.apache.org/viewvc?rev=677835&view=rev Log: JIRA 375 "Provide a way for not creating items from nested ResultMaps when the items contain only null values"
Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/config/ResultMapConfig.java ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/ResultMap.java ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/ResultMapping.java Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java?rev=677835&r1=677834&r2=677835&view=diff ============================================================================== --- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java (original) +++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/SqlMapParser.java Thu Jul 17 23:30:03 2008 @@ -243,6 +243,7 @@ String statementName = childAttributes.getProperty("select"); String resultMapName = childAttributes.getProperty("resultMap"); String callback = childAttributes.getProperty("typeHandler"); + String notNullColumn = childAttributes.getProperty("notNullColumn"); state.getConfig().getErrorContext().setMoreInfo("Check the result mapping property type or name."); Class javaClass = null; @@ -275,7 +276,7 @@ } } - state.getResultConfig().addResultMapping(propertyName, columnName, columnIndex, javaClass, jdbcType, nullValue, statementName, resultMapName, typeHandlerImpl); + state.getResultConfig().addResultMapping(propertyName, columnName, columnIndex, javaClass, jdbcType, nullValue, notNullColumn, statementName, resultMapName, typeHandlerImpl); } }); Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd?rev=677835&r1=677834&r2=677835&view=diff ============================================================================== --- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd (original) +++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/builder/xml/sql-map-2.dtd Thu Jul 17 23:30:03 2008 @@ -91,6 +91,7 @@ columnIndex CDATA #IMPLIED jdbcType CDATA #IMPLIED nullValue CDATA #IMPLIED +notNullColumn CDATA #IMPLIED select CDATA #IMPLIED resultMap CDATA #IMPLIED typeHandler CDATA #IMPLIED Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/config/ResultMapConfig.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/config/ResultMapConfig.java?rev=677835&r1=677834&r2=677835&view=diff ============================================================================== --- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/config/ResultMapConfig.java (original) +++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/config/ResultMapConfig.java Thu Jul 17 23:30:03 2008 @@ -101,7 +101,7 @@ discriminator.addSubMap(value.toString(), resultMap); } - public void addResultMapping(String propertyName, String columnName, Integer columnIndex, Class javaClass, String jdbcType, String nullValue, String statementName, String resultMapName, Object impl) { + public void addResultMapping(String propertyName, String columnName, Integer columnIndex, Class javaClass, String jdbcType, String nullValue, String notNullColumn, String statementName, String resultMapName, Object impl) { errorContext.setObjectId(propertyName + " mapping of the " + resultMap.getId() + " result map"); TypeHandler handler; if (impl != null) { @@ -121,6 +121,7 @@ mapping.setJdbcTypeName(jdbcType); mapping.setTypeHandler(handler); mapping.setNullValue(nullValue); + mapping.setNotNullColumn(notNullColumn); mapping.setStatementName(statementName); mapping.setNestedResultMapName(resultMapName); if (resultMapName != null && resultMapName.length() > 0) { Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/ResultMap.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/ResultMap.java?rev=677835&r1=677834&r2=677835&view=diff ============================================================================== --- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/ResultMap.java (original) +++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/ResultMap.java Thu Jul 17 23:30:03 2008 @@ -443,14 +443,23 @@ } } - values = resultMap.getResults(statementScope, statementScope.getResultSet()); - if (statementScope.isRowDataFound()) { - Object o = resultMap.setResultObjectValues(statementScope, null, values); - if (o != NO_VALUE) { - if (obj != null && obj instanceof Collection) { - ((Collection) obj).add(o); - } else { - PROBE.setObject(resultObject, propertyName, o); + //JIRA 375 "Provide a way for not creating items from nested ResultMaps when the items contain only null values" + boolean subResultObjectAbsent = false; + if(mapping.getNotNullColumn() != null) { + if(statementScope.getResultSet().getObject(mapping.getNotNullColumn()) == null) { + subResultObjectAbsent = true; + } + } + if(!subResultObjectAbsent) { + values = resultMap.getResults(statementScope, statementScope.getResultSet()); + if (statementScope.isRowDataFound()) { + Object o = resultMap.setResultObjectValues(statementScope, null, values); + if (o != NO_VALUE) { + if (obj != null && obj instanceof Collection) { + ((Collection) obj).add(o); + } else { + PROBE.setObject(resultObject, propertyName, o); + } } } } @@ -631,4 +640,4 @@ return value; } } -} \ No newline at end of file +} Modified: ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/ResultMapping.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/ResultMapping.java?rev=677835&r1=677834&r2=677835&view=diff ============================================================================== --- ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/ResultMapping.java (original) +++ ibatis/trunk/java/mapper/mapper2/src/com/ibatis/sqlmap/engine/mapping/result/ResultMapping.java Thu Jul 17 23:30:03 2008 @@ -30,6 +30,7 @@ private int jdbcType; private String jdbcTypeName; private String nullValue; + private String notNullColumn; private String statementName; private Class javaType; @@ -178,6 +179,24 @@ } /** + * Getter for the name of the column to check for null before instantiating a nested resultMapping value + * + * @return - the null substitution + */ + public String getNotNullColumn() { + return notNullColumn; + } + + /** + * Setter for the name of the column to check for null before instantiating a nested resultMapping value + * + * @param notNullColumn - the column name + */ + public void setNotNullColumn(String notNullColumn) { + this.notNullColumn = notNullColumn; + } + + /** * Getter for the name of the statement * * @return - the name