예제 #1
0
        public async Task NotUniqueConstraintIndex()
        {
            var store = await StoreBuilder.New().CreateAsync();

            var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();

            var domain = await store.DomainModels.New().CreateAsync("Test");

            var graph = domain.Resolve <IHyperGraph>() as Hyperstore.Modeling.HyperGraph.HyperGraph;
            MemoryIndexManager manager = graph.IndexManager as MemoryIndexManager;

            manager.CreateIndex(schema.Definition.XExtendsBaseClass, "index1", false, "Name");

            manager.AddToIndex(schema.Definition.XExtendsBaseClass, "index1", new Identity("Test", "1"), "momo");
            manager.AddToIndex(schema.Definition.XExtendsBaseClass, "index1", new Identity("Test", "2"), "momo");
            var index = manager.GetIndex("index1");

            using (var session = store.BeginSession(new SessionConfiguration {
                Readonly = true
            }))
            {
                Assert.Equal(2, index.GetAll("momo").Count());
                Assert.Equal(2, index.GetAll().Count());
            }
        }
예제 #2
0
        public async Task UniqueConstraintIndex()
        {
            await Assert.ThrowsAsync <UniqueConstraintException>(async() =>
            {
                var store  = await StoreBuilder.New().CreateAsync();
                var schema = await store.Schemas.New <TestDomainDefinition>().CreateAsync();
                var domain = await store.DomainModels.New().CreateAsync("Test");
                var graph  = domain.Resolve <IHyperGraph>() as Hyperstore.Modeling.HyperGraph.HyperGraph;
                MemoryIndexManager manager = graph.IndexManager as MemoryIndexManager;
                using (var s = store.BeginSession(new SessionConfiguration {
                    Readonly = true
                }))
                {
                    manager.CreateIndex(schema.Definition.XExtendsBaseClass, "index1", true, "Name");

                    manager.AddToIndex(schema.Definition.XExtendsBaseClass, "index1", new Identity("Test", "1"), "momo");
                    manager.AddToIndex(schema.Definition.XExtendsBaseClass, "index1", new Identity("Test", "2"), "momo");
                }
            });
        }
            ///-------------------------------------------------------------------------------------------------
            /// <summary>
            ///  Executes the given graph.
            /// </summary>
            /// <param name="indexManager">
            ///  The graph.
            /// </param>
            ///-------------------------------------------------------------------------------------------------
            public override void Execute(MemoryIndexManager indexManager)
            {
                DebugContract.Requires(indexManager);

                indexManager.AddToIndex(SchemaElement, IndexName, Id, Key);
            }