Re: ps: database failures not rolling up to eof stack ??
Re: ps: database failures not rolling up to eof stack ??
- Subject: Re: ps: database failures not rolling up to eof stack ??
- From: Chuck Hill <email@hidden>
- Date: Mon, 31 Jan 2011 10:59:32 -0800
On Jan 29, 2011, at 5:48 AM, Ramsey Gurley wrote:
> Someone already beat you to it Jake,
>
> http://issues.objectstyle.org/jira/browse/WONDER-664
>
> And as usual, Chuck Hill is right (^_^)
Well, maybe almost half right. It throws, so it does not (or need to) return true.
> The method in question throws or returns false. Following the methods up the call stack, I see databaseContextShouldHandleDatabaseException returns !handled. So that returns true. That in turn is called by _delegateHandledDatabaseException in EODatabaseContext which returns the !blah.booleanValue(). So that returns false. And that method is called by the catch block of saveChangesInEditingContext(). The call looks like
>
> if(_delegateHandledDatabaseException) {blah} else { rollback(); throws}
>
> In short, the problem isn't that the code swallows. The problem appears to be that the code throws without calling context.rollbackChanges() first. However, since this little section of code appears to be so roundly despised by all, I'll just remove the error handling altogether and you guys can handle the EOGeneralAdaptorExceptions yourselves.
The missing call to rollback() looks like a bug in EOF WRT to the JavaDocs:
> Invoked when an exception is thrown that might be handled by reconnecting to the database. The delegate should return true to permit the database context to handle the exception by automatically trying to reconnect to the database, for example, if the delegate determines that the exception was due to a dropped connection.
>
> The delegate should return false to handle the exception itself with a reconnection strategy appropriate to the exception and application. In this case, the database context assumes that all reconnection and associated clean-up have been performed by the delegate and it immediately retries the operation that generated the original exception.
>
> If exception is not one that can be handled by reconnecting to the database, the delegate should simply re-throw it. If this method is not implemented, reconnection will be handled by the response of the adaptor to isDroppedConnectionException.
That last paragraph is what this code is trying to do, but it looks like it will cause problems due to the missing rollback if the delegate throws as documented.
Chuck
> On Jan 28, 2011, at 10:18 PM, Chuck Hill wrote:
>
>>
>> On Jan 28, 2011, at 7:09 PM, Jake Fisher wrote:
>>
>>> In ERXSqlHelper-->MySQLHelper-->handleDatabaseException it swallows
>>> the jdbc exception whole and never reports it. The best you ever get
>>> bubbled up to you in a completely non-descriptive custom validator
>>> exception.........
>>>
>>> I have been meaning to log this as an issue for a long time, sorry for
>>> that, unless of course that is the intended behavior though I can't
>>> see why it would be....
>>>
>>> ~Jake
>>>
>>>
>>>
>>> Code snippet from ERXSQLHelper reposted below for evaluation by more eyes.
>>>
>>> ------
>>> @Override
>>> public boolean handleDatabaseException(EODatabaseContext
>>> databaseContext, Throwable throwable) {
>>> if(throwable instanceof EOGeneralAdaptorException) {
>>> EOGeneralAdaptorException e = (EOGeneralAdaptorException)throwable;
>>> NSDictionary userInfo = e.userInfo();
>>> EOAdaptorOperation failedOp =
>>> userInfo==null?null:(EOAdaptorOperation)userInfo.objectForKey(EOAdaptorChannel.FailedAdaptorOperationKey);
>>> if(failedOp != null && failedOp.exception() instanceof
>>> JDBCAdaptorException) {
>>> JDBCAdaptorException ae = (JDBCAdaptorException)failedOp.exception();
>>>
>>> // MySQL error codes:
>>> http://dev.mysql.com/doc/refman/5.0/en/error-messages-server.html
>>> switch(ae.sqlException().getErrorCode()) {
>>>
>>> case 1062: //Violates unique constraint
>>> handleUniqueConstraintAdaptorException(databaseContext, failedOp);
>>
>> Thinking this should return true here.
>>
>>> break;
>>>
>>> default:
>>>
>>> }
>>> }
>>> }
>>> return false;
>>
>> This is * @return whether or not the SQL helper can handle this exception
>> so it should be OK.
>>
>>
>>> }
>>>
>>> /**
>>> * Throws a validation exception for a unique constraint failure.
>>> * @param context The database context
>>> * @param failedOp The operation that failed
>>> * @throws NSValidation.ValidationException The exception thrown.
>>> The key for the validation template strings file is
>>> <code>UniqueConstraintException</code>
>>> */
>>> protected void
>>> handleUniqueConstraintAdaptorException(EODatabaseContext context,
>>> EOAdaptorOperation failedOp) throws NSValidation.ValidationException {
>>> NSValidation.ValidationException ve =
>>> ERXValidationFactory.defaultFactory().createCustomException(null,
>>> "UniqueConstraintException");
>>> throw ve;
>>> }
>>> }
>>>
>>>
>>>
>>> On Fri, Jan 28, 2011 at 5:22 PM, Chuck Hill <email@hidden> wrote:
>>>>
>>>> On Jan 28, 2011, at 2:16 PM, Simon wrote:
>>>>
>>>>> Check for a custom EC, custom DB context, or delegates for either of those as a place to start. At what point are you NOT seeing it? Could it just be getting ignored at the UI level? I have seen "clever" handling like this:
>>>>>
>>>>> public WOActionResults save() {
>>>>> try {
>>>>> editingContext().saveChanges();
>>>>> }
>>>>> catch (Exception e) {
>>>>> }
>>>>> return context().page();
>>>>> }
>>>>>
>>>>> nice :-) we have 'L' plates in the office that we dish out to people for that kind of stuff
>>>>
>>>> We used to have a cane, it was a caning offense.
>>>>
>>>>
>>>>> ('L' plates in the UK are for learner drivers - i have no idea if that translates around the globe..)
>>>>
>>>> It does in British Columbia. We also have N for the Newfie drivers (or is that New drivers...). I can think of a few others that would be useful.
>>>>
>>>>
>>>>>> ps. is WOVNG still progressing ?
>>>>>
>>>>> Yes, about as well as your exception. :-P
>>>>>
>>>>> ahhh. ok. i guessed that form the number of files release on sourceforge :-P
>>>>>
>>>>> if there is anything worth punting out then please do so - we're about to start reviewing how we can improve validation and it would be good to see what you were trying to do with that stuff.
>>>>
>>>> I don't think much more got done, though I have more internally. It is an interest of mine, so I would be keen on being part of the discussion.
>>>>
>>>>
>>>> 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
>>>>
>>
>> --
>> 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
>
--
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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