コード例 #1
0
        private IList <IndexEntryUpdate <SchemaDescriptorSupplier> > GenerateSomeUpdates(int count)
        {
            IList <IndexEntryUpdate <SchemaDescriptorSupplier> > updates = new List <IndexEntryUpdate <SchemaDescriptorSupplier> >();

            for (int i = 0; i < count; i++)
            {
                long entityId = Random.nextLong(10_000_000);
                switch (Random.among(UpdateMode.MODES))
                {
                case ADDED:
                    updates.Add(IndexEntryUpdate.add(entityId, _descriptor, Random.nextValue()));
                    break;

                case REMOVED:
                    updates.Add(IndexEntryUpdate.remove(entityId, _descriptor, Random.nextValue()));
                    break;

                case CHANGED:
                    updates.Add(IndexEntryUpdate.change(entityId, _descriptor, Random.nextValue(), Random.nextValue()));
                    break;

                default:
                    throw new System.ArgumentException();
                }
            }
            return(updates);
        }
コード例 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void process(org.neo4j.kernel.api.index.IndexEntryUpdate<?> update) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        public override void Process <T1>(IndexEntryUpdate <T1> update)
        {
            IndexUpdater to = Select(update.Values()[0].valueGroup());

            switch (update.UpdateMode())
            {
            case ADDED:
            case REMOVED:
                to.Process(update);
                break;

            case CHANGED:
                IndexUpdater from = Select(update.BeforeValues()[0].valueGroup());
                // There are two cases:
                // - both before/after go into the same updater --> pass update into that updater
                if (from == to)
                {
                    from.Process(update);
                }
                // - before go into one and after into the other --> REMOVED from one and ADDED into the other
                else
                {
                    from.Process(IndexEntryUpdate.remove(update.EntityId, update.IndexKey(), update.BeforeValues()));
                    to.Process(IndexEntryUpdate.add(update.EntityId, update.IndexKey(), update.Values()));
                }
                break;

            default:
                throw new System.ArgumentException("Unknown update mode");
            }
        }
