public NakedObjectManager(IMetamodelManager metamodel, ISession session, IIdentityMap identityMap, IOidGenerator oidGenerator, NakedObjectFactory nakedObjectFactory) {
            Assert.AssertNotNull(metamodel);
            Assert.AssertNotNull(session);
            Assert.AssertNotNull(identityMap);
            Assert.AssertNotNull(oidGenerator);
            Assert.AssertNotNull(nakedObjectFactory);

            this.metamodel = metamodel;
            this.session = session;
            this.identityMap = identityMap;
            this.oidGenerator = oidGenerator;
            this.nakedObjectFactory = nakedObjectFactory;
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Repository{T}"/> class.
 /// </summary>
 /// <param name="identityMap">The identity map.</param>
 public Repository(IIdentityMap identityMap)
     : base(identityMap)
 {
 }
예제 #3
0
 public Task <T> HandleAsync(DbDataReader reader, IIdentityMap map, QueryStatistics stats, CancellationToken token)
 {
     return(_handler.HandleAsync(reader, map, stats, token));
 }
예제 #4
0
        public static Task <IList <T> > ResolveAsync <T>(this IManagedConnection runner, NpgsqlCommand cmd, ISelector <T> selector, IIdentityMap map, CancellationToken token)
        {
            var selectMap = map.ForQuery();

            return(runner.ExecuteAsync(cmd, async(c, tkn) =>
            {
                var list = new List <T>();
                using (var reader = await cmd.ExecuteReaderAsync(tkn).ConfigureAwait(false))
                {
                    while (await reader.ReadAsync(tkn).ConfigureAwait(false))
                    {
                        list.Add(selector.Resolve(reader, selectMap));
                    }
                }

                return list.As <IList <T> >();
            }, token));
        }
예제 #5
0
        public static async Task <T> FetchAsync <T>(this IManagedConnection runner, IQueryHandler <T> handler, IIdentityMap map, CancellationToken token)
        {
            var command = new NpgsqlCommand();

            handler.ConfigureCommand(command);

            return(await runner.ExecuteAsync(command, async (c, tkn) =>
            {
                using (var reader = await command.ExecuteReaderAsync(tkn).ConfigureAwait(false))
                {
                    return await handler.HandleAsync(reader, map, tkn).ConfigureAwait(false);
                }
            }, token).ConfigureAwait(false));
        }
 public Single_threaded_tests()
 {
     // Arbitrary expiration policy. We won't be validating expirations in these tests
     // because it's tricky to do so with MemoryCache.
     this.identityMap = new MemoryCacheIdentityMap<TestEntity>(TimeSpan.FromSeconds(10), Substitute.For<ILogger>());
 }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        protected virtual void ValidateData([NotNull] IModel model)
        {
            Check.NotNull(model, nameof(model));

            var identityMaps        = new Dictionary <IKey, IIdentityMap>();
            var sensitiveDataLogged = Dependencies.Logger.ShouldLogSensitiveData();

            foreach (var entityType in model.GetEntityTypes().Where(et => !et.IsQueryType))
            {
                var          key         = entityType.FindPrimaryKey();
                IIdentityMap identityMap = null;
                foreach (var seedDatum in entityType.GetData())
                {
                    foreach (var property in entityType.GetProperties())
                    {
                        if (!seedDatum.TryGetValue(property.Name, out var value) ||
                            value == null)
                        {
                            if (!property.IsNullable &&
                                ((!property.RequiresValueGenerator() &&
                                  (property.ValueGenerated & ValueGenerated.OnAdd) == 0) ||
                                 property.IsKey()))
                            {
                                throw new InvalidOperationException(CoreStrings.SeedDatumMissingValue(entityType.DisplayName(), property.Name));
                            }
                        }
                        else if (property.RequiresValueGenerator() &&
                                 property.IsKey() &&
                                 property.ClrType.IsDefaultValue(value))
                        {
                            if (property.ClrType.IsSignedInteger())
                            {
                                throw new InvalidOperationException(CoreStrings.SeedDatumSignedNumericValue(entityType.DisplayName(), property.Name));
                            }

                            throw new InvalidOperationException(CoreStrings.SeedDatumDefaultValue(entityType.DisplayName(), property.Name, property.ClrType.GetDefaultValue()));
                        }
                        else if (!property.ClrType.GetTypeInfo().IsAssignableFrom(value.GetType().GetTypeInfo()))
                        {
                            if (sensitiveDataLogged)
                            {
                                throw new InvalidOperationException(
                                          CoreStrings.SeedDatumIncompatibleValueSensitive(
                                              entityType.DisplayName(), value, property.Name, property.ClrType.DisplayName()));
                            }

                            throw new InvalidOperationException(
                                      CoreStrings.SeedDatumIncompatibleValue(
                                          entityType.DisplayName(), property.Name, property.ClrType.DisplayName()));
                        }
                    }

                    var keyValues = new object[key.Properties.Count];
                    for (var i = 0; i < key.Properties.Count; i++)
                    {
                        keyValues[i] = seedDatum[key.Properties[i].Name];
                    }

                    foreach (var navigation in entityType.GetNavigations())
                    {
                        if (seedDatum.TryGetValue(navigation.Name, out var value) &&
                            ((navigation.IsCollection() && value is IEnumerable collection && collection.Any()) ||
                             (!navigation.IsCollection() && value != null)))
                        {
                            if (sensitiveDataLogged)
                            {
                                throw new InvalidOperationException(
                                          CoreStrings.SeedDatumNavigationSensitive(
                                              entityType.DisplayName(),
                                              string.Join(", ", key.Properties.Select((p, i) => p.Name + ":" + keyValues[i])),
                                              navigation.Name,
                                              navigation.GetTargetType().DisplayName(),
                                              Property.Format(navigation.ForeignKey.Properties)));
                            }

                            throw new InvalidOperationException(
                                      CoreStrings.SeedDatumNavigation(
                                          entityType.DisplayName(),
                                          navigation.Name,
                                          navigation.GetTargetType().DisplayName(),
                                          Property.Format(navigation.ForeignKey.Properties)));
                        }
                    }

                    if (identityMap == null)
                    {
                        if (!identityMaps.TryGetValue(key, out identityMap))
                        {
                            identityMap       = key.GetIdentityMapFactory()(sensitiveDataLogged);
                            identityMaps[key] = identityMap;
                        }
                    }

                    var entry = identityMap.TryGetEntry(keyValues);
                    if (entry != null)
                    {
                        if (sensitiveDataLogged)
                        {
                            throw new InvalidOperationException(
                                      CoreStrings.SeedDatumDuplicateSensitive(
                                          entityType.DisplayName(), string.Join(", ", key.Properties.Select((p, i) => p.Name + ":" + keyValues[i]))));
                        }

                        throw new InvalidOperationException(
                                  CoreStrings.SeedDatumDuplicate(
                                      entityType.DisplayName(), Property.Format(key.Properties)));
                    }

                    entry = new InternalShadowEntityEntry(null, entityType);

                    identityMap.Add(keyValues, entry);
                }
            }
        }
예제 #8
0
 public void Delete(IIdentityMap map, object id)
 {
     _parent.Delete(map, id);
 }
예제 #9
0
 public DomainRepository(IEventStoreUnitOfWork <TDomainEvent> eventStoreUnitOfWork, IIdentityMap <TDomainEvent> identityMap)
 {
     _eventStoreUnitOfWork = eventStoreUnitOfWork;
     _identityMap          = identityMap;
 }
예제 #10
0
 public IEvent Handle(DbDataReader reader, IIdentityMap map, QueryStatistics stats)
 {
     return(reader.Read() ? _selector.Resolve(reader, map, stats) : null);
 }
예제 #11
0
 public async Task <T> HandleAsync(DbDataReader reader, IIdentityMap map, QueryStatistics stats, CancellationToken token)
 {
     return(await reader.ReadAsync(token).ConfigureAwait(false)
         ? await storage.ResolveAsync(0, reader, map, token).ConfigureAwait(false) : default(T));
 }
예제 #12
0
 public T Handle(DbDataReader reader, IIdentityMap map, QueryStatistics stats)
 {
     return(reader.Read() ? storage.Resolve(0, reader, map) : default(T));
 }
예제 #13
0
 public async Task <StreamState> HandleAsync(DbDataReader reader, IIdentityMap map, QueryStatistics stats, CancellationToken token)
 {
     return(await reader.ReadAsync(token).ConfigureAwait(false)
         ? await ResolveAsync(reader, map, stats, token).ConfigureAwait(false)
         : null);
 }
예제 #14
0
 public StreamState Handle(DbDataReader reader, IIdentityMap map, QueryStatistics stats)
 {
     return(reader.Read() ? Resolve(reader, map, stats) : null);
 }
예제 #15
0
 public EnumCache(IIdentityMap <FieldInfo, T> inner)
 {
     _inner = inner;
 }
예제 #16
0
        private IIdentityMap GetOrCreateIdentityMap(IKey key)
        {
            if (_identityMap0 == null)
            {
                _identityMap0 = key.GetIdentityMapFactory()();
                return _identityMap0;
            }

            if (_identityMap0.Key == key)
            {
                return _identityMap0;
            }

            if (_identityMap1 == null)
            {
                _identityMap1 = key.GetIdentityMapFactory()();
                return _identityMap1;
            }

            if (_identityMap1.Key == key)
            {
                return _identityMap1;
            }

            if (_identityMaps == null)
            {
                _identityMaps = new Dictionary<IKey, IIdentityMap>();
            }

            IIdentityMap identityMap;
            if (!_identityMaps.TryGetValue(key, out identityMap))
            {
                identityMap = key.GetIdentityMapFactory()();
                _identityMaps[key] = identityMap;
            }
            return identityMap;
        }
예제 #17
0
 public void Setup()
 {
     _mockery         = new MockRepository( );
     _mockIdentityMap = _mockery.DynamicMock <IIdentityMap <ICustomer> >( );
     _mockMapper      = _mockery.DynamicMock <ICustomerDataMapper>( );
 }
예제 #18
0
 public void Store(IIdentityMap map, object id, object entity)
 {
     _parent.Store(map, id, entity);
 }
예제 #19
0
 private ICustomerRepository CreateSUT(IIdentityMap <ICustomer> identityMap, ICustomerDataMapper mapper)
 {
     return(new CustomerRepository(identityMap, mapper));
 }
예제 #20
0
 public Task <TResult> ResolveAsync(DbDataReader reader, IIdentityMap map, QueryStatistics stats, CancellationToken token)
 {
     return(reader.GetFieldValueAsync <TResult>(0, token));
 }
예제 #21
0
 public MartenQueryExecutor(IManagedConnection runner, IDocumentSchema schema, IIdentityMap identityMap)
 {
     Schema      = schema;
     IdentityMap = identityMap;
     Connection  = runner;
 }
예제 #22
0
        public static T Fetch <T>(this IManagedConnection runner, IQueryHandler <T> handler, IIdentityMap map)
        {
            var command = new NpgsqlCommand();

            handler.ConfigureCommand(command);

            return(runner.Execute(command, c =>
            {
                using (var reader = command.ExecuteReader())
                {
                    return handler.Handle(reader, map);
                }
            }));
        }
예제 #23
0
        public DocumentSession(StoreOptions options, IDocumentSchema schema, ISerializer serializer, IManagedConnection connection, IQueryParser parser, IIdentityMap identityMap) : base(schema, serializer, connection, parser, identityMap)
        {
            _options    = options;
            _schema     = schema;
            _serializer = serializer;
            _connection = connection;

            _identityMap = identityMap;
            _unitOfWork  = new UnitOfWork(_schema);

            if (_identityMap is IDocumentTracker)
            {
                _unitOfWork.AddTracker(_identityMap.As <IDocumentTracker>());
            }

            Events = new EventStore(this, _identityMap, schema, _serializer, _connection);
        }
예제 #24
0
        public static IList <T> Resolve <T>(this IManagedConnection runner, NpgsqlCommand cmd, ISelector <T> selector, IIdentityMap map)
        {
            var selectMap = map.ForQuery();

            return(runner.Execute(cmd, c =>
            {
                var list = new List <T>();

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        list.Add(selector.Resolve(reader, selectMap));
                    }
                }

                return list;
            }));
        }
