Example #1
0
 public EntityContext(
     IEntityContextFactory factory,
     IMappingsRepository mappings,
     IEntityStore entityStore,
     IEntitySource entitySource,
     IBaseUriSelectionPolicy baseUriSelector,
     IRdfTypeCache typeCache,
     IBlankNodeIdGenerator blankIdGenerator,
     IResultTransformerCatalog transformerCatalog,
     IEntityCaster caster,
     IDatasetChangesTracker changeTracker,
     ILogger log)
     : this(
         factory,
         mappings,
         entityStore,
         entitySource,
         baseUriSelector,
         typeCache,
         blankIdGenerator,
         transformerCatalog,
         caster,
         changeTracker,
         null,
         log)
 {
 }
Example #2
0
        public EntityContext(
            IEntityContextFactory factory,
            IMappingsRepository mappings,
            IEntityStore entityStore,
            IEntitySource entitySource,
            IBaseUriSelectionPolicy baseUriSelector,
            IRdfTypeCache typeCache,
            IBlankNodeIdGenerator blankIdGenerator,
            IResultTransformerCatalog transformerCatalog,
            IEntityCaster caster,
            IDatasetChangesTracker changeTracker,
            IResourceResolutionStrategy resourceResolutionStrategy,
            ILogger log)
            : this(changeTracker)
        {
            _factory                    = factory;
            _entityStore                = entityStore;
            _entitySource               = entitySource;
            _baseUriSelector            = baseUriSelector;
            _mappings                   = mappings;
            _typeCache                  = typeCache;
            _blankIdGenerator           = blankIdGenerator;
            _transformerCatalog         = transformerCatalog;
            _caster                     = caster;
            _typedEntityMapping         = _mappings.MappingFor <ITypedEntity>();
            _typesPropertyMapping       = _typedEntityMapping.PropertyFor("Types");
            _resourceResolutionStrategy = resourceResolutionStrategy;
            _log = log;

            if (_baseUriSelector == null)
            {
                _log.Warning("No Base URI Selection Policy. It will not be possible to use relative URIs");
            }
        }
Example #3
0
 /// <summary>Searches for property mappings.</summary>
 /// <param name="mappingsRepository">Repository to be queried.</param>
 /// <param name="declaringType">Type of entity.</param>
 /// <param name="propertyName">Property name to be searched for.</param>
 /// <returns>Property mapping or null.</returns>
 public static IPropertyMapping FindPropertyMapping(this IMappingsRepository mappingsRepository, Type declaringType, string propertyName)
 {
     return((from entityMapping in mappingsRepository
             where (entityMapping.EntityType == declaringType) || (declaringType.IsAssignableFrom(entityMapping.EntityType))
             from propertyMapping in entityMapping.Properties
             where propertyMapping.Name == propertyName
             select propertyMapping).FirstOrDefault());
 }
Example #4
0
 internal DefaultEntityContext(IEntitySource entitySource, IMappingsRepository mappingsRepository, IChangeDetector changeDetector)
 {
     _entitySource    = entitySource;
     Mappings         = mappingsRepository;
     _changeDetector  = changeDetector;
     _deletedEntities = new List <Iri>();
     _entityCache     = new ConcurrentDictionary <Iri, Entity>();
 }
Example #5
0
        /// <summary>Initializes a new instance of the <see cref="DefaultChangeDetector" /> class.</summary>
        /// <param name="mappingsRepository">Mappings repository.</param>
        internal DefaultChangeDetector(IMappingsRepository mappingsRepository)
        {
            if (mappingsRepository == null)
            {
                throw new ArgumentNullException(nameof(mappingsRepository));
            }

            _mappingsRepository = mappingsRepository;
        }
 public InternalProxyCaster(
     Func <Entity, IEntityMapping, IEntityProxy> proxyFactory,
     IMappingsRepository mappings,
     INamedGraphSelector graphSelector,
     IEntityStore store)
 {
     _createProxy          = proxyFactory;
     _mappings             = mappings;
     _graphSelector        = graphSelector;
     _store                = store;
     _typedEntityMapping   = _mappings.MappingFor <ITypedEntity>();
     _typesPropertyMapping = _typedEntityMapping.PropertyFor("Types");
     _cache                = new ConcurrentDictionary <IEntityContext, IDictionary <Entity, IDictionary <int, dynamic> > >();
 }
