Skip to content

Commit

Permalink
private var fix, wrap rels in seq
Browse files Browse the repository at this point in the history
  • Loading branch information
wagjo committed Mar 6, 2011
1 parent 92fe75b commit 146ea48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ emphasized):
* _[index](http://wagjo.github.com/borneo/borneo.core-api.html#borneo.core/index)_ - returns Index Manager
* _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 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__
* _[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__
Expand Down
25 changes: 13 additions & 12 deletions src/borneo/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,24 @@
(= :all e) org.neo4j.graphdb.ReturnableEvaluator/ALL
:else (returnable-with-protocol e)))

(defn- start!
;;;; Public API

(defn start!
"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]
(io!)
(let [n (EmbeddedGraphDatabase. path)]
(alter-var-root #'*neo-db* (fn [_] n))))

(defn- stop!
"Closes a connection stored in *neo-db*"
(defn stop!
"Closes a connection stored in *neo-db*.
Do not use this function, use with-db! or with-local-db! instead"
[]
(io!)
(.shutdown *neo-db*))


;;;; Public API

(defmacro with-db!
"Establish a connection to the neo db.
Because there is an overhead when establishing connection, users should
Expand All @@ -247,7 +248,7 @@
`(do
;; Not using binding macro, because db should be accessible
;; from multiple threads.
(start! path)
(start! ~path)
(try
~@body
(finally (stop!)))))
Expand Down Expand Up @@ -475,16 +476,16 @@
(rels node nil :in) ; Rels of any type of :in direction
(rels node :foo nil) ; Use (rel node :foo) instead"
([^Node node]
(.getRelationships node))
(seq (.getRelationships node)))
([^Node node type-or-types]
(let [t (map rel-type* (flatten [type-or-types]))]
;; 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]
(cond
(nil? type) (.getRelationships node (rel-dir direction))
(nil? type) (seq (.getRelationships node (rel-dir direction)))
(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
"Returns the only relationship for the node of the given type and
Expand Down

0 comments on commit 146ea48

Please sign in to comment.