Revision 224468 says it fixed IBATISNET-97 for QueryForList and
QueryForMap. I don't think this is necessary. QueryForList and
QueryForMap both return empty (non-null) IList or IDictionary objects
if the query returned zero results. A zero element IList or IDictionary
is a normal case and shouldn't need special processing.
RunQueryForList uses this code to always ensure a non-null IList is
passed back:
if (_statement.ListClass == null)
{
list = new ArrayList();
}
else
{
list = _statement.CreateInstanceOfListClass();
}
ExecuteQueryForMap calls through to this method in MappedStatement.cs:
private IDictionary RunQueryForMap( RequestScope request, IDalSession
session, object parameterObject, string keyProperty, string
valueProperty )
{
IDictionary map = new Hashtable();
IList list = ExecuteQueryForList(session, parameterObject);
for(int i =0; i<list.Count; i++)
{
// snip
}
return map;
}
Line 838 of MappedStatement.cs (revision 224468) has this code:
object mapAsObject = (IDictionary)_statement.CacheModel[key];
if (mapAsObject == CacheModel.NULL_OBJECT)
{
// unreachable ???
map = new Hashtable();
}
else if (mapAsObject == null)
{
// snip
}
else
{
map = (IDictionary)mapAsObject;
}
I think the original code:
map = (IDictionary)_statement.CacheModel[key];
if (map == null)
{
map = RunQueryForList(...);
_statement.CacheModel[key] = map;
}
is fine and does not need to be modified. The same thing applies for
the original ExecuteQueryForList code.
- Ron
--- "Gilles Bayon (JIRA)" <[email protected]> wrote:
> [ http://issues.apache.org/jira/browse/IBATISNET-97?page=all ]
>
> Gilles Bayon closed IBATISNET-97:
> ---------------------------------
>
> Fix Version: DataMapper 1.3
> Resolution: Fixed
> Assign To: Gilles Bayon
>
> In SVN
>
> > CacheModel does not support caching null results
> > ------------------------------------------------
> >
> > Key: IBATISNET-97
> > URL: http://issues.apache.org/jira/browse/IBATISNET-97
> > Project: iBatis for .NET
> > Type: Bug
> > Components: DataMapper
> > Versions: DataMapper 1.2.1
> > Reporter: Ron Grabowski
> > Assignee: Gilles Bayon
> > Priority: Minor
> > Fix For: DataMapper 1.3
>
> >
> > When caching is enabled and the sqlMap.QueryForObject method
> returns a null value, that null value is not cached. Subsequent calls
> to sqlMap.QueryForObject always miss the cache and query the
> database. For more information see the Java ticket of the same issue:
> > http://issues.apache.org/jira/browse/IBATIS-174
> > One solution is to define a special marker object in CacheModel.cs:
> > /// <summary>
> > /// Marked object to allow null objects to be cached
> > /// </summary>
> > [NonSerialized]
> > public readonly static object NULL_OBJECT = new Object();
> > and insert that value into the cache when a null value is returned
> from the initial query.
> > The code to retrieve an item from the cache in MappedStatement.cs:
> > if (obj == null)
> > {
> > obj = RunQueryForObject(request, session, parameterObject,
> resultObject);
> > _statement.CacheModel[key] = obj;
> > }
> > could be changed to this:
> > // check if this query has alreay been run
> > if (obj == CacheModel.NULL_OBJECT)
> > {
> > // convert the marker object back into a null value
> > obj = null;
> > }
> > else if (obj == null)
> > {
> > obj = RunQueryForObject(request, session, parameterObject,
> resultObject);
> > if (obj == null)
> > {
> > // store null value in cache using the special marker object
> > _statement.CacheModel[key] = CacheModel.NULL_OBJECT;
> > }
> > else
> > {
> > // query returned a normal, non-null value
> > _statement.CacheModel[key] = obj;
> > }
> > }
>
> --
> 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
>
>