Example #7
0
        public void Setup()
        {
            _mappings = new TestMappingsRepository(new QueryableTests.NamedGraphsPersonMapping());
            _baseUriSelectionPolicy = new Mock <IBaseUriSelectionPolicy>();
            _baseUriSelectionPolicy.Setup(policy => policy.SelectBaseUri(It.IsAny <EntityId>())).Returns(new Uri("http://test/"));
            _entitySource = new Mock <IEntitySource>(MockBehavior.Strict);
            _store        = new Mock <IEntityStore>(MockBehavior.Strict);
            _store.Setup(store => store.AssertEntity(It.IsAny <EntityId>(), It.IsAny <IEnumerable <IEntityQuad> >()));

            _entityContext = new Mock <IEntityContext>(MockBehavior.Strict);
            _entityContext.Setup(context => context.Create <IPerson>(It.IsAny <EntityId>())).Returns((EntityId id) => CreatePersonEntity(id));
            _entityContext.SetupGet(context => context.Mappings).Returns(_mappings);
            _entityContext.SetupGet(context => context.BaseUriSelector).Returns(_baseUriSelectionPolicy.Object);

            _persons     = new EntityQueryable <IPerson>(_entityContext.Object, _entitySource.Object, _store.Object);
            _testQueries = GetTestQueries();
        }
        public void Setup()
        {
            _mappings = new TestMappingsRepository(new QueryableTests.NamedGraphsPersonMapping());
            _baseUriSelectionPolicy = new Mock<IBaseUriSelectionPolicy>();
            _baseUriSelectionPolicy.Setup(policy => policy.SelectBaseUri(It.IsAny<EntityId>())).Returns(new Uri("http://test/"));
            _entitySource = new Mock<IEntitySource>(MockBehavior.Strict);
            _entityStore = new Mock<IEntityStore>(MockBehavior.Strict);
            _entityStore.Setup(store => store.AssertEntity(It.IsAny<EntityId>(), It.IsAny<IEnumerable<EntityQuad>>()));

            _entityContext = new Mock<IEntityContext>(MockBehavior.Strict);
            _entityContext.Setup(context => context.Load<IPerson>(It.IsAny<EntityId>())).Returns((EntityId id) => CreatePersonEntity(id));
            _entityContext.Setup(context => context.Store).Returns(_entityStore.Object);
            _entityContext.SetupGet(context => context.Mappings).Returns(_mappings);
            _entityContext.SetupGet(context => context.BaseUriSelector).Returns(_baseUriSelectionPolicy.Object);

            _persons = new EntityQueryable<IPerson>(_entityContext.Object, _entitySource.Object, _mappings, _baseUriSelectionPolicy.Object);
            _testQueries = GetTestQueries();
        }
Example #9
0
        /// <summary>Searches for class mappings.</summary>
        /// <param name="mappingsRepository">Repository to be queried.</param>
        /// <param name="type">Type of entity.</param>
        /// <returns>Class mapping or null.</returns>
        public static IEnumerable <Uri> FindMappedClasses(this IMappingsRepository mappingsRepository, Type type)
        {
            IEnumerable <Uri> result = new Uri[0];

            if ((mappingsRepository != null) && (type != null))
            {
                IEntityMapping entityMapping = mappingsRepository.FindEntityMapping(type);
                if (entityMapping == null)
                {
                    entityMapping = mappingsRepository.FindEntityMapping(type.FindEntityType());
                }

                if (entityMapping != null)
                {
                    result = entityMapping.Classes.OfType <IQueryableClassMapping>().SelectMany(cm => cm.Uris).Distinct(AbsoluteUriComparer.Default);
                }
            }

            return(result);
        }
Example #10
0
 /// <summary>Searches for entity mappings.</summary>
 /// <typeparam name="T">Type of entity.</typeparam>
 /// <param name="mappingsRepository">Repository to be queried.</param>
 /// <returns>Entity mapping or null.</returns>
 public static IEntityMapping FindEntityMapping <T>(this IMappingsRepository mappingsRepository) where T : IEntity
 {
     return(mappingsRepository.FindEntityMapping(typeof(T)));
 }
Example #11
0
 /// <summary>Searches for entity mappings.</summary>
 /// <param name="mappingsRepository">Repository to be queried.</param>
 /// <param name="type">Type of entity.</param>
 /// <returns>Entity mapping or null.</returns>
 public static IEntityMapping FindEntityMapping(this IMappingsRepository mappingsRepository, Type type)
 {
     return(mappingsRepository.MappingFor(type));
 }
Example #12
0
 /// <summary>Searches for property mappings.</summary>
 /// <param name="mappingsRepository">Repository to be queried.</param>
 /// <param name="property">Property to be searched for.</param>
 /// <returns>Property mapping or null.</returns>
 public static IPropertyMapping FindPropertyMapping(this IMappingsRepository mappingsRepository, PropertyInfo property)
 {
     return(mappingsRepository.FindPropertyMapping(property.DeclaringType, property.Name));
 }
Example #13
0
 /// <summary>Searches for property mappings.</summary>
 /// <typeparam name="T">Type of entity.</typeparam>
 /// <param name="mappingsRepository">Repository to be queried.</param>
 /// <param name="propertyName">Property name to be searched for.</param>
 /// <returns>Property mapping or null.</returns>
 public static IPropertyMapping FindPropertyMapping <T>(this IMappingsRepository mappingsRepository, string propertyName) where T : IEntity
 {
     return(mappingsRepository.FindPropertyMapping(typeof(T), propertyName));
 }
Example #14
0
 /// <summary>Searches for class mappings.</summary>
 /// <param name="mappingsRepository">Repository to be queried.</param>
 /// <typeparam name="T">Type of entity.</typeparam>
 /// <returns>Class mapping or null.</returns>
 public static IEnumerable <Uri> FindMappedClasses <T>(this IMappingsRepository mappingsRepository)
 {
     return(mappingsRepository.FindMappedClasses(typeof(T)));
 }
 internal TransactionLabeller(T mappingsRepo)
 {
     this.mappingsRepo = mappingsRepo;
     mappings          = this.mappingsRepo.Get();
     this.mappingsRepo.RegisterCallbackOnUpdate(mappings => this.mappings = mappings);
 }