コード例 #3
0
ファイル: EntityUpdates.cs プロジェクト: Neo4Net/Neo4Net
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("ConstantConditions") private <INDEX_KEY extends org.neo4j.internal.kernel.api.schema.SchemaDescriptorSupplier> Iterable<org.neo4j.kernel.api.index.IndexEntryUpdate<INDEX_KEY>> gatherUpdatesForPotentials(Iterable<INDEX_KEY> potentiallyRelevant)
        private IEnumerable <IndexEntryUpdate <INDEX_KEY> > GatherUpdatesForPotentials <INDEX_KEY>(IEnumerable <INDEX_KEY> potentiallyRelevant) where INDEX_KEY : [email protected]
        {
            IList <IndexEntryUpdate <INDEX_KEY> > indexUpdates = new List <IndexEntryUpdate <INDEX_KEY> >();

            foreach (INDEX_KEY indexKey in potentiallyRelevant)
            {
                SchemaDescriptor schema         = indexKey.schema();
                bool             relevantBefore = relevantBefore(schema);
                bool             relevantAfter  = relevantAfter(schema);
                int[]            propertyIds    = Schema.PropertyIds;
                if (relevantBefore && !relevantAfter)
                {
                    indexUpdates.Add(IndexEntryUpdate.remove(_entityId, indexKey, ValuesBefore(propertyIds)));
                }
                else if (!relevantBefore && relevantAfter)
                {
                    indexUpdates.Add(IndexEntryUpdate.add(_entityId, indexKey, ValuesAfter(propertyIds)));
                }
                else if (relevantBefore && relevantAfter)
                {
                    if (ValuesChanged(propertyIds, Schema.propertySchemaType()))
                    {
                        indexUpdates.Add(IndexEntryUpdate.change(_entityId, indexKey, ValuesBefore(propertyIds), ValuesAfter(propertyIds)));
                    }
                }
            }
            return(indexUpdates);
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldContainFedRelationshipUpdate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldContainFedRelationshipUpdate()
        {
            OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(_nodeStore, _relationshipStore, _indexingService, _propertyPhysicalToLogicalConverter);

            long relId = 0;
            RelationshipRecord inUse    = GetRelationship(relId, true, ENTITY_TOKEN);
            Value propertyValue         = Values.of("hej");
            long  propertyId            = CreateRelationshipProperty(inUse, propertyValue, 1);
            RelationshipRecord notInUse = GetRelationship(relId, false, ENTITY_TOKEN);

            _relationshipStore.updateRecord(inUse);

            Command.RelationshipCommand relationshipCommand = new Command.RelationshipCommand(inUse, notInUse);
            PropertyRecord propertyBlocks = new PropertyRecord(propertyId);

            propertyBlocks.RelId = relId;
            Command.PropertyCommand propertyCommand = new Command.PropertyCommand(_recordAccess.getIfLoaded(propertyId).forReadingData(), propertyBlocks);

            StoreIndexDescriptor indexDescriptor = forSchema(multiToken(_entityTokens, RELATIONSHIP, 1, 4, 6), EMPTY.ProviderDescriptor).withId(0);

            _indexingService.createIndexes(indexDescriptor);
            _indexingService.getIndexProxy(indexDescriptor.Schema()).awaitStoreScanCompleted(0, MILLISECONDS);

            onlineIndexUpdates.Feed(NodeGroup(null), RelationshipGroup(relationshipCommand, propertyCommand));
            assertTrue(onlineIndexUpdates.HasUpdates());
            IEnumerator <IndexEntryUpdate <SchemaDescriptor> > iterator = onlineIndexUpdates.GetEnumerator();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertEquals(iterator.next(), IndexEntryUpdate.remove(relId, indexDescriptor, propertyValue, null, null));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            assertFalse(iterator.hasNext());
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustDiscoverRelationshipInStoreMissingFromIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustDiscoverRelationshipInStoreMissingFromIndex()
        {
            GraphDatabaseService db = CreateDatabase();

            using (Transaction tx = Db.beginTx())
            {
                Db.execute(format(RELATIONSHIP_CREATE, "rels", array("REL"), array("prop"))).close();
                tx.Success();
            }
            StoreIndexDescriptor indexDescriptor;
            long relId;

            using (Transaction tx = Db.beginTx())
            {
                Db.schema().awaitIndexesOnline(1, TimeUnit.MINUTES);
                indexDescriptor = GetIndexDescriptor(first(Db.schema().Indexes));
                Node         node = Db.createNode();
                Relationship rel  = node.CreateRelationshipTo(node, RelationshipType.withName("REL"));
                rel.SetProperty("prop", "value");
                relId = rel.Id;
                tx.Success();
            }
            IndexingService indexes    = GetIndexingService(db);
            IndexProxy      indexProxy = indexes.GetIndexProxy(indexDescriptor.Schema());

            using (IndexUpdater updater = indexProxy.NewUpdater(IndexUpdateMode.ONLINE))
            {
                updater.Process(IndexEntryUpdate.remove(relId, indexDescriptor, Values.stringValue("value")));
            }

            Db.shutdown();

            ConsistencyCheckService.Result result = CheckConsistency();
            assertFalse(result.Successful);
        }
コード例 #6
0
 internal virtual void Add <T1>(IndexEntryUpdate <T1> update)
 {
     if (update.EntityId == 2)
     {
         JobConflict.update(IndexEntryUpdate.remove(NodeToDelete, Index, ValueToDelete));
     }
     Added[update.EntityId] = update.Values()[0].asObjectCopy();
 }
コード例 #7
0
        internal static IndexEntryUpdate <LabelSchemaDescriptor> Remove(params Value[] value)
        {
            switch (value.Length)
            {
            case 1:
                return(IndexEntryUpdate.remove(0, _indexKey, value));

            case 2:
                return(IndexEntryUpdate.remove(0, _compositeIndexKey, value));

            default:
                return(null);
            }
        }
コード例 #8
0
        private static IndexEntryUpdate <SchemaDescriptorSupplier> AsUpdate(IndexUpdateCursor <GenericKey, NativeIndexValue> reader)
        {
            switch (reader.UpdateMode())
            {
            case ADDED:
                return(IndexEntryUpdate.add(reader.Key().EntityId, _descriptor, reader.Key().asValue()));

            case CHANGED:
                return(IndexEntryUpdate.change(reader.Key().EntityId, _descriptor, reader.Key().asValue(), reader.Key2().asValue()));

            case REMOVED:
                return(IndexEntryUpdate.remove(reader.Key().EntityId, _descriptor, reader.Key().asValue()));

            default:
                throw new System.ArgumentException();
            }
        }
コード例 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDifferentiateNodesAndRelationships() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDifferentiateNodesAndRelationships()
        {
            OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(_nodeStore, _relationshipStore, _indexingService, _propertyPhysicalToLogicalConverter);

            int        nodeId            = 0;
            NodeRecord inUseNode         = GetNode(nodeId, true);
            Value      nodePropertyValue = Values.of("hej");
            long       nodePropertyId    = CreateNodeProperty(inUseNode, nodePropertyValue, 1);
            NodeRecord notInUseNode      = GetNode(nodeId, false);

            _nodeStore.updateRecord(inUseNode);

            Command.NodeCommand nodeCommand        = new Command.NodeCommand(inUseNode, notInUseNode);
            PropertyRecord      nodePropertyBlocks = new PropertyRecord(nodePropertyId);

            nodePropertyBlocks.NodeId = nodeId;
            Command.PropertyCommand nodePropertyCommand = new Command.PropertyCommand(_recordAccess.getIfLoaded(nodePropertyId).forReadingData(), nodePropertyBlocks);

            StoreIndexDescriptor nodeIndexDescriptor = forSchema(multiToken(_entityTokens, NODE, 1, 4, 6), EMPTY.ProviderDescriptor).withId(0);

            _indexingService.createIndexes(nodeIndexDescriptor);
            _indexingService.getIndexProxy(nodeIndexDescriptor.Schema()).awaitStoreScanCompleted(0, MILLISECONDS);

            long relId = 0;
            RelationshipRecord inUse        = GetRelationship(relId, true, ENTITY_TOKEN);
            Value relationshipPropertyValue = Values.of("da");
            long  propertyId            = CreateRelationshipProperty(inUse, relationshipPropertyValue, 1);
            RelationshipRecord notInUse = GetRelationship(relId, false, ENTITY_TOKEN);

            _relationshipStore.updateRecord(inUse);

            Command.RelationshipCommand relationshipCommand = new Command.RelationshipCommand(inUse, notInUse);
            PropertyRecord relationshipPropertyBlocks       = new PropertyRecord(propertyId);

            relationshipPropertyBlocks.RelId = relId;
            Command.PropertyCommand relationshipPropertyCommand = new Command.PropertyCommand(_recordAccess.getIfLoaded(propertyId).forReadingData(), relationshipPropertyBlocks);

            StoreIndexDescriptor relationshipIndexDescriptor = forSchema(multiToken(_entityTokens, RELATIONSHIP, 1, 4, 6), EMPTY.ProviderDescriptor).withId(1);

            _indexingService.createIndexes(relationshipIndexDescriptor);
            _indexingService.getIndexProxy(relationshipIndexDescriptor.Schema()).awaitStoreScanCompleted(0, MILLISECONDS);

            onlineIndexUpdates.Feed(NodeGroup(nodeCommand, nodePropertyCommand), RelationshipGroup(relationshipCommand, relationshipPropertyCommand));
            assertTrue(onlineIndexUpdates.HasUpdates());
            assertThat(onlineIndexUpdates, containsInAnyOrder(IndexEntryUpdate.remove(relId, relationshipIndexDescriptor, relationshipPropertyValue, null, null), IndexEntryUpdate.remove(nodeId, nodeIndexDescriptor, nodePropertyValue, null, null)));
        }
コード例 #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpdateCorrectIndexes() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldUpdateCorrectIndexes()
        {
            OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(_nodeStore, _relationshipStore, _indexingService, _propertyPhysicalToLogicalConverter);

            long relId = 0;
            RelationshipRecord inUse    = GetRelationship(relId, true, ENTITY_TOKEN);
            Value propertyValue         = Values.of("hej");
            Value propertyValue2        = Values.of("da");
            long  propertyId            = CreateRelationshipProperty(inUse, propertyValue, 1);
            long  propertyId2           = CreateRelationshipProperty(inUse, propertyValue2, 4);
            RelationshipRecord notInUse = GetRelationship(relId, false, ENTITY_TOKEN);

            _relationshipStore.updateRecord(inUse);

            Command.RelationshipCommand relationshipCommand = new Command.RelationshipCommand(inUse, notInUse);
            PropertyRecord propertyBlocks = new PropertyRecord(propertyId);

            propertyBlocks.RelId = relId;
            Command.PropertyCommand propertyCommand = new Command.PropertyCommand(_recordAccess.getIfLoaded(propertyId).forReadingData(), propertyBlocks);

            PropertyRecord propertyBlocks2 = new PropertyRecord(propertyId2);

            propertyBlocks2.RelId = relId;
            Command.PropertyCommand propertyCommand2 = new Command.PropertyCommand(_recordAccess.getIfLoaded(propertyId2).forReadingData(), propertyBlocks2);

            StoreIndexDescriptor indexDescriptor0 = forSchema(multiToken(_entityTokens, RELATIONSHIP, 1, 4, 6), EMPTY.ProviderDescriptor).withId(0);
            StoreIndexDescriptor indexDescriptor1 = forSchema(multiToken(_entityTokens, RELATIONSHIP, 2, 4, 6), EMPTY.ProviderDescriptor).withId(1);
            StoreIndexDescriptor indexDescriptor2 = forSchema(multiToken(new int[] { ENTITY_TOKEN, OTHER_ENTITY_TOKEN }, RELATIONSHIP, 1), EMPTY.ProviderDescriptor).withId(2);
            StoreIndexDescriptor indexDescriptor3 = forSchema(multiToken(new int[] { OTHER_ENTITY_TOKEN }, RELATIONSHIP, 1), EMPTY.ProviderDescriptor).withId(3);

            _indexingService.createIndexes(indexDescriptor0, indexDescriptor1, indexDescriptor2);
            _indexingService.getIndexProxy(indexDescriptor0.Schema()).awaitStoreScanCompleted(0, MILLISECONDS);
            _indexingService.getIndexProxy(indexDescriptor1.Schema()).awaitStoreScanCompleted(0, MILLISECONDS);
            _indexingService.getIndexProxy(indexDescriptor2.Schema()).awaitStoreScanCompleted(0, MILLISECONDS);

            onlineIndexUpdates.Feed(NodeGroup(null), RelationshipGroup(relationshipCommand, propertyCommand, propertyCommand2));
            assertTrue(onlineIndexUpdates.HasUpdates());
            assertThat(onlineIndexUpdates, containsInAnyOrder(IndexEntryUpdate.remove(relId, indexDescriptor0, propertyValue, propertyValue2, null), IndexEntryUpdate.remove(relId, indexDescriptor1, null, propertyValue2, null), IndexEntryUpdate.remove(relId, indexDescriptor2, propertyValue)));
            assertThat(onlineIndexUpdates, not(containsInAnyOrder(indexDescriptor3)));                     // This index is only for a different relationship type.
        }
コード例 #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void process(org.neo4j.kernel.api.index.IndexEntryUpdate<?> update) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        public override void Process <T1>(IndexEntryUpdate <T1> update)
        {
            PointValue value = ( PointValue )update.Values()[0];

            switch (update.UpdateMode())
            {
            case ADDED:
                Select(value.CoordinateReferenceSystem).process(update);
                break;

            case CHANGED:
                // These are both spatial, but could belong in different parts
                PointValue   fromValue = ( PointValue )update.BeforeValues()[0];
                IndexUpdater from      = Select(fromValue.CoordinateReferenceSystem);
                IndexUpdater to        = Select(value.CoordinateReferenceSystem);
                // There are two cases:
                // - both before/after go into the same updater --> pass update into that updater
                if (from == to)
                {
                    from.Process(update);
                }
                // - before go into one and after into the other --> REMOVED from one and ADDED into the other
                else
                {
                    from.Process(IndexEntryUpdate.remove(update.EntityId, update.IndexKey(), update.BeforeValues()));
                    to.Process(IndexEntryUpdate.add(update.EntityId, update.IndexKey(), update.Values()));
                }
                break;

            case REMOVED:
                Select(value.CoordinateReferenceSystem).process(update);
                break;

            default:
                throw new System.ArgumentException("Unknown update mode");
            }
        }
コード例 #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void process(org.neo4j.kernel.api.index.IndexEntryUpdate<?> update) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException
        public override void Process <T1>(IndexEntryUpdate <T1> update)
        {
            switch (update.UpdateMode())
            {
            case ADDED:
                InstanceSelector.select(SlotSelector.selectSlot(update.Values(), GroupOf)).process(update);
                break;

            case CHANGED:
                // Hmm, here's a little conundrum. What if we change from a value that goes into native
                // to a value that goes into fallback, or vice versa? We also don't want to blindly pass
                // all CHANGED updates to both updaters since not all values will work in them.
                IndexUpdater from = InstanceSelector.select(SlotSelector.selectSlot(update.BeforeValues(), GroupOf));
                IndexUpdater to   = InstanceSelector.select(SlotSelector.selectSlot(update.Values(), GroupOf));
                // There are two cases:
                // - both before/after go into the same updater --> pass update into that updater
                if (from == to)
                {
                    from.Process(update);
                }
                // - before go into one and after into the other --> REMOVED from one and ADDED into the other
                else
                {
                    from.Process(IndexEntryUpdate.remove(update.EntityId, update.IndexKey(), update.BeforeValues()));
                    to.Process(IndexEntryUpdate.add(update.EntityId, update.IndexKey(), update.Values()));
                }
                break;

            case REMOVED:
                InstanceSelector.select(SlotSelector.selectSlot(update.Values(), GroupOf)).process(update);
                break;

            default:
                throw new System.ArgumentException("Unknown update mode");
            }
        }