Check if item exists in index

85 views
Skip to first unread message

Samwillie

unread,
May 11, 2012, 6:26:50 AM5/11/12
to Neo4j
Hi,

Is there a way to check if for example an id exists in index - just to
avoid a null pointer exception like in the statement below?

IndexHits<Node> nodeHits = index.get("id", nodeId);
//The above statement throws a null pointer exception if the nodeId
doesn't exist in index.
Node node = nodeHits.getSingle();
nodeHits.close();

Thanks,

Samwillie

unread,
May 11, 2012, 7:37:36 AM5/11/12
to Neo4j
Hi,

Sorry for the post, found the "index.existsForNodes()" method using
which we can avoid a null pointer exception.

Thanks again,

Peter Neubauer

unread,
May 11, 2012, 7:38:15 AM5/11/12
to ne...@googlegroups.com
Ok,
was just on my way to answer :)

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

If you can write, you can code - @coderdojomalmo
If you can sketch, you can use a graph database - @neo4j

Samwillie

unread,
May 11, 2012, 8:32:17 AM5/11/12
to Neo4j
Thanks Peter!

On May 11, 1:38 pm, Peter Neubauer <peter.neuba...@neotechnology.com>
wrote:
Reply all
Reply to author
Forward
0 new messages