This is a great idea, I have done similar things in the past as well. Has anyone tried this on DB2 yet, though? My initial guess is that it won't work. In the past I have checked the SQLError for a -803 (which I'm sure is not the best approach because the sqlError is probably platform dependent ... y/n?). Correct me if I'm wrong, but I noticed that DB2 has the sqlState for this error coded as a 23505. If I could get to the DB2 doc online right now, I'd point you to it, but as so often is the case there is some problem on IBM's website that hosts the doc. ;-(
If this requires some special handling, I'd love to contribute to the codebase ... if I knew where to begin. ;-) Thanks, Jason ----- Original Message ----- From: "Matthew Baird" <[EMAIL PROTECTED]> To: "OJB Users List" <[EMAIL PROTECTED]> Sent: Monday, October 14, 2002 11:33 PM Subject: [FEATURE] Key Constraint Violation detection > 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 > ---------------------------------------------------------------------------- ---- > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
