I added support to check if an insert causes a key constraint violation.
 
Why would this be useful? In our application we currently need to check for the 
existence of an item before we insert it, otherwise we will get a vanilla PB 
exception. We can't just blindly insert and then do an update if it throws because it 
might not be a key constraint error. Please don't tell me exceptions shouldn't be used 
for flow control. :)
 
How was it implemented? I check the results of the sql call exception (if there was 
one) and check the sqlState, if it is 23000 (the XOPEN ISO string for key constraint) 
I throw a KeyConstraintViolatedException which is a subclass of 
PersistenceBrokerException.
 
this allows us to insert (without doing the lookup first) quickly, and handle the 
exceptional case of the data already being in the database.
 
Hopefully someone else will find this useful.
 
There are tests to show this working.
 
cheers,
Matthew

<<winmail.dat>>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


Reply via email to