You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Stefan Friedrich (JIRA)" <ib...@incubator.apache.org> on 2006/02/21 17:23:27 UTC

[jira] Created: (IBATIS-265) Map data into HashMaps: HashMap of List of HashMaps

Map data into HashMaps: HashMap of List of HashMaps
---------------------------------------------------

         Key: IBATIS-265
         URL: http://issues.apache.org/jira/browse/IBATIS-265
     Project: iBatis for Java
        Type: Improvement
    Reporter: Stefan Friedrich
    Priority: Minor


We tried to implement the HashMaps as results for our queries. The problem is, that whenever a HashMap is set as the resultClass, a queryForObject is called and so, every select can only return ONE result. In our application we expect a list of HashMaps at certain locations. The solution for our problem would be very simple and - in our opinion - would work with only three new lines of code:


The Method BasicResultMap.getResults(RequestScope request, ResultSet rs) the targetType for further calls is set: 


if (resultClass == null) { 
	throw new SqlMapException("The result class was null when trying to get results for ResultMap named " + getId() + ".");
} else if (Map.class.isAssignableFrom(resultClass)) { 
	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, Object.class); 
} else if (DomTypeMarker.class.isAssignableFrom(resultClass)) { 
	Class javaType = mapping.getJavaType(); 
	if (javaType == null) { 
		javaType = DomTypeMarker.class; 
	} 
	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
} else { 
	Probe p = ProbeFactory.getProbe(resultClass); 
	Class type = p.getPropertyTypeForSetter(resultClass, mapping.getPropertyName()); 
	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, type); 
}


The part that needs to be changed is in the first "else-Statement".


if (resultClass == null) { 
	throw new SqlMapException("The result class was null when trying to get results for ResultMap named " + getId() + ".");
} else if (Map.class.isAssignableFrom(resultClass)) { 
	Class javaType = mapping.getJavaType(); 
	if (javaType == null) { 
		javaType = Object.class; 
	} 
	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
} else if (DomTypeMarker.class.isAssignableFrom(resultClass)) { 
	Class javaType = mapping.getJavaType(); 
	if (javaType == null) { 
		javaType = DomTypeMarker.class; 
	} 
	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
} else { 
	Probe p = ProbeFactory.getProbe(resultClass); 
	Class type = p.getPropertyTypeForSetter(resultClass, mapping.getPropertyName()); 
	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, type); 
}

As you can see, the changes would have no effect, if no javaType was set. But for our concerns, we would set the javaType to java.util.ArrayList and everything would be just fine!


Stefan


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (IBATIS-265) Map data into HashMaps: HashMap of List of HashMaps

