public void Batch(Action<IStorageActionsAccessor> action)
{
if (disposerLock.IsReadLockHeld) // we are currently in a nested Batch call
{
if (current.Value != null) // check again, just to be sure
{
action(current.Value);
return;
}
}
disposerLock.EnterReadLock();
try
{
ExecuteBatch(action);
}
catch (EsentErrorException e)
{
if (disposed)
{
Trace.WriteLine("TransactionalStorage.Batch was called after it was disposed, call was ignored.");
return; // this may happen if someone is calling us from the finalizer thread, so we can't even throw on that
}
switch (e.Error)
{
case JET_err.WriteConflict:
case JET_err.SessionWriteConflict:
case JET_err.WriteConflictPrimaryIndex:
throw new ConcurrencyException("Concurrent modification to the same document are not allowed");
default:
throw;
}
}
finally
{
disposerLock.ExitReadLock();
if(disposed == false)
current.Value = null;
}
onCommit();// call user code after we exit the lock
}