Re: Trapping SQLException in D2W
Re: Trapping SQLException in D2W
- Subject: Re: Trapping SQLException in D2W
- From: Ramsey Gurley <email@hidden>
- Date: Wed, 24 Aug 2011 09:42:16 -0700
On Aug 24, 2011, at 7:29 AM, Chuck Hill wrote:
> Hi Markus,
>
> On 2011-08-24, at 1:49 AM, Markus Ruggiero wrote:
>
>> Folks,
>>
>> I have the following requirement: I need a unique constraint on the combination of 2 attributes. As I have learned from some postings about a year back the distinct index in EOModeler does not work (and it surely does not for me). Or should it?
>
> No, the indexing is not ready for use.
The WOLips migration templates have been updated recently. You can at least model unique indexes and the Migration generator will produce the migrations necessary to create them in the database.
>> This is Oracle 9 and WO54, Eclipse Ganymed and suitable WOLips. So to at least to ensure the integrity of the data I have defined a unique constraint via SQL. But now I get a very ugli looking SQLException. This is functionally ok but for the user not acceptable (understandable).
>>
>> How can I trap such an Exception during SAVE in a (ER)D2W app and present a nice looking error message (similar to what is shown when some validations fail)?
>>
>> Thanks a lot and have a nice day
>> ---markus---
>
> It is tricky. The response from every database is different so you need some database specific code to interpret the exception.
Just thought I would add that if you are using wonder's database context delegate, you can also provide your own ERXSQLHelper.OracleSQLHelper subclass via a property
Oracle.SQLHelper=com.whatever.MyOracleHelper
and override the handleDatabaseException method on it to handle the general adaptor exception that happens when the unique constraint fails.
As Chuck mentioned, the quality of the message you receive from your database may make this approach useless (ahem... MySQL), but if you can figure out the modeled index from your database exception, this might do the trick.
Also, if you do it this way, make sure you call context.rollbackChanges before throwing your validation exception.
Ramsey
> I think the best way is to use an EOEditingContext (ERXEC for Wonder apps) sub-class that catches the exception from saveChanges(), and interprets the exception. Done like that, it should be transparent to D2W. I have this implemented for some databases (Oracle is one of them!), in our GVC libraries but have not moved this to Wonder. I started a project in 2009 to complete this validation work and port to Wonder, but uh, er, it kind of fell off the top of my priority list. :-) The base, non-Wonder, code is here: http://sourceforge.net/projects/wovng/ You can get the "used in production" code from our Open Source frameworks: http://www.global-village.net/chill/gvc_frameworks The WOCommunity site has my presentation from WOWODC 2009: http://www.wocommunity.org/podcasts/wowodc/west09/WOWODCW09-Validation.mov
>
> Chuck
>
>
> --
> Chuck Hill Senior Consultant / VP Development
>
> Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
> http://www.global-village.net/products/practical_webobjects
_______________________________________________
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