Permalink
Browse files

private var fix, wrap rels in seq

  • Loading branch information...
wagjo committed Mar 6, 2011
1 parent 92fe75b commit 146ea48c25b4c7766eae9dd6d4552bf47bc2a327
Showing with 14 additions and 12 deletions.
  1. +1 −0 README.md
  2. +13 −12 src/borneo/core.clj
View
@@ -29,6 +29,7 @@ emphasized):
* _[index](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/index)_ - returns Index Manager * _[index](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/index)_ - returns Index Manager
* _Property Containers (both Nodes and Relationships)_ * _Property Containers (both Nodes and Relationships)_
* _[prop?](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/prop?)_ - returns true if node or relationship contains given property * _[prop?](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/prop?)_ - returns true if node or relationship contains given property
* _[prop](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/prop)_ - returns specific property value for a given node or relationship
* ___[props](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/props)_ - returns map of properties for a given node or relationship__ * ___[props](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/props)_ - returns map of properties for a given node or relationship__
* _[set-prop!](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/set-prop!)_ - sets or removes property in a given node or relationship * _[set-prop!](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/set-prop!)_ - sets or removes property in a given node or relationship
* ___[set-props!](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/set-props!)_ - sets (or removes) properties for a given node or relationships__ * ___[set-props!](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/set-props!)_ - sets (or removes) properties for a given node or relationships__
View
@@ -221,23 +221,24 @@
(= :all e) org.neo4j.graphdb.ReturnableEvaluator/ALL (= :all e) org.neo4j.graphdb.ReturnableEvaluator/ALL
:else (returnable-with-protocol e))) :else (returnable-with-protocol e)))
(defn- start! ;;;; Public API
(defn start!
"Establish a connection to the database. "Establish a connection to the database.
Uses *neo-db* Var to hold the connection." Uses *neo-db* Var to hold the connection.
Do not use this function, use with-db! or with-local-db! instead"
[path] [path]
(io!) (io!)
(let [n (EmbeddedGraphDatabase. path)] (let [n (EmbeddedGraphDatabase. path)]
(alter-var-root #'*neo-db* (fn [_] n)))) (alter-var-root #'*neo-db* (fn [_] n))))
(defn- stop! (defn stop!
"Closes a connection stored in *neo-db*" "Closes a connection stored in *neo-db*.
Do not use this function, use with-db! or with-local-db! instead"
[] []
(io!) (io!)
(.shutdown *neo-db*)) (.shutdown *neo-db*))
;;;; Public API
(defmacro with-db! (defmacro with-db!
"Establish a connection to the neo db. "Establish a connection to the neo db.
Because there is an overhead when establishing connection, users should Because there is an overhead when establishing connection, users should
@@ -247,7 +248,7 @@
`(do `(do
;; Not using binding macro, because db should be accessible ;; Not using binding macro, because db should be accessible
;; from multiple threads. ;; from multiple threads.
(start! path) (start! ~path)
(try (try
~@body ~@body
(finally (stop!))))) (finally (stop!)))))
@@ -475,16 +476,16 @@
(rels node nil :in) ; Rels of any type of :in direction (rels node nil :in) ; Rels of any type of :in direction
(rels node :foo nil) ; Use (rel node :foo) instead" (rels node :foo nil) ; Use (rel node :foo) instead"
([^Node node] ([^Node node]
(.getRelationships node)) (seq (.getRelationships node)))
([^Node node type-or-types] ([^Node node type-or-types]
(let [t (map rel-type* (flatten [type-or-types]))] (let [t (map rel-type* (flatten [type-or-types]))]
;; TODO: Is there a way to type hint array in following call? ;; TODO: Is there a way to type hint array in following call?
(.getRelationships node (into-array RelationshipType t)))) (seq (.getRelationships node (into-array RelationshipType t)))))
([^Node node type direction] ([^Node node type direction]
(cond (cond
(nil? type) (.getRelationships node (rel-dir direction)) (nil? type) (seq (.getRelationships node (rel-dir direction)))
(nil? direction) (rels node type) (nil? direction) (rels node type)
:else (.getRelationships node (rel-type* type) (rel-dir direction))))) :else (seq (.getRelationships node (rel-type* type) (rel-dir direction))))))
(defn single-rel (defn single-rel
"Returns the only relationship for the node of the given type and "Returns the only relationship for the node of the given type and

0 comments on commit 146ea48

Please sign in to comment.