Product Information > JADE .NET Developer’s Reference > Chapter 2 - Object Management > JoobInterveningUpdateException

JoobInterveningUpdateException

A JoobInterveningUpdateException is thrown when a JADE session has upgraded a lock on an object from shared to update, but another JADE session has updated the object in the interim when it was unlocked.

The exception is thrown after the update lock has been acquired. An application therefore has the option to ignore the exception and continue execution, if appropriate; for example:

TimeSpan timeout = TimeSpan.FromSeconds(5);
using (System.Data.IDbTransaction tran = context.BeginTransaction())
{
    context.Lock(collA, LockType.Shared, LockDuration.Transaction, timeout);
    // ...
    try
    {
        context.Lock(collA, LockType.Update, LockDuration.Transaction, timeout);
    }
    catch (JoobInterveningUpdateException ex)
    {
        // Ignore the exception: the code does not depend on previously
        // checked values (that may have changed).
    }
    //...
}

An alternative would be to resume execution from an earlier point in order to refresh any properties of the object (that is now update locked) that may have changed, without needing to roll back the current transaction.

The following code fragment gives an example of how this could be done.

bool    retryNeeded;
context.SetImplicitUpdatingLockType(LockType.Update);
using (System.Data.IDbTransaction tran = context.BeginTransaction())
{
    do
    {
        retryNeeded = false;
        try
        {
            //Calling TryGetValue acquires a shared lock on the collection.
            Person existingPerson;
            if ( !allPeople.TryGetValue( person.Id, out existingPerson) )
            {
                //Adding upgrades the lock from shared to update, which
                //unlocks the collection in the interim.
                allPeople.Add(person);
            }
        }
        catch ( JoobInterveningUpdateException ex )
        {
             retryNeeded = true; //Need to check if the person has just been
                                 //added to the collection by another process.
        }
    }
    while (retryNeeded);
}

In this example, if a JoobInterveningUpdateException is thrown, the JADE session needs to check again to see if the person is in the collection, as it could have been added by another JADE session while the collection was unlocked. Note that when retrying, the collection is locked with an update lock.