Permalink
Browse files

Handle NotFoundException and return nil from (node|rel)-by-id.

  • Loading branch information...
1 parent a272195 commit 9ae644d4bfb45c40310826ff5536fd2da9c3ffcc Bobby Calderwood committed with wagjo Mar 11, 2011
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/borneo/core.clj
View
13 src/borneo/core.clj
@@ -35,6 +35,7 @@
- NullPointerException is thrown if there is no open connection to the db."
(:import (org.neo4j.graphdb Direction
Node
+ NotFoundException
PropertyContainer
Relationship
RelationshipType
@@ -594,16 +595,20 @@
(lazy-seq (.getAllNodes *neo-db*)))
(defn node-by-id
- "Returns node with a given id.
+ "Returns node with a given id, or nil if no such node exists.
Note that ids are not very good as unique identifiers."
[id]
- (.getNodeById *neo-db* id))
+ (try
+ (.getNodeById *neo-db* id)
+ (catch NotFoundException e nil)))
(defn rel-by-id
- "Returns relationship with a given id.
+ "Returns relationship with a given id, or nil if no such relationship exists.
Note that ids are not very good as unique identifiers."
[id]
- (.getRelationshipById *neo-db* id))
+ (try
+ (.getRelationshipById *neo-db* id)
+ (catch NotFoundException e nil)))
(defn root
"Returns reference/root node."

0 comments on commit 9ae644d

Please sign in to comment.