V
villo
Hi everybody
I always have agreed that exception shouldn't be used for flow control,
nevertheless I have incurred in a situation where breaking this
principle is probably good, for other reasons than design.
The situation is inserting a row in a table, extremely simple stuff. It
happens that the application is basically only doing this and the table
has ~10^7 records, so I have rewritten the application logic, that
would be correctly described as
ARecordObject r=...
if(aDao.find(r)!=null)
aDao.insert(r);
else
aDao.merge(r,anotherRecordObject);
in the form of
if(!aDao.insert(r))
aDao.merge(r,anotherRecordObject);
where insert catches DataIntegrityViolationException and returns true
iff an insert was made.
Now, I see that the first form is better for many reasons, but if the
latter performs faster should I really
bother?
Cheers
Francesco
I always have agreed that exception shouldn't be used for flow control,
nevertheless I have incurred in a situation where breaking this
principle is probably good, for other reasons than design.
The situation is inserting a row in a table, extremely simple stuff. It
happens that the application is basically only doing this and the table
has ~10^7 records, so I have rewritten the application logic, that
would be correctly described as
ARecordObject r=...
if(aDao.find(r)!=null)
aDao.insert(r);
else
aDao.merge(r,anotherRecordObject);
in the form of
if(!aDao.insert(r))
aDao.merge(r,anotherRecordObject);
where insert catches DataIntegrityViolationException and returns true
iff an insert was made.
Now, I see that the first form is better for many reasons, but if the
latter performs faster should I really
bother?
Cheers
Francesco