Posted by "Stefan Friedrich (JIRA)" <ib...@incubator.apache.org>.
    [ http://issues.apache.org/jira/browse/IBATIS-265?page=comments#action_12370131 ] 

Stefan Friedrich commented on IBATIS-265:
-----------------------------------------

Please reopen this issue, as what we want to have is a HashMap of Lists of HashMaps AND NOT a simple List of HashMaps! In this case the queryForList() is extremly not the thing we need.... By the way...the queryForList - Method is not a secret for us...

> Map data into HashMaps: HashMap of List of HashMaps
> ---------------------------------------------------
>
>          Key: IBATIS-265
>          URL: http://issues.apache.org/jira/browse/IBATIS-265
>      Project: iBatis for Java
>         Type: Improvement
>     Reporter: Stefan Friedrich
>     Assignee: Sven Boden
>     Priority: Minor

>
> We tried to implement the HashMaps as results for our queries. The problem is, that whenever a HashMap is set as the resultClass, a queryForObject is called and so, every select can only return ONE result. In our application we expect a list of HashMaps at certain locations. The solution for our problem would be very simple and - in our opinion - would work with only three new lines of code:
> The Method BasicResultMap.getResults(RequestScope request, ResultSet rs) the targetType for further calls is set: 
> if (resultClass == null) { 
> 	throw new SqlMapException("The result class was null when trying to get results for ResultMap named " + getId() + ".");
> } else if (Map.class.isAssignableFrom(resultClass)) { 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, Object.class); 
> } else if (DomTypeMarker.class.isAssignableFrom(resultClass)) { 
> 	Class javaType = mapping.getJavaType(); 
> 	if (javaType == null) { 
> 		javaType = DomTypeMarker.class; 
> 	} 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
> } else { 
> 	Probe p = ProbeFactory.getProbe(resultClass); 
> 	Class type = p.getPropertyTypeForSetter(resultClass, mapping.getPropertyName()); 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, type); 
> }
> The part that needs to be changed is in the first "else-Statement".
> if (resultClass == null) { 
> 	throw new SqlMapException("The result class was null when trying to get results for ResultMap named " + getId() + ".");
> } else if (Map.class.isAssignableFrom(resultClass)) { 
> 	Class javaType = mapping.getJavaType(); 
> 	if (javaType == null) { 
> 		javaType = Object.class; 
> 	} 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
> } else if (DomTypeMarker.class.isAssignableFrom(resultClass)) { 
> 	Class javaType = mapping.getJavaType(); 
> 	if (javaType == null) { 
> 		javaType = DomTypeMarker.class; 
> 	} 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
> } else { 
> 	Probe p = ProbeFactory.getProbe(resultClass); 
> 	Class type = p.getPropertyTypeForSetter(resultClass, mapping.getPropertyName()); 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, type); 
> }
> As you can see, the changes would have no effect, if no javaType was set. But for our concerns, we would set the javaType to java.util.ArrayList and everything would be just fine!
> Stefan

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (IBATIS-265) Map data into HashMaps: HashMap of List of HashMaps

Posted by "Utkarsh (JIRA)" <ib...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/IBATIS-265?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12485638 ] 

Utkarsh commented on IBATIS-265:
--------------------------------

I would agree with Stefan. I think what Stefan was trying to say was misunderstood. I am trying to implement something similar to what he is saying. 

example

       <resultMap id="parentResultMap" class="java.util.HashMap">
		<result column="property_1" property="property1" />
		<result column="property_2" property="property2" />
		<result column="property_1" property="keyToChildHashMap"  select="namespace.loadChild"/>
	</resultMap>
        
         <select id="loadParent" resultMap="parentResultMap">
                select property_1, propert_2 from parent
         </select>

	<resultMap id="childResultMap" class="java.util.HashMap">
		<result column="child_property_1" property="childProperty1" />
		<result column="child_property_2" property="childProperty2" />
	</resultMap>

         <select id="loadChild" resultMap="childResultMap">
                select child_property_1, child_property_2 from child where child.property_1 = #property1#
         </select>      

I can see why he is requesting this to be re-opened as at this point, if the resultClass i.e say HashMap is assignable to a Map then it would treat it like and object and you cannot treat it like a List of HashMaps

Could you please re-open this.

Thanks
Utkarsh 
        

> Map data into HashMaps: HashMap of List of HashMaps
> ---------------------------------------------------
>
>                 Key: IBATIS-265
>                 URL: https://issues.apache.org/jira/browse/IBATIS-265
>             Project: iBatis for Java
>          Issue Type: Improvement
>            Reporter: Stefan Friedrich
>         Assigned To: Sven Boden
>            Priority: Minor
>
> We tried to implement the HashMaps as results for our queries. The problem is, that whenever a HashMap is set as the resultClass, a queryForObject is called and so, every select can only return ONE result. In our application we expect a list of HashMaps at certain locations. The solution for our problem would be very simple and - in our opinion - would work with only three new lines of code:
> The Method BasicResultMap.getResults(RequestScope request, ResultSet rs) the targetType for further calls is set: 
> if (resultClass == null) { 
> 	throw new SqlMapException("The result class was null when trying to get results for ResultMap named " + getId() + ".");
> } else if (Map.class.isAssignableFrom(resultClass)) { 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, Object.class); 
> } else if (DomTypeMarker.class.isAssignableFrom(resultClass)) { 
> 	Class javaType = mapping.getJavaType(); 
> 	if (javaType == null) { 
> 		javaType = DomTypeMarker.class; 
> 	} 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
> } else { 
> 	Probe p = ProbeFactory.getProbe(resultClass); 
> 	Class type = p.getPropertyTypeForSetter(resultClass, mapping.getPropertyName()); 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, type); 
> }
> The part that needs to be changed is in the first "else-Statement".
> if (resultClass == null) { 
> 	throw new SqlMapException("The result class was null when trying to get results for ResultMap named " + getId() + ".");
> } else if (Map.class.isAssignableFrom(resultClass)) { 
> 	Class javaType = mapping.getJavaType(); 
> 	if (javaType == null) { 
> 		javaType = Object.class; 
> 	} 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
> } else if (DomTypeMarker.class.isAssignableFrom(resultClass)) { 
> 	Class javaType = mapping.getJavaType(); 
> 	if (javaType == null) { 
> 		javaType = DomTypeMarker.class; 
> 	} 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
> } else { 
> 	Probe p = ProbeFactory.getProbe(resultClass); 
> 	Class type = p.getPropertyTypeForSetter(resultClass, mapping.getPropertyName()); 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, type); 
> }
> As you can see, the changes would have no effect, if no javaType was set. But for our concerns, we would set the javaType to java.util.ArrayList and everything would be just fine!
> Stefan

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (IBATIS-265) Map data into HashMaps: HashMap of List of HashMaps

