Hi, Tobias.  I was only referring to the case when it was the intent to
delete the node also.  In that case, you *have* to delete all the
relationships to the node in order to delete the node.  No worries, it is
easy enough to implement!


-----Original Message-----
From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On
Behalf Of Tobias Ivarsson
Sent: Sunday, April 25, 2010 5:53 PM
To: Neo user discussions
Subject: Re: [Neo] Checking if relationship exists between two nodes

On Sun, Apr 25, 2010 at 10:42 PM, Mattias Persson <matt...@neotechnology.com
> wrote:

> 2010/4/25, Rick Bullotta <rick.bullo...@burningskysoftware.com>:
> > Cool, Mattias.  I just ran into that requirement again today.
> >
> > This is also another good case for the cached/persisted "number of
> > relationships" counter on a node that has also been discussed. It would
> > enable the optimization to occur automatically.
> Although for this method it doesn't matter, sort of, because it'll
> iterate from both nodes in parallell (unless it immediately finds it
> from the first direction, within the first 50 or so)
> >
> > Another API function that would be useful (though it is also easy to
> > implement) is one that automatically deletes all relationships for a
> node,
> > then deletes the node, since that is the required path of action anyway
> to
> > delete a node.
> >
> well, yeah maybe. I don't think I've ever wanted to do that so I
> haven't created a utility method for it. But it may be time to add it
>

I think just removing all relationships of a node is a bit unsafe. I would
prefer if you had to supply the RelationshipTypes to delete, so that you
don't destroy unexpected structures.

SomeUtilityClass.delete( Node node, RelationshipType... expectedTypes )

>
> >
> > -----Original Message-----
> > From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org]
> On
> > Behalf Of Mattias Persson
> > Sent: Sunday, April 25, 2010 3:52 PM
> > To: Neo4j user discussions
> > Subject: [Neo] Checking if relationship exists between two nodes
> >
> > As you all (probably) know the Neo4j API has no method
> > Node#hasRelationshipTo(Node otherNode) and to find out such a thing
could
> > potentially be slow if both the nodes has many relationships (of the
> > type/direction you want to check).
> >
> > I just created a utility for that which starts to iterate from the node
> (of
> > the two) that the developer thinks/knows has the least relationships. If
> a
> > certain amount of relationships have been iterated and not yet found a
> new
> > thread is spawned which starts to iterate from the other node in the
> > opposite direction. The method will return as soon as the first thread
> finds
> > a match. I'd guess that's the fastest way currently to do that. The next
> > level of this would be to add indexing for relationships (which is an
> > upcoming feature) and go via that instead.
> >
> > So the code may look like:
> >
> > (it's in the neo4j-utils component)
> >
> >   GraphDatabaseUtil graphDbUtil = new GraphDatabaseUtil( graphDb );
> >   boolean exists = graphDbUtil.relationshipExistsBetween( node1, node2,
> >       MyRelTypes.MY_TYPE, Direction.OUTGOING );
> >
> > --
> > Mattias Persson, [matt...@neotechnology.com]
> > Hacker, Neo Technology
> > www.neotechnology.com
> > _______________________________________________
> > Neo mailing list
> > User@lists.neo4j.org
> > https://lists.neo4j.org/mailman/listinfo/user
> >
> > _______________________________________________
> > Neo mailing list
> > User@lists.neo4j.org
> > https://lists.neo4j.org/mailman/listinfo/user
> >
>
>
> --
> Mattias Persson, [matt...@neotechnology.com]
> Hacker, Neo Technology
> www.neotechnology.com
> _______________________________________________
> Neo mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user
>



-- 
Tobias Ivarsson <tobias.ivars...@neotechnology.com>
Hacker, Neo Technology
www.neotechnology.com
Cellphone: +46 706 534857
_______________________________________________
Neo mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

_______________________________________________
Neo mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to