Re: DB uniqueness constraints and dealing with them
Re: DB uniqueness constraints and dealing with them
- Subject: Re: DB uniqueness constraints and dealing with them
- From: Paul Stringer <email@hidden>
- Date: Fri, 04 Jul 2008 16:32:38 +0200
With the following I was able to get the keys and values with some
regexing, but not very database independant but does work with
FrontBase. It relies on the sql exception message predictably
containing the key and value information. Wether other databases do I
don't know but you may get some mileage here.
String FRONTBASE_UNIQUE_CONSTRAINT_KV_PATTERN ="\\(UNIQUE,\\s[A-Z]+\
\._[C]\\d+\\(([A-Z]+)='(.+)'\\)"
JDBCAdaptorException e = ((EOAdaptorOperation)
someEOGeneralAdaptorExceptionCausedByUniqueConstraint
.userInfo
().objectForKey
("EOFailedAdaptorOperationKey")).exception().sqlException();
Pattern p = Pattern.compile(FRONTBASE_UNIQUE_CONSTRAINT_KV_PATTERN);
Matcher m = p.matcher(e.sqlException().getMessage());
if (m.find() && m.groupCount()==2){
String key = m.group(1);
String value = m.group(2);
String method = "UniqueContraintViolation" +
ERXStringUtilities.capitalize(key.toLowerCase());
return
ERXValidationFactory
.defaultFactory
().createCustomException((ERXGenericRecord)databaseFailedOp.object(),
key, value, method);
}
Happy 4th of July (was wondering why it was quiet here today)
Paul S
Treasuremytext.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden