//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public <E extends Exception> void writeTo(org.neo4j.values.AnyValueWriter<E> writer) throws E
        public override void WriteTo <E>(AnyValueWriter <E> writer) where E : Exception
        {
            if (_relationship is RelationshipProxy)
            {
                RelationshipProxy proxy = ( RelationshipProxy )_relationship;
                if (!proxy.InitializeData())
                {
                    // If the relationship has been deleted since it was found by the query, then we'll have to tell the client that their transaction conflicted,
                    // and that they need to retry it.
                    throw new ReadAndDeleteTransactionConflictException(RelationshipProxy.isDeletedInCurrentTransaction(_relationship));
                }
            }

            MapValue p;

            try
            {
                p = Properties();
            }
            catch (NotFoundException)
            {
                p = VirtualValues.EMPTY_MAP;
            }
            catch (System.InvalidOperationException e)
            {
                throw new ReadAndDeleteTransactionConflictException(RelationshipProxy.isDeletedInCurrentTransaction(_relationship), e);
            }

            if (Id() < 0)
            {
                writer.WriteVirtualRelationshipHack(_relationship);
            }

            writer.WriteRelationship(Id(), StartNode().id(), EndNode().id(), Type(), p);
        }
        /// <summary>
        /// Builds out the nodes and descriptors on the client side. Adds to a _cachedNodes list and keeps it updated.
        /// </summary>
        /// <param name="relatedNodesResult"></param>
        /// <returns></returns>
        private List <INodeProxy> BuildNodeList(RelatedNodesSearchResult relatedNodesResult)
        {
            List <INodeProxy> nodes = new List <INodeProxy>();

            if (relatedNodesResult.Nodes.Count > 0)
            {
                foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values)
                {
                    if (_cachedNodes.ContainsKey(soapNode.Id))
                    {
                        _cachedNodes.Remove(soapNode.Id);
                    }
                    NodeProxy node = new NodeProxy(soapNode);
                    _cachedNodes.Add(soapNode.Id, node);
                }

                foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values)
                {
                    foreach (SoapRelationship relationship in soapNode.Relationships.Values)
                    {
                        RelationshipProxy relationshipProxy = new RelationshipProxy(relationship);

                        foreach (DescriptorProxy descriptor in relationshipProxy.Descriptors)
                        {
                            if (_cachedNodes.ContainsKey(descriptor.NodeId))
                            {
                                INodeProxy connectedNode = _cachedNodes[descriptor.NodeId];
                                descriptor.Node = connectedNode;
                                if (!connectedNode.Descriptors.Contains(descriptor))
                                {
                                    connectedNode.Descriptors.Add(descriptor);
                                }
                            }
                        }
                    }
                }

                foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values)
                {
                    nodes.Add(_cachedNodes[soapNode.Id]);
                }

                foreach (INodeProxy nodeProxy in nodes)
                {
                    foreach (IDescriptorProxy descriptorProxy in nodeProxy.Descriptors)
                    {
                        CompleteRelationship(descriptorProxy.Relationship);
                    }
                }
            }

            return(nodes);
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            EmbeddedProxySPI manager = mock(typeof(EmbeddedProxySPI));

            when(manager.NewNodeProxy(anyLong())).thenAnswer(invocationOnMock =>
            {
                long id        = invocationOnMock.getArgument(0);
                NodeProxy mock = mock(typeof(NodeProxy));
                when(mock.Id).thenReturn(id);
                return(mock);
            });
            when(manager.NewRelationshipProxy(anyLong())).thenAnswer(invocationOnMock =>
            {
                long id = invocationOnMock.getArgument(0);
                RelationshipProxy mock = mock(typeof(RelationshipProxy));
                when(mock.Id).thenReturn(id);
                return(mock);
            });
            _converter = new ParameterConverter(manager);
        }
        private Relationship Relationship(long relId)
        {
            RelationshipProxy relationship = _proxySpi.newRelationshipProxy(relId);

            if (!_state.relationshipVisit(relId, relationship))
            {               // This relationship has been created or changed in this transaction
                RelationshipProxy cached = _relationshipsReadFromStore.get(relId);
                if (cached != null)
                {
                    return(cached);
                }

                try
                {                         // Get this relationship data from the store
                    _store.relationshipVisit(relId, relationship);
                    _relationshipsReadFromStore.put(relId, relationship);
                }
                catch (EntityNotFoundException e)
                {
                    throw new System.InvalidOperationException("Getting deleted relationship data should have been covered by the tx state", e);
                }
            }
            return(relationship);
        }
        /// <summary>
        /// Builds out the nodes and descriptors on the client side. Adds to a _cachedNodes list and keeps it updated.
        /// </summary>
        /// <param name="relatedNodesResult"></param>
        /// <returns></returns>
        private List<INodeProxy> BuildNodeList(RelatedNodesSearchResult relatedNodesResult)
        {
            List<INodeProxy> nodes = new List<INodeProxy>();

            if (relatedNodesResult.Nodes.Count > 0)
            {
                foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values)
                {
                    if (_cachedNodes.ContainsKey(soapNode.Id))
                    {
                        _cachedNodes.Remove(soapNode.Id);
                    }
                    NodeProxy node = new NodeProxy(soapNode);
                    _cachedNodes.Add(soapNode.Id, node);
                }

                foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values)
                {
                    foreach (SoapRelationship relationship in soapNode.Relationships.Values)
                    {
                        RelationshipProxy relationshipProxy = new RelationshipProxy(relationship);

                        foreach (DescriptorProxy descriptor in relationshipProxy.Descriptors)
                        {
                            if (_cachedNodes.ContainsKey(descriptor.NodeId))
                            {
                                INodeProxy connectedNode = _cachedNodes[descriptor.NodeId];
                                descriptor.Node = connectedNode;
                                if (!connectedNode.Descriptors.Contains(descriptor))
                                {
                                    connectedNode.Descriptors.Add(descriptor);
                                }
                            }
                        }
                    }
                }

                foreach (SoapNode soapNode in relatedNodesResult.Nodes.Values)
                {
                    nodes.Add(_cachedNodes[soapNode.Id]);
                }

                foreach (INodeProxy nodeProxy in nodes)
                {
                    foreach (IDescriptorProxy descriptorProxy in nodeProxy.Descriptors)
                    {
                        CompleteRelationship(descriptorProxy.Relationship);
                    }
                }
            }

            return nodes;
        }
        private void GetRelatedNodesByIdAsyncCompleted(object sender, GetRelatedNodesCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                List<INodeProxy> nodes = new List<INodeProxy>();
                
                foreach (SoapNode soapNode in e.Result.RelatedNodes.Values)
                {
                    if (!_cachedNodes.ContainsKey(soapNode.Id))
                    {
                        NodeProxy node = new NodeProxy(soapNode);
                        _cachedNodes.Add(soapNode.Id, node);
                    }
                }

                foreach (SoapNode soapNode in e.Result.RelatedNodes.Values)
                {
                    INodeProxy node = _cachedNodes[soapNode.Id];

                    foreach (SoapRelationship relationship in soapNode.Relationships)
                    {
                        RelationshipProxy relationshipProxy = new RelationshipProxy(relationship);

                        foreach (DescriptorProxy descriptor in relationshipProxy.Descriptors)
                        {
                            if (_cachedNodes.ContainsKey(descriptor.NodeId))
                            {
                                INodeProxy connectedNode = _cachedNodes[descriptor.NodeId];

                                if (!connectedNode.Descriptors.Contains(descriptor))
                                {
                                    descriptor.Node = connectedNode;

                                    connectedNode.Descriptors.Add(descriptor);
                                }
                            }
                        }
                    }
                }

                INodeProxy nodeProxy = _cachedNodes[e.Result.SearchedNode.Id];
                nodes.Add(nodeProxy);

                foreach (INodeProxy np in _localNewNodes.Values)
                {
                    nodes.Add(np);
                }

                foreach (IDescriptorProxy descriptor in nodeProxy.Descriptors)
                {
                    foreach (IDescriptorProxy alternateDescriptor in descriptor.Relationship.Descriptors)
                    {
                        if (!nodes.Contains(alternateDescriptor.Node))
                        {
                            nodes.Add(alternateDescriptor.Node);
                        }
                    }
                }

                INodeProxy searchedNode = new NodeProxy(e.Result.SearchedNode);

                ReturnedNodesEventArgs eventArgs = new ReturnedNodesEventArgs(searchedNode, nodes.ToArray());

                if (GetRelatedNodesByIdCompleted != null)
                {
                    GetRelatedNodesByIdCompleted.Invoke(this, eventArgs);
                }
            }
        }
