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; }
/// <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) { }
public Task <T> HandleAsync(DbDataReader reader, IIdentityMap map, QueryStatistics stats, CancellationToken token) { return(_handler.HandleAsync(reader, map, stats, token)); }
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)); }
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); } } }
public void Delete(IIdentityMap map, object id) { _parent.Delete(map, id); }
public DomainRepository(IEventStoreUnitOfWork <TDomainEvent> eventStoreUnitOfWork, IIdentityMap <TDomainEvent> identityMap) { _eventStoreUnitOfWork = eventStoreUnitOfWork; _identityMap = identityMap; }
public IEvent Handle(DbDataReader reader, IIdentityMap map, QueryStatistics stats) { return(reader.Read() ? _selector.Resolve(reader, map, stats) : null); }
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)); }
public T Handle(DbDataReader reader, IIdentityMap map, QueryStatistics stats) { return(reader.Read() ? storage.Resolve(0, reader, map) : default(T)); }
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); }
public StreamState Handle(DbDataReader reader, IIdentityMap map, QueryStatistics stats) { return(reader.Read() ? Resolve(reader, map, stats) : null); }
public EnumCache(IIdentityMap <FieldInfo, T> inner) { _inner = inner; }
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; }
public void Setup() { _mockery = new MockRepository( ); _mockIdentityMap = _mockery.DynamicMock <IIdentityMap <ICustomer> >( ); _mockMapper = _mockery.DynamicMock <ICustomerDataMapper>( ); }
public void Store(IIdentityMap map, object id, object entity) { _parent.Store(map, id, entity); }
private ICustomerRepository CreateSUT(IIdentityMap <ICustomer> identityMap, ICustomerDataMapper mapper) { return(new CustomerRepository(identityMap, mapper)); }
public Task <TResult> ResolveAsync(DbDataReader reader, IIdentityMap map, QueryStatistics stats, CancellationToken token) { return(reader.GetFieldValueAsync <TResult>(0, token)); }
public MartenQueryExecutor(IManagedConnection runner, IDocumentSchema schema, IIdentityMap identityMap) { Schema = schema; IdentityMap = identityMap; Connection = runner; }
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); } })); }
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); }
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; })); }
public IEnumerable <T> Handle(DbDataReader reader, IIdentityMap map, QueryStatistics stats) { return(_inner.Handle(reader, map, stats)); }
public T Handle(DbDataReader reader, IIdentityMap map, QueryStatistics stats) { return(_handler.Handle(reader, map, stats)); }
public async Task <IEnumerable <T> > HandleAsync(DbDataReader reader, IIdentityMap map, QueryStatistics stats, CancellationToken token) { return(await _inner.HandleAsync(reader, map, stats, token).ConfigureAwait(false)); }
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; }
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); }
public EnumCache() { _inner = new DictionaryIdentityMap <FieldInfo, T>(); }
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)); }
public T Resolve(DbDataReader reader, IIdentityMap map, QueryStatistics stats) { var json = reader.GetTextReader(0); return(map.Serializer.FromJson <T>(json)); }
public void Remove(IIdentityMap map, object entity) { _parent.Remove(map, entity); }