ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brandon Goodin" <brandon.goo...@gmail.com>
Subject Caching and provided result object
Date Wed, 11 Oct 2006 22:43:05 GMT
Hey all,

I'm not sure if anyone else has ran up against this. But, there is a problem
when using queryForObject(id, parameterObject, resultObject) and caching.

I have code that does the following:

public class Monster {

private String monsterName;
private Integer ferocityLevel;
private Integer height;
...
//getters/setters
...
}

public class MonsterService {
...
    public Monster getMonster (String monsterName) {
        Monster monster = new Monster(monsterName);
        return monsterDao.fetch(monster);
    }
...
}

public class MonsterDao {
...
    public void fetch (Monster monster) {
        queryForObject("Monster.fetch", monster, monster);
    }
...
}

The first time I call MonsterService.getMonster("Godzilla"), all is fine
because the Monster object is not yet cached in iBATIS. The normal means of
populating the supplied resultObject is employed. But as soon as the object
is cached it never populates my resultObject beyond the monsterName that i
provided. Basically, when getCacheKey(request, parameterObject) is called it
returns the monster object appropriately. The only problem is that it never
populates the supplied resultObject. It simply returns the cachedObject
which would be fine if I wasn't providing a resultObject that i expected to
be populated. In other words, I'm not looking for a returned object I'm
looking for my supplied object to be populated.

-- CachingStatement --
...
public Object executeQueryForObject(RequestScope request, Transaction trans,
Object parameterObject, Object resultObject)
     throws SQLException {
   CacheKey cacheKey = getCacheKey(request, parameterObject);
   cacheKey.update("executeQueryForObject");
   Object object = cacheModel.getObject(cacheKey);
   if (object == CacheModel.NULL_OBJECT){
       //    This was cached, but null
       object = null;
   }else if (object == null) {
       object = statement.executeQueryForObject(request, trans,
parameterObject, resultObject);
      cacheModel.putObject(cacheKey, object);
   }
    return object;
}
..
--

We could provide a means either in the CachedStatement class or upstream in
the SqlMapExecutorDelegate to handle the translation from the cached object
values into the supplied resultObject.

Thoughts?

Brandon.

Mime
View raw message