예제 #25
0
 public IEnumerable <T> Handle(DbDataReader reader, IIdentityMap map, QueryStatistics stats)
 {
     return(_inner.Handle(reader, map, stats));
 }
예제 #26
0
 public T Handle(DbDataReader reader, IIdentityMap map, QueryStatistics stats)
 {
     return(_handler.Handle(reader, map, stats));
 }
예제 #27
0
 public async Task <IEnumerable <T> > HandleAsync(DbDataReader reader, IIdentityMap map, QueryStatistics stats,
                                                  CancellationToken token)
 {
     return(await _inner.HandleAsync(reader, map, stats, token).ConfigureAwait(false));
 }
예제 #28
0
        public QuerySession(DocumentStore store, IManagedConnection connection, IQueryParser parser, IIdentityMap identityMap, ITenant tenant)
        {
            Tenant       = tenant;
            _store       = store;
            _connection  = connection;
            _parser      = parser;
            _identityMap = identityMap;

            WriterPool = store.CreateWriterPool();
            Serializer = store.Serializer;
        }
예제 #29
0
 public T Resolve(IIdentityMap map, ILoader loader, object id)
 {
     // TODO -- watch it here if it's the wrong type
     return(map.Get(id, () => loader.LoadDocument <TBase>(id)) as T);
 }
예제 #30
0
 public EnumCache()
 {
     _inner = new DictionaryIdentityMap <FieldInfo, T>();
 }
예제 #31
0
 public Task <T> ResolveAsync(IIdentityMap map, ILoader loader, CancellationToken token, object id)
 {
     return(map.GetAsync(id, tk => loader.LoadDocumentAsync <TBase>(id, tk), token)
            .ContinueWith(x => x.Result as T, token));
 }
예제 #32
0
        public T Resolve(DbDataReader reader, IIdentityMap map, QueryStatistics stats)
        {
            var json = reader.GetTextReader(0);

            return(map.Serializer.FromJson <T>(json));
        }
예제 #33
0
 public void Remove(IIdentityMap map, object entity)
 {
     _parent.Remove(map, entity);
 }