<snippet>
try {
editingContext.saveChanges();
} catch (EOGeneralAdaptorException e) {
if (isDbDuplicateKeyError(e)) {
log.error("Duplicate Key Found for: " + tx.barcode());
//... more code...
} else {
throw e;
}
} catch (er.extensions.ERXValidationException ve) {
log.error("Validation Error for: " + tx.barcode() + ". Reverting
E-ticket. Not Saved. " + ve.getMessage());
editingContext.revert();
}
</snippet>
// Supporting Method
private boolean isDbDuplicateKeyError(EOGeneralAdaptorException e) {
if
(e
.userInfo().objectForKey(EOAdaptorChannel.FailedAdaptorOperationKey) !
= null) {
EOAdaptorOperation operation =
(EOAdaptorOperation
)e.userInfo().objectForKey(EOAdaptorChannel.FailedAdaptorOperationKey);
if (operation.exception() != null) {
if (operation.exception().getMessage().indexOf("error
code: 1062") >= 0) {
// Duplicate Key was found. 1062 is MySQL's error
code for unique constraint violation
return true;
}
}
}
return false;
}
.neilmac
On 4 Jul 2008, at 16:36, Miguel Arroz wrote:
In PostgreSQL it works. I don't know if it works on other DBs, but I suppose the error message will contain the constraint name somehow. Anyway, test it on the DBs you use
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
