/// <summary>
        /// A label has been changed, figure out what updates are needed to tx state.
        /// </summary>
        /// <param name="labelId"> The id of the changed label </param>
        /// <param name="existingPropertyKeyIds"> all property key ids the node has, sorted by id </param>
        /// <param name="node"> cursor to the node where the change was applied </param>
        /// <param name="propertyCursor"> cursor to the properties of node </param>
        /// <param name="changeType"> The type of change event </param>
        internal virtual void OnLabelChange(int labelId, int[] existingPropertyKeyIds, NodeCursor node, PropertyCursor propertyCursor, LabelChangeType changeType)
        {
            Debug.Assert(NoSchemaChangedInTx());

            // Check all indexes of the changed label
            ICollection <SchemaDescriptor> indexes = _indexingService.getRelatedIndexes(new long[] { labelId }, existingPropertyKeyIds, NODE);

            if (indexes.Count > 0)
            {
                MutableIntObjectMap <Value> materializedProperties = IntObjectMaps.mutable.empty();
                foreach (SchemaDescriptor index in indexes)
                {
                    int[]   indexPropertyIds = index.Schema().PropertyIds;
                    Value[] values           = GetValueTuple(node, propertyCursor, NO_SUCH_PROPERTY_KEY, NO_VALUE, indexPropertyIds, materializedProperties);
                    switch (changeType)
                    {
                    case Org.Neo4j.Kernel.Impl.Newapi.IndexTxStateUpdater.LabelChangeType.AddedLabel:
                        _indexingService.validateBeforeCommit(index.Schema(), values);
                        _read.txState().indexDoUpdateEntry(index.Schema(), node.NodeReference(), null, ValueTuple.of(values));
                        break;

                    case Org.Neo4j.Kernel.Impl.Newapi.IndexTxStateUpdater.LabelChangeType.RemovedLabel:
                        _read.txState().indexDoUpdateEntry(index.Schema(), node.NodeReference(), ValueTuple.of(values), null);
                        break;

                    default:
                        throw new System.InvalidOperationException(changeType + " is not a supported event");
                    }
                }
            }
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup() throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void Setup()
        {
            _txState = mock(typeof(TransactionState));

            Dictionary <int, Value> map = new Dictionary <int, Value>();

            map[PROP_ID1] = Values.of("hi1");
            map[PROP_ID2] = Values.of("hi2");
            map[PROP_ID3] = Values.of("hi3");
            _node         = (new StubNodeCursor()).withNode(0, new long[] { LABEL_ID1, LABEL_ID2 }, map);
            _node.next();

            _propertyCursor = new StubPropertyCursor();

            Read readOps = mock(typeof(Read));

            when(readOps.TxState()).thenReturn(_txState);

            IndexingService indexingService = mock(typeof(IndexingService));
            IndexProxy      indexProxy      = mock(typeof(IndexProxy));

            when(indexingService.getIndexProxy(any(typeof(SchemaDescriptor)))).thenReturn(indexProxy);
            when(indexingService.getRelatedIndexes(any(), anyInt(), any())).thenAnswer(invocationOnMock =>
            {
                long[] labels     = invocationOnMock.getArgument(0);
                int propertyKeyId = invocationOnMock.getArgument(1);
                ISet <SchemaDescriptor> descriptors = new HashSet <SchemaDescriptor>();
                foreach (IndexDescriptor index in _indexes)
                {
                    if (contains(labels, index.schema().keyId()) && contains(index.schema().PropertyIds, propertyKeyId))
                    {
                        descriptors.add(index.schema());
                    }
                }
                return(descriptors);
            });
            when(indexingService.getRelatedIndexes(any(), any(typeof(int[])), any())).thenAnswer(invocationOnMock =>
            {
                long[] labels        = invocationOnMock.getArgument(0);
                int[] propertyKeyIds = invocationOnMock.getArgument(1);
                ISet <SchemaDescriptor> descriptors = new HashSet <SchemaDescriptor>();
                foreach (IndexDescriptor index in _indexes)
                {
                    if (contains(labels, index.schema().keyId()))
                    {
                        bool containsAll = true;
                        foreach (int propertyId in index.schema().PropertyIds)
                        {
                            containsAll &= contains(propertyKeyIds, propertyId);
                        }
                        if (containsAll)
                        {
                            descriptors.add(index.schema());
                        }
                    }
                }
                return(descriptors);
            });

            _indexTxUpdater = new IndexTxStateUpdater(readOps, indexingService);
        }