I am looking for a method which would try to retrieve a single record and if it is not available, the record is created and returned. If such method is there, pls let me know. Otherwise, I am planning to add the following code in the manager.java.vm
public $beanClass loadUniqueOrInsertUsingTemplate($beanClass bean) throws DAOException
{
$beanClass[] beans = this.loadUsingTemplate(bean);
if (beans.length == 0)
return save(bean);
if (beans.length > 1)
throw new ObjectRetrievalException("More than one element !!");
return beans[0];
}
Just made a minor modification to loadUniqueUsingTemplate(); changed the "return null" into "return save(bean)". I guess this will work; if you think there might be issues, please let me know.
Thanks
Balaji
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am looking for a method which would try to retrieve a single record and if it is not available, the record is created and returned. If such method is there, pls let me know. Otherwise, I am planning to add the following code in the manager.java.vm
public $beanClass loadUniqueOrInsertUsingTemplate($beanClass bean) throws DAOException
{
$beanClass[] beans = this.loadUsingTemplate(bean);
if (beans.length == 0)
return save(bean);
if (beans.length > 1)
throw new ObjectRetrievalException("More than one element !!");
return beans[0];
}
Just made a minor modification to loadUniqueUsingTemplate(); changed the "return null" into "return save(bean)". I guess this will work; if you think there might be issues, please let me know.
Thanks
Balaji
Sounds to me like something that should be in a transaction or sychronized or whatever, otherwise you will get duplicates created under load.