public virtual TResult ExecuteQuery <TModel, TResult>(Query <TModel, TResult> query) where TModel : Model { try { Synchronizer.EnterRead(); object result = query.ExecuteStub(_model as TModel); EnsureIsolation(ref result, query); return((TResult)result); } finally { Synchronizer.Exit(); } }
/// <summary> /// Actual command execution /// </summary> public object Execute(Command command) { EnsureNotDisposed(); EnsureAuthorized(command); FireExecutingEvent(command); lock (_commandSequenceLock) { var ctx = ExecutionContext.Begin(); bool exceptionThrown = false; _executionTimer.Restart(); _config.Isolation.Commands.Apply(ref command); ulong lastEntryId = (_config.PersistenceMode == PersistenceMode.Journaling) ? _journalAppender.Append(command) : 0; try { return(_kernel.ExecuteCommand(command)); } catch (Exception ex) { exceptionThrown = true; if (_config.PersistenceMode == PersistenceMode.Journaling) { _journalAppender.AppendRollbackMarker(); } if (!(ex is CommandAbortedException)) { Rollback(); ex = new CommandFailedException("Command failed with rollback, see inner exception for details", ex); } throw ex; } finally { _synchronizer.Exit(); if (!exceptionThrown) { var args = new CommandExecutedEventArgs(lastEntryId, command, ctx.Timestamp, _executionTimer.Elapsed, ctx.Events); CommandExecuted.Invoke(this, args); } ExecutionContext.Current = null; } } }