Example #7
0
        private void GetRelatedNodesByIdAsyncCompleted(object sender, GetRelatedNodesCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                List <INodeProxy> nodes = new List <INodeProxy>();

                foreach (SoapNode soapNode in e.Result.RelatedNodes.Values)
                {
                    if (!_cachedNodes.ContainsKey(soapNode.Id))
                    {
                        NodeProxy node = new NodeProxy(soapNode);
                        _cachedNodes.Add(soapNode.Id, node);
                    }
                }

                foreach (SoapNode soapNode in e.Result.RelatedNodes.Values)
                {
                    INodeProxy node = _cachedNodes[soapNode.Id];

                    foreach (SoapRelationship relationship in soapNode.Relationships)
                    {
                        RelationshipProxy relationshipProxy = new RelationshipProxy(relationship);

                        foreach (DescriptorProxy descriptor in relationshipProxy.Descriptors)
                        {
                            if (_cachedNodes.ContainsKey(descriptor.NodeId))
                            {
                                INodeProxy connectedNode = _cachedNodes[descriptor.NodeId];

                                if (!connectedNode.Descriptors.Contains(descriptor))
                                {
                                    descriptor.Node = connectedNode;

                                    connectedNode.Descriptors.Add(descriptor);
                                }
                            }
                        }
                    }
                }

                INodeProxy nodeProxy = _cachedNodes[e.Result.SearchedNode.Id];
                nodes.Add(nodeProxy);

                foreach (INodeProxy np in _localNewNodes.Values)
                {
                    nodes.Add(np);
                }

                foreach (IDescriptorProxy descriptor in nodeProxy.Descriptors)
                {
                    foreach (IDescriptorProxy alternateDescriptor in descriptor.Relationship.Descriptors)
                    {
                        if (!nodes.Contains(alternateDescriptor.Node))
                        {
                            nodes.Add(alternateDescriptor.Node);
                        }
                    }
                }

                INodeProxy searchedNode = new NodeProxy(e.Result.SearchedNode);

                ReturnedNodesEventArgs eventArgs = new ReturnedNodesEventArgs(searchedNode, nodes.ToArray());

                if (GetRelatedNodesByIdCompleted != null)
                {
                    GetRelatedNodesByIdCompleted.Invoke(this, eventArgs);
                }
            }
        }