Cache entry invalidation on updates

2005-05-22 Thread Oscar Picasso
Is there a way to invalidate a cache entry on update?

Let say I have the following select using a cache model (result class = User):

select id, username, password from users where useraname = #username#;

and the following update (parameter class = User):

update users
set password = #password#
where username = #username#

Following an update, I want the select statement to retrieve a fresh User but I
don't want all the cache entries to be flushed.

I cannot make it work: the select statement returns the 'old' user.

At first I though that this was the purpose of a read-write cache. But I am
under the impression that read-write caches are unrelated to the invalidation
of particular cache entries on inserts or updates.

Am I right?

Any idea of how to do what I want?

Oscar Picasso

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Bidirectional parent-child relationship and groupBy

2005-04-07 Thread Oscar Picasso
Hi,

I have something like that:

class Category
{
  int id;
  ListSubcategory subcategories;
  
  ..getters and setters
}

class Subcategory
{
  int id;
  Category parent;
  
  ..getters and setters
}


A groupBy in the Category resultMap loads the related subcategories. 

However while loading these subcategories, I would like each subcategory parent
to be set.

I can use lazy loading but it can set a different parent for the subcategories
under a same Category (!= identity = more objects created).

Is there a mean to do that in the result Map (set the subcategory parent to the
same Category in a group).

Currently, I do it in the dao code but I don't find this solution very clean.

Thanks.

Oscar



__ 
Yahoo! Messenger 
Show us what our next emoticon should look like. Join the fun. 
http://www.advision.webevents.yahoo.com/emoticontest


Support for Java 1.5 generics

2005-04-05 Thread Oscar Picasso
Hi,

It seems that IBatis (or maybe cglib) doesn't fully support Java 1.5 generics.

Here is my use case (a somewhat deep hierarchy):

= DOMAIN MODEL =
//-
public interface Persistable
{
  public void setId(Integer id);
  public Integer getId();
}

//-
public abstract class AbstractPersistable 
  implements Persistable
{
  private Integer id;

  public Integer getId()
  {
return id;
  }

  public void setId(Integer id)
  {
this.id = id;
  }
}

//-
public interface NodeN extends Node extends Persistable
{
  public void setParent(N parent);
  public N getParent();
  ...
}

//-
public abstract class AbstractNodeN extends AbstractNode 
  extends AbstractPersistable implements NodeN
{
  private N parent;

  public N getParent()
  {
return this.parent;
  }

  public void setParent(N parent)
  {
this.parent = parent;
  }
  ...
}

//-
public class Category extends AbstractNodeCategory
{
  ... some other methods
}


= DAOS CLASSES AND INTERFACES =
//-
public interface PersistableDAOP extends Persistable {
public P findById(Integer id);
}

//-
public interface NodeDAON extends Node extends PersistableDAON
{
  ... some other methods
}

//-
public abstract class AbstractIbatisAccessD extends Persistable 
extends SqlMapDaoTemplate implements PersistableDAOD
{

  public AbstractIbatisAccess(DaoManager manager)
  {
super(manager);
  }

  public D findById(Integer id)
  {
try
{
  return (D) getSqlMapExecutor().queryForObject(getNamespace() +
.findById, id);
} catch (SQLException e)
{
  throw new DaoException(e);
}
  }
  ...
}

//-
public abstract class AbstractNodeIbatisAccessD extends NodeD 
   extends AbstractIbatisAccessD implements NodeDAOD
{

  public AbstractNodeIbatisAccess(DaoManager manager)
  {
super(manager);
  }
  ... override some methods
}

//-
public class CategoryIbatisAccess 
  extends AbstractNodeIbatisAccessCategory implements CategoryDAO {
public CategoryIbatisAccess(DaoManager manager) {
super(manager);
}

@Override
protected String getNamespace() {
return categories;
}
}

= DAOS CONFIG =
...
dao interface=org.xenata.ads.dao.CategoryDAO
implementation=org.xenata.ads.access.ibatis.CategoryIbatisAccess/
...

= SQLMAP =
resultMap id=category class=org.xenata.ads.domain.Category
  result property=id column=id/
  result property=parent column=parent_id select=categories.findById/
  ...
/resultMap

select id=findById 
parameterClass=int 
resultMap=category
  select id,
 parent_id,
 ...
  from categories
  where id = #value#

/select



=   
When doing: 

CategoryDAO dao = daoManager.getDao(CategoryDAO.class);
Category category = dao.findById(1);

I get the Exception below. Any idea? Has anyone worked with generics and
iBatis? 

I am under the impression that cglib doesn't know it has to enhance an actual
Category. Or is it something that could be solved in iBatis?

Thanks.

Oscar


= EXCEPTION TRACE =
Testcase: testFindById(org.xenata.ads.access.ibatis.CategoryIbatisAccessTest):
Caused an ERROR
null
com.ibatis.dao.client.DaoException
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in resources/ibatis/category.xml.  
--- The error occurred while applying a result map.  
--- Check the categories.category.  
--- The error happened while setting a property on the result object.  
--- Cause: com.ibatis.common.exception.NestedRuntimeException: Error setting
properties of '[EMAIL PROTECTED]'.  Cause:
java.lang.ClassCastException:
org.xenata.ads.domain.Node$$EnhancerByCGLIB$$1e4f4b2f_2
Caused by: java.lang.ClassCastException:
org.xenata.ads.domain.Node$$EnhancerByCGLIB$$1e4f4b2f_2
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error setting
properties of '[EMAIL PROTECTED]'.  Cause:
java.lang.ClassCastException:
org.xenata.ads.domain.Node$$EnhancerByCGLIB$$1e4f4b2f_2
Caused by: java.lang.ClassCastException:
org.xenata.ads.domain.Node$$EnhancerByCGLIB$$1e4f4b2f_2
at
org.xenata.ads.access.ibatis.AbstractIbatisAccess.findById(AbstractIbatisAccess.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.ibatis.dao.engine.impl.DaoProxy.invoke(DaoProxy.java:72)
at $Proxy3.findById(Unknown Source)
at
org.xenata.ads.access.ibatis.CategoryIbatisAccessTest.testFindById(CategoryIbatisAccessTest.java:112)
at