|
Many applications have process flows that need to check for the existence/non-existence of a persistent instance of an entity. Although this is possible using the current generic dao, it requires a try/catch block around get(id) and will generate a warning message in the logs if no such persitent instance exists, which may not be desired. It would be more elegant, and make code significantly easier to read, if the dao had an additional exists(id) method:
Currently:
try {
genericDao.get(id);
}
catch (ObjectRetrievalFailureException e)
{
//Object does not exist
.....
}
Note that in the above snippet ObjectRetrieval exception may be thrown in other cases too - not just when the object does not exist.
Proposed:
if ( !genericDao.exists(id) ) {
//Object does not exist
.........
}
|