コード例 #1
0
        public virtual TValue Get <TValue>(object key)
        {
            _usageGuard.AssertNoContextChangeOccurred(this);
            TValue value;

            if (TryGet(key, out value))
            {
                return(value);
            }

            throw new NoSuchDocumentException(key, typeof(TValue));
        }
コード例 #2
0
        private IEnumerable <IAggregateRootEvent> GetAggregateHistoryInternal(Guid aggregateId, bool takeWriteLock)
        {
            _usageGuard.AssertNoContextChangeOccurred(this);
            _schemaManager.SetupSchemaIfDatabaseUnInitialized();
            lock (AggregateLockManager.GetAggregateLockObject(aggregateId))
            {
                var cachedAggregateHistory = _cache.GetCopy(aggregateId);

                var newEventsFromDatabase = _eventReader.GetAggregateHistory(
                    aggregateId: aggregateId,
                    startAfterInsertedVersion: cachedAggregateHistory.MaxSeenInsertedVersion,
                    takeWriteLock: takeWriteLock);

                var containsRefactoringEvents = newEventsFromDatabase.Where(IsRefactoringEvent).Any();
                if (containsRefactoringEvents && cachedAggregateHistory.MaxSeenInsertedVersion > 0)
                {
                    _cache.Remove(aggregateId);
                    return(GetAggregateHistoryInternal(aggregateId: aggregateId, takeWriteLock: takeWriteLock));
                }

                var currentHistory = cachedAggregateHistory.Events.Count == 0
                                                   ? SingleAggregateInstanceEventStreamMutator.MutateCompleteAggregateHistory(_migrationFactories, newEventsFromDatabase)
                                                   : cachedAggregateHistory.Events.Concat(newEventsFromDatabase).ToList();

                //Should within a transaction a process write events, read them, then fail to commit we will have cached events that are not persisted unless we refuse to cache them here.
                if (!_aggregatesWithEventsAddedByThisInstance.Contains(aggregateId))
                {
                    var maxSeenInsertedVersion = newEventsFromDatabase.Any()
                                                     ? newEventsFromDatabase.Max(@event => @event.InsertedVersion)
                                                     : cachedAggregateHistory.MaxSeenInsertedVersion;

                    _cache.Store(
                        aggregateId,
                        new SqlServerEventStoreEventsCache.Entry(events: currentHistory, maxSeenInsertedVersion: maxSeenInsertedVersion));
                }

                return(currentHistory);
            }
        }
コード例 #3
0
        private bool TryGetInternal <TValue>(object key, Type documentType, out TValue value)
        {
            if (documentType.IsInterface)
            {
                throw new ArgumentException("You cannot query by id for an interface type. There is no guarantee of uniqueness");
            }
            UsageGuard.AssertNoContextChangeOccurred(this);

            if (_idMap.TryGet(key, out value) && documentType.IsAssignableFrom(value.GetType()))
            {
                return(true);
            }

            var documentItem = GetDocumentItem(key, documentType);

            if (!documentItem.IsDeleted && BackingStore.TryGet(key, out value, _persistentValues) && documentType.IsAssignableFrom(value.GetType()))
            {
                OnInitialLoad(key, value);
                return(true);
            }

            return(false);
        }
コード例 #4
0
ファイル: UnitOfWork.cs プロジェクト: zuohd/Composable
 public void AddParticipants(IEnumerable <IUnitOfWorkParticipant> unitOfWorkParticipants)
 {
     _usageGuard.AssertNoContextChangeOccurred(this);
     Log.Debug("Adding participants");
     unitOfWorkParticipants.ForEach(AddParticipant);
 }
コード例 #5
0
        public TAggregate Get <TAggregate>(Guid aggregateId) where TAggregate : IEventStored
        {
            _usageGuard.AssertNoContextChangeOccurred(this);
            TAggregate result;

            if (!DoTryGet(aggregateId, out result))
            {
                throw new AggregateRootNotFoundException(aggregateId);
            }
            return(result);
        }