Posted by "Sven Boden (JIRA)" <ib...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/IBATIS-265?page=all ]
     
Sven Boden closed IBATIS-265:
-----------------------------

    Resolution: Invalid
     Assign To: Sven Boden

Use a HashMap as resultClass and use queryForList()... you will get a list of HashMaps. No changes are required as it's already supported.


> Map data into HashMaps: HashMap of List of HashMaps
> ---------------------------------------------------
>
>          Key: IBATIS-265
>          URL: http://issues.apache.org/jira/browse/IBATIS-265
>      Project: iBatis for Java
>         Type: Improvement
>     Reporter: Stefan Friedrich
>     Assignee: Sven Boden
>     Priority: Minor

>
> We tried to implement the HashMaps as results for our queries. The problem is, that whenever a HashMap is set as the resultClass, a queryForObject is called and so, every select can only return ONE result. In our application we expect a list of HashMaps at certain locations. The solution for our problem would be very simple and - in our opinion - would work with only three new lines of code:
> The Method BasicResultMap.getResults(RequestScope request, ResultSet rs) the targetType for further calls is set: 
> if (resultClass == null) { 
> 	throw new SqlMapException("The result class was null when trying to get results for ResultMap named " + getId() + ".");
> } else if (Map.class.isAssignableFrom(resultClass)) { 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, Object.class); 
> } else if (DomTypeMarker.class.isAssignableFrom(resultClass)) { 
> 	Class javaType = mapping.getJavaType(); 
> 	if (javaType == null) { 
> 		javaType = DomTypeMarker.class; 
> 	} 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
> } else { 
> 	Probe p = ProbeFactory.getProbe(resultClass); 
> 	Class type = p.getPropertyTypeForSetter(resultClass, mapping.getPropertyName()); 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, type); 
> }
> The part that needs to be changed is in the first "else-Statement".
> if (resultClass == null) { 
> 	throw new SqlMapException("The result class was null when trying to get results for ResultMap named " + getId() + ".");
> } else if (Map.class.isAssignableFrom(resultClass)) { 
> 	Class javaType = mapping.getJavaType(); 
> 	if (javaType == null) { 
> 		javaType = Object.class; 
> 	} 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
> } else if (DomTypeMarker.class.isAssignableFrom(resultClass)) { 
> 	Class javaType = mapping.getJavaType(); 
> 	if (javaType == null) { 
> 		javaType = DomTypeMarker.class; 
> 	} 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, javaType); 
> } else { 
> 	Probe p = ProbeFactory.getProbe(resultClass); 
> 	Class type = p.getPropertyTypeForSetter(resultClass, mapping.getPropertyName()); 
> 	columnValues[i] = getNestedSelectMappingValue(request, rs, mapping, type); 
> }
> As you can see, the changes would have no effect, if no javaType was set. But for our concerns, we would set the javaType to java.util.ArrayList and everything would be just fine!
> Stefan

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira