示例#1
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: private org.neo4j.graphdb.schema.IndexDefinition descriptorToDefinition(final org.neo4j.internal.kernel.api.TokenRead tokenRead, org.neo4j.internal.kernel.api.IndexReference index)
        private IndexDefinition DescriptorToDefinition(TokenRead tokenRead, IndexReference index)
        {
            try
            {
                SchemaDescriptor schema          = index.Schema();
                int[]            entityTokenIds  = Schema.EntityTokenIds;
                bool             constraintIndex = index.Unique;
                string[]         propertyNames   = PropertyNameUtils.GetPropertyKeys(tokenRead, index.Properties());
                switch (Schema.entityType())
                {
                case NODE:
                    Label[] labels = new Label[entityTokenIds.Length];
                    for (int i = 0; i < labels.Length; i++)
                    {
                        labels[i] = label(tokenRead.NodeLabelName(entityTokenIds[i]));
                    }
                    return(new IndexDefinitionImpl(_actions, index, labels, propertyNames, constraintIndex));

                case RELATIONSHIP:
                    RelationshipType[] relTypes = new RelationshipType[entityTokenIds.Length];
                    for (int i = 0; i < relTypes.Length; i++)
                    {
                        relTypes[i] = withName(tokenRead.RelationshipTypeName(entityTokenIds[i]));
                    }
                    return(new IndexDefinitionImpl(_actions, index, relTypes, propertyNames, constraintIndex));

                default:
                    throw new System.ArgumentException("Cannot create IndexDefinition for " + Schema.entityType() + " entity-typed schema.");
                }
            }
            catch (KernelException e)
            {
                throw new Exception(e);
            }
        }
        private void TakeSnapshot()
        {
            try
            {
                using (StorageNodeCursor node = _store.allocateNodeCursor(), StoragePropertyCursor properties = _store.allocatePropertyCursor(), StorageRelationshipScanCursor relationship = _store.allocateRelationshipScanCursor())
                {
                    TokenRead tokenRead = _transaction.tokenRead();
                    _state.addedAndRemovedNodes().Removed.each(nodeId =>
                    {
                        node.Single(nodeId);
                        if (node.Next())
                        {
                            properties.Init(node.PropertiesReference());
                            while (properties.Next())
                            {
                                try
                                {
                                    _removedNodeProperties.Add(new NodePropertyEntryView(this, nodeId, tokenRead.PropertyKeyName(properties.PropertyKey()), null, properties.PropertyValue()));
                                }
                                catch (PropertyKeyIdNotFoundKernelException e)
                                {
                                    throw new System.InvalidOperationException("Nonexisting properties was modified for node " + nodeId, e);
                                }
                            }

                            foreach (long labelId in node.Labels())
                            {
                                try
                                {
                                    _removedLabels.Add(new LabelEntryView(this, nodeId, tokenRead.NodeLabelName(toIntExact(labelId))));
                                }
                                catch (LabelNotFoundKernelException e)
                                {
                                    throw new System.InvalidOperationException("Nonexisting label was modified for node " + nodeId, e);
                                }
                            }
                        }
                    });
                    _state.addedAndRemovedRelationships().Removed.each(relId =>
                    {
                        Relationship relationshipProxy = relationship(relId);
                        relationship.Single(relId);
                        if (relationship.Next())
                        {
                            properties.Init(relationship.PropertiesReference());
                            while (properties.Next())
                            {
                                try
                                {
                                    _removedRelationshipProperties.Add(new RelationshipPropertyEntryView(relationshipProxy, tokenRead.PropertyKeyName(properties.PropertyKey()), null, properties.PropertyValue()));
                                }
                                catch (PropertyKeyIdNotFoundKernelException e)
                                {
                                    throw new System.InvalidOperationException("Nonexisting node properties was modified for relationship " + relId, e);
                                }
                            }
                        }
                    });
                    foreach (NodeState nodeState in _state.modifiedNodes())
                    {
                        IEnumerator <StorageProperty> added = nodeState.AddedAndChangedProperties();
                        long nodeId = nodeState.Id;
                        while (added.MoveNext())
                        {
                            StorageProperty property = added.Current;
                            _assignedNodeProperties.Add(new NodePropertyEntryView(this, nodeId, tokenRead.PropertyKeyName(property.PropertyKeyId()), property.Value(), CommittedValue(nodeState, property.PropertyKeyId(), node, properties)));
                        }
                        nodeState.RemovedProperties().each(id =>
                        {
                            try
                            {
                                NodePropertyEntryView entryView = new NodePropertyEntryView(this, nodeId, tokenRead.PropertyKeyName(id), null, CommittedValue(nodeState, id, node, properties));
                                _removedNodeProperties.Add(entryView);
                            }
                            catch (PropertyKeyIdNotFoundKernelException e)
                            {
                                throw new System.InvalidOperationException("Nonexisting node properties was modified for node " + nodeId, e);
                            }
                        });

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.storageengine.api.txstate.LongDiffSets labels = nodeState.labelDiffSets();
                        LongDiffSets labels = nodeState.LabelDiffSets();
                        AddLabelEntriesTo(nodeId, labels.Added, _assignedLabels);
                        AddLabelEntriesTo(nodeId, labels.Removed, _removedLabels);
                    }
                    foreach (RelationshipState relState in _state.modifiedRelationships())
                    {
                        Relationship relationshipProxy      = relationship(relState.Id);
                        IEnumerator <StorageProperty> added = relState.AddedAndChangedProperties();
                        while (added.MoveNext())
                        {
                            StorageProperty property = added.Current;
                            _assignedRelationshipProperties.Add(new RelationshipPropertyEntryView(relationshipProxy, tokenRead.PropertyKeyName(property.PropertyKeyId()), property.Value(), CommittedValue(relState, property.PropertyKeyId(), relationship, properties)));
                        }
                        relState.RemovedProperties().each(id =>
                        {
                            try
                            {
                                RelationshipPropertyEntryView entryView = new RelationshipPropertyEntryView(relationshipProxy, tokenRead.PropertyKeyName(id), null, CommittedValue(relState, id, relationship, properties));
                                _removedRelationshipProperties.Add(entryView);
                            }
                            catch (PropertyKeyIdNotFoundKernelException e)
                            {
                                throw new System.InvalidOperationException("Nonexisting properties was modified for relationship " + relState.Id, e);
                            }
                        });
                    }
                }
            }
            catch (PropertyKeyIdNotFoundKernelException e)
            {
                throw new System.InvalidOperationException("An entity that does not exist was modified.", e);
            }
        }