Re: Optimistic Locking on Client
Re: Optimistic Locking on Client
- Subject: Re: Optimistic Locking on Client
- From: Nick Pilch <email@hidden>
- Date: Tue, 23 Aug 2005 11:25:42 -0700
Title: Re: Optimistic Locking on
Client
I imagine you will just have to search the text of the exception
for what you are looking for. You might have to look for something
database-dependent. Sometimes I see "Failed to update row in
database" (I use Oracle) and I'm guessing that that's an
optimistic locking failure.
At 2:37 PM -0400 8/22/05, Praveen Boppana wrote:
Yes, But how do we determine the
exception cause is Optimistic Locking and How can we handle
it.
This is what we do on server side.
Following code does not work on client side as we do not have access
to following.
com.webobjects.eoaccess.EOAdaptorChannel,
com.webobjects.eoaccess.EODatabaseContext,
com.webobjects.eoaccess.EOGeneralAdaptorException,
com.webobjects.eoaccess.EODatabaseOperation
Thanks
Praveen
/**
* Deal with an optimistic
locking failure using "Last Write Wins"
*/
public void
handleOptimisticLockingFailureByLastWriteWins(EOEditingContext ec,
EOGeneralAdaptorException lockingException)
throws NSForwardException {
//Get the info dictionary that is created when the exception is
thrown.
NSDictionary info
= lockingException.userInfo();
//Determine the adaptor operation that triggered the optimistic
locking failure.
EOAdaptorOperation adaptorOperation =
(EOAdaptorOperation)info.objectForKey(EOAdaptorChannel.FailedAdaptorOperationKey);
int operationType =
adaptorOperation.adaptorOperator();
//Determine the database operation that triggered the
failure.
EODatabaseOperation dbOperation =
(EODatabaseOperation)info.objectForKey(EODatabaseContext.FailedDatabaseOperationKey);
//Retrieve the enterprise object that triggered the
failure.
EOEnterpriseObject failedEO =
(EOEnterpriseObject)dbOperation.object();
//Retrieve the dictionary of values involved in the
failure.
NSDictionary
valuesInFailedSave =
adaptorOperation.changedValues();
if
(NSLog.debugLoggingAllowedForLevel(NSLog.DebugLevelInformational))
{
NSLog.out.appendln("valuesInFailedSave:
" + valuesInFailedSave);
}
//Take action based on the type of adaptor operation that triggered
the optimistic locking failure.
if (operationType == EODatabaseOperation.AdaptorUpdateOperator)
{
//Recover by essentially ignoring the
optimistic locking failure and committing
the
//changes that originally failed. This is
a last write wins policy.
//Overwrite any changes in the database
with the eo's values.
failedEO.reapplyChangesFromDictionary(valuesInFailedSave);
} else {
//The optimistic locking failure was
causes by another type of adaptor operation, not an
update.
throw new
NSForwardException(lockingException,
"Unknown adaptorOperator " + operationType + " in optimistic locking
exception.");
}
ec.saveChanges();
}
On Aug 22, 2005, at 2:19 PM, Nick Pilch
wrote:
I think the server would be handing back
the exception to the client, so it would likely be wrapped in an
NSForwardException and the string "Server Exception" or
"ServerException" will appear in there somewhere. This
information is from my memory.
At 9:41 AM -0400 8/22/05, Praveen Boppana
wrote:
Hi,
Any one has any suggestion about handling
Optimistic Locking Error on Java Client application?.
I know how it can be handled on server
side using following code.
/**
* Determine if the exception
thrown during a save is an optimistic locking exception.
*/
public boolean
isOptimisticLockingFailure(EOGeneralAdaptorException
exceptionWhileSaving) {
//Get the info dictionary that is created when the exception is
thrown.
NSDictionary
exceptionInfo = exceptionWhileSaving.userInfo();
//Determine the type of the failure.
Object
failureType = (exceptionInfo != null) ?
exceptionInfo.objectForKey(EOAdaptorChannel.AdaptorFailureKey) : null;
//Return depending on the type of failure.
if ((failureType != null) &&
(failureType.equals(EOAdaptorChannel.AdaptorOptimisticLockingFailure))) {
return true;
} else {
return false;
}
}
Since we do not have access to the
com.webobjects.eoaccess from client side. I'm not sure how can handle
this.
Please help.
Thanks
Praveen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
asy.org
This email sent to email@hidden
--
Nick Pilch / email@hidden
_______________________________________________
Do not post admin requests to the list.
They will be ignored.
Webobjects-dev mailing
list (email@hidden)
Help/Unsubscribe/Update your
Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list
(email@hidden)
Help/Unsubscribe/Update your Subscription:
>asy.org
This email sent to email@hidden
--
Nick Pilch / email@hidden
_______________________________________________
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