public void RemoveRelation(IRelationById item, AbstractScopedCache repositoryScopedCache) { var sessionIdAsString = GetSessionId().ToString("n"); using (DisposableTimer.TraceDuration <NhSessionHelper>("In RemoveRelation for session " + sessionIdAsString, "End RemoveRelation for session " + sessionIdAsString)) { var relationType = GetOrCreateNodeRelationType(item.Type.RelationName, repositoryScopedCache); // Nh should handle this for us but got an error with mappings atm in SqlCe (APN 09/11/11) // Clear session cache to make sure it loads all of the tags in order to delete them all NhSession.Flush(); // Clear the repository cache of this relation in case one has been added and then removed in the same unit of work var cacheKey = GenerateCacheKeyForRelation(item, relationType); repositoryScopedCache.InvalidateItems(cacheKey); var sourceIdValue = (Guid)item.SourceId.Value; var destinationIdValue = (Guid)item.DestinationId.Value; var existingRelation = GetDbRelation(relationType.Alias, sourceIdValue, destinationIdValue).ToArray(); if (existingRelation.Any()) { existingRelation.ForEach(x => NhSession.Delete(x)); } } }
protected AbstractRepositoryGroup(GroupedProviderMetadata providers, Uri idRoot, AbstractScopedCache scopedCache, RepositoryContext hiveContext) { Providers = providers; IdRoot = idRoot; UnitScopedCache = scopedCache; HiveContext = hiveContext; }
protected DefaultFrameworkContext(AbstractScopedCache scopedCache, AbstractApplicationCache applicationCache, AbstractFinalizer finalizer) { ScopedCache = scopedCache; ApplicationCache = applicationCache; ScopedFinalizer = finalizer; }
public void Setup() { _frameworkContext = new FakeFrameworkContext(); _unitScopedCache = new DictionaryScopedCache(); var providerGroup = GroupedProviderMockHelper.GenerateProviderGroup(1, 0, 1, _frameworkContext); var idRoot = new Uri("oh-yeah://this-is-my-root/"); _groupUnitFactory = new GroupUnitFactory(providerGroup.Writers, idRoot, FakeHiveCmsManager.CreateFakeRepositoryContext(_frameworkContext), _frameworkContext, () => _unitScopedCache); }
protected DefaultFrameworkContext(AbstractScopedCache scopedCache, AbstractApplicationCache applicationCache, AbstractFinalizer finalizer, IFrameworkCaches caches, AbstractSerializationService serialization) { ScopedCache = scopedCache; ApplicationCache = applicationCache; ScopedFinalizer = finalizer; Caches = caches; Serialization = serialization; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultFrameworkContext"/> class. /// </summary> /// <param name="textManager">The text manager.</param> /// <param name="typeMappers">The type mappers.</param> /// <param name="scopedCache">The scoped cache.</param> /// <param name="applicationCache">The application cache</param> /// <param name="finalizer"></param> /// <param name="taskMgr"></param> /// <remarks></remarks> public DefaultFrameworkContext( TextManager textManager, MappingEngineCollection typeMappers, AbstractScopedCache scopedCache, AbstractApplicationCache applicationCache, AbstractFinalizer finalizer, ApplicationTaskManager taskMgr) : this(scopedCache, applicationCache, finalizer) { TextManager = textManager; TypeMappers = typeMappers; TaskManager = taskMgr; }
public ProviderUnit(AbstractEntityRepository entityRepository, AbstractScopedCache unitScopedCache) { EntityRepository = entityRepository; WorkCompleting += (obj, target) => { EntityRepository.PrepareForCompletion(); EntityRepository.Revisions.PrepareForCompletion(); EntityRepository.Schemas.PrepareForCompletion(); EntityRepository.Schemas.Revisions.PrepareForCompletion(); }; FrameworkContext = entityRepository.FrameworkContext; UnitScopedCache = unitScopedCache; }
public GroupUnit(IEnumerable <ProviderUnit> providerUnits, Uri idRoot, AbstractScopedCache scopedCache, bool canDisposeCache, IFrameworkContext frameworkContext, RepositoryContext hiveContext) { // Only check that providerUnits is not null, it's OK if it's empty - might be a group unit for a group that can't do anything :) Mandate.ParameterNotNull(providerUnits, "providerUnits"); Mandate.ParameterNotNull(idRoot, "idRoot"); Mandate.ParameterNotNull(scopedCache, "scopedCache"); ProviderUnits = providerUnits; IdRoot = idRoot; _canDisposeCache = canDisposeCache; UnitScopedCache = scopedCache; FrameworkContext = frameworkContext ?? providerUnits.First().EntityRepository.FrameworkContext; WasAbandoned = false; var enumerable = ProviderUnits.ToArray(); var entityRepositories = enumerable.Select(y => { y.EntityRepository.HiveContext = hiveContext; return(y.EntityRepository); }).ToList(); var providerEntityRevisionRepositories = enumerable.Select(y => { y.EntityRepository.Revisions.HiveContext = hiveContext; return(y.EntityRepository.Revisions); }).ToList(); var schemaRepositories = enumerable.Select(y => { y.EntityRepository.Schemas.HiveContext = hiveContext; return(y.EntityRepository.Schemas); }).ToList(); var providerSchemaRevisionRepositories = enumerable.Select(y => { y.EntityRepository.Schemas.Revisions.HiveContext = hiveContext; return(y.EntityRepository.Schemas.Revisions); }).ToList(); _entityRepository = new EntityRepositoryGroup <TFilter>(entityRepositories, providerEntityRevisionRepositories, schemaRepositories, providerSchemaRevisionRepositories, IdRoot, UnitScopedCache, FrameworkContext, hiveContext); }
public QueryableDataSourceWrapper(IEnumerable <AbstractReadonlyEntityRepository> repositoryPool, ICoreReadonlyRelationsRepository groupRepo, Uri idRoot, IFrameworkContext context, AbstractScopedCache containerScopedCache, RepositoryContext hiveContext) { _idRoot = idRoot; _groupRepo = groupRepo; _repositoryPool = repositoryPool; FrameworkContext = context; ContainerScopedCache = containerScopedCache; HiveContext = hiveContext; }
public ReadonlyEntityRepositoryGroup(IEnumerable <AbstractReadonlyEntityRepository> childRepositories, IEnumerable <AbstractReadonlyRevisionRepository <TypedEntity> > childRevisionSessions, IEnumerable <AbstractReadonlySchemaRepository> childSchemaSessions, IEnumerable <AbstractReadonlyRevisionRepository <EntitySchema> > childSchemaRevisionSessions, Uri idRoot, AbstractScopedCache scopedCache, IFrameworkContext context, RepositoryContext hiveContext) : base(childRepositories, idRoot, scopedCache, hiveContext) { ChildSessions = childRepositories; Revisions = new ReadonlyRevisionRepositoryGroup <TFilter, TypedEntity>(childRevisionSessions, IdRoot, scopedCache, hiveContext); Schemas = new ReadonlySchemaRepositoryGroup <TFilter>(childSchemaSessions, childSchemaRevisionSessions, IdRoot, scopedCache, hiveContext); FrameworkContext = context; }
public ReadonlyGroupUnit(IEnumerable <ReadonlyProviderUnit> providerUnits, Uri idRoot, AbstractScopedCache scopedCache, bool canDisposeCache, IFrameworkContext frameworkContext, RepositoryContext hiveContext) { Mandate.ParameterNotNull(providerUnits, "providerUnits"); Mandate.ParameterNotNull(idRoot, "idRoot"); Mandate.ParameterNotNull(scopedCache, "scopedCache"); ProviderUnits = providerUnits; IdRoot = idRoot; _canDisposeCache = canDisposeCache; UnitScopedCache = scopedCache; FrameworkContext = frameworkContext ?? providerUnits.First().EntityRepository.FrameworkContext; var enumerable = ProviderUnits.ToArray(); var entityRepositories = enumerable.Select(y => { y.EntityRepository.HiveContext = hiveContext; return(y.EntityRepository); }).ToList(); var providerEntityRevisionRepositories = enumerable.Select(y => { y.EntityRepository.Revisions.HiveContext = hiveContext; return(y.EntityRepository.Revisions); }).ToList(); var schemaRepositories = enumerable.Select(y => { y.EntityRepository.Schemas.HiveContext = hiveContext; return(y.EntityRepository.Schemas); }).ToList(); var providerSchemaRevisionRepositories = enumerable.Select(y => { y.EntityRepository.Schemas.Revisions.HiveContext = hiveContext; return(y.EntityRepository.Schemas.Revisions); }).ToList(); _entitySession = new ReadonlyEntityRepositoryGroup <TFilter>(entityRepositories, providerEntityRevisionRepositories, schemaRepositories, providerSchemaRevisionRepositories, IdRoot, UnitScopedCache, FrameworkContext, hiveContext); }
public NodeRelationType GetOrCreateNodeRelationType(string alias, AbstractScopedCache repositoryScopedCache) { return(repositoryScopedCache.GetOrCreateTyped( "NodeRelationType-" + alias, () => { var existing = NhSession.QueryOver <NodeRelationType>() .Where(x => x.Alias == alias) .Cacheable() .Take(1) .SingleOrDefault <NodeRelationType>(); return existing ?? new NodeRelationType() { Alias = alias, Id = alias.EncodeAsGuid() }; })); }
public EntityRepositoryGroup(IEnumerable <AbstractEntityRepository> childRepositories, IEnumerable <AbstractRevisionRepository <TypedEntity> > childRevisionSessions, IEnumerable <AbstractSchemaRepository> childSchemaSessions, IEnumerable <AbstractRevisionRepository <EntitySchema> > childSchemaRevisionSessions, Uri idRoot, AbstractScopedCache scopedCache, IFrameworkContext frameworkContext, RepositoryContext hiveContext) : base(childRepositories, idRoot, scopedCache, hiveContext) { Mandate.ParameterNotNull(idRoot, "idRoot"); Mandate.ParameterNotNull(scopedCache, "scopedCache"); Mandate.ParameterNotNullOrEmpty(childRepositories, "childRepositories"); Mandate.ParameterNotNullOrEmpty(childRevisionSessions, "childRevisionSessions"); Mandate.ParameterNotNullOrEmpty(childSchemaSessions, "childSchemaSessions"); Mandate.ParameterNotNullOrEmpty(childSchemaRevisionSessions, "childSchemaRevisionSessions"); ChildSessions = childRepositories; FrameworkContext = frameworkContext ?? childRepositories.First().FrameworkContext; Revisions = new RevisionRepositoryGroup <TFilter, TypedEntity>(childRevisionSessions, IdRoot, scopedCache, hiveContext); Schemas = new SchemaRepositoryGroup <TFilter>(childSchemaSessions, childSchemaRevisionSessions, IdRoot, scopedCache, hiveContext); }
public HiveQueryResultEventArgs(IEnumerable <object> results, QueryDescription query, AbstractScopedCache scopedCache) { Results = results; ScopedCache = scopedCache; QueryDescription = query; }
public HiveRevisionPreActionEventArgs(IRevision <IVersionableEntity> entity, AbstractScopedCache scopedCache) : base(scopedCache) { Entity = entity; }
public ReadonlyRevisionRepositoryGroup(IEnumerable <AbstractReadonlyRevisionRepository <T> > childRepositories, Uri idRoot, AbstractScopedCache scopedCache, RepositoryContext hiveContext) : base(childRepositories, idRoot, scopedCache, hiveContext) { ChildSessions = childRepositories; }
public HiveEntityPreActionEventArgs(IRelatableEntity entity, AbstractScopedCache scopedCache) : base(scopedCache) { Entity = entity; }
public HiveEntityPostDeletionEventArgs(HiveId id, AbstractScopedCache scopedCache) : base(scopedCache) { Id = id; }
public HiveRelationByIdPostActionEventArgs(IRelationById relation, AbstractScopedCache scopedCache) : base(scopedCache) { Relation = relation; }
public HiveSchemaPreActionEventArgs(AbstractSchemaPart schemaPart, AbstractScopedCache scopedCache) : base(scopedCache) { SchemaPart = schemaPart; }
public HiveRelationPostActionEventArgs(IReadonlyRelation <IRelatableEntity, IRelatableEntity> relation, AbstractScopedCache scopedCache) : base(scopedCache) { Relation = relation; }
public AbstractHiveEventArgs(AbstractScopedCache scopedCache) { ScopedCache = scopedCache; }
public HiveRevisionPostActionEventArgs(IRevision <IVersionableEntity> entity, AbstractScopedCache scopedCache) { Entity = entity; ScopedCache = scopedCache; }
public HiveSchemaPostActionEventArgs(AbstractSchemaPart schemaPart, AbstractScopedCache scopedCache) { SchemaPart = schemaPart; ScopedCache = scopedCache; }
protected AbstractRepositoryGroup(IEnumerable <AbstractProviderRepository> childRepositories, Uri idRoot, AbstractScopedCache scopedCache, RepositoryContext hiveContext) : this(new GroupedProviderMetadata(childRepositories), idRoot, scopedCache, hiveContext) { }
public void AddRelation(IReadonlyRelation <IRelatableEntity, IRelatableEntity> item, AbstractScopedCache repositoryScopedCache) { var sessionIdAsString = GetSessionId().ToString("n"); using (DisposableTimer.TraceDuration <NhSessionHelper>("In AddRelation for session " + sessionIdAsString, "End AddRelation for session " + sessionIdAsString)) { // Get the source and destination items from the Nh session var sourceNode = NhSession.Get <Node>((Guid)item.SourceId.Value); var destNode = NhSession.Get <Node>((Guid)item.DestinationId.Value); // Check the Nh session is already aware of the items if (sourceNode == null || destNode == null) { string extraMessage = string.Empty; if (sourceNode == null) { extraMessage = "Source {0} cannot be found.\n".InvariantFormat(item.SourceId.Value); } if (destNode == null) { extraMessage += "Destination {0} cannot be found.".InvariantFormat(item.DestinationId.Value); } throw new InvalidOperationException( "Before adding a relation between source {0} and destination {1}, you must call AddOrUpdate with those items or they must already exist in the datastore.\n{2}" .InvariantFormat(item.SourceId, item.DestinationId, extraMessage)); } // Try to load an existing relation of the same type between the two var relationType = GetOrCreateNodeRelationType(item.Type.RelationName, repositoryScopedCache); // Grab the existing relation (if exists) using the compound key of start node / end node / relation type var cacheKey = GenerateCacheKeyForRelation(item, relationType); NodeRelation relationToReturn = repositoryScopedCache.GetOrCreateTyped( cacheKey, () => { return(NhSession .QueryOver <NodeRelation>() .Where(x => x.StartNode == sourceNode && x.EndNode == destNode && x.NodeRelationType == relationType) .Cacheable() .SingleOrDefault()); }); // Avoid a duplicate by checking if one already exists if (relationToReturn != null) { // Make sure existing relation has ordinal relationToReturn.Ordinal = item.Ordinal; } else { // Create a new relation relationToReturn = new NodeRelation { StartNode = sourceNode, EndNode = destNode, NodeRelationType = relationType, Ordinal = item.Ordinal }; relationToReturn = NhSession.Merge(relationToReturn) as NodeRelation; } // Ensure metadata correct on existing or new entity CreateAndAddRelationTags(item, relationToReturn); } }
public ReadonlyProviderUnit(AbstractReadonlyEntityRepository entityRepository, AbstractScopedCache unitScopedCache) { EntityRepository = entityRepository; FrameworkContext = entityRepository.FrameworkContext; UnitScopedCache = unitScopedCache; }
public HiveEntityPostActionEventArgs(IRelatableEntity entity, AbstractScopedCache scopedCache) { Entity = entity; ScopedCache = scopedCache; }
public HiveQueryResultEventArgs(object result, QueryDescription query, AbstractScopedCache scopedCache) : this(Enumerable.Repeat(result, 1).ToArray(), query, scopedCache) { }
/// <summary> /// Initializes a new instance of the <see cref="DefaultFrameworkContext"/> class. /// </summary> /// <param name="textManager">The text manager.</param> /// <param name="typeMappers">The type mappers.</param> /// <param name="scopedCache">The scoped cache.</param> /// <param name="applicationCache">The application cache</param> /// <param name="finalizer">The finalizer.</param> /// <param name="taskMgr">The task manager.</param> /// <param name="caches">The lifetime-managed cache providers.</param> public DefaultFrameworkContext( TextManager textManager, MappingEngineCollection typeMappers, AbstractScopedCache scopedCache, AbstractApplicationCache applicationCache, AbstractFinalizer finalizer, ApplicationTaskManager taskMgr, IFrameworkCaches caches, AbstractSerializationService serialization) : this(scopedCache, applicationCache, finalizer, caches, serialization) { TextManager = textManager; TypeMappers = typeMappers; TaskManager = taskMgr; }
public static IGroupUnit <TFilter> OpenWriter <TFilter>(this IHiveManager hiveManager, AbstractScopedCache overrideCacheScope = null) where TFilter : class, IProviderTypeFilter { var factory = hiveManager.GetWriter <TFilter>(); return(factory.Create <TFilter>(overrideCacheScope)); }