-
Notifications
You must be signed in to change notification settings - Fork 29
/
peer.clj
56 lines (49 loc) · 1.7 KB
/
peer.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(ns ^{:doc "Main entry point for Java."}
asami.peer
(:gen-class
:name asami.Peer
:methods [#^{:static true} [connect [String] Object]
#^{:static true} [createDatabase [String] boolean]
#^{:static true} [deleteDatabase [String] boolean]
#^{:static true} [getDatabaseNames [] java.util.List]
#^{:static true} [q [Object] Object]
#^{:static true} [tempid [Object] Object]
#^{:static true} [tempid [Object long] Object]
#^{:static true} [tempid [] Object]])
(:require [asami.core :as core]
[asami.graph :as graph]
[asami.storage :as storage]
[zuko.node :refer [new-node]]
[asami.storage :as storage]))
(defn -connect
"Connects to a database described in the uri"
[^String uri]
(core/connect uri))
(defn -createDatabase
"Creates a database described in the uri"
^Boolean [^String uri]
(core/create-database uri))
(defn -deleteDatabase
"Removes a database of the given uri"
^Boolean [^String uri]
(core/delete-database uri))
(defn -getDatabaseNames
"Retrieves the names of the known databases"
^java.util.List []
(core/get-database-names))
(defn -q
"Executes a query against inputs"
[query inputs]
(apply core/q query inputs))
(defonce ids (atom {}))
(defn -tempid
"Generates a temporary internal ID"
([] (graph/new-node))
([connection] (new-node (storage/graph (storage/db connection))))
([connection id]
(let [id-for (fn [m i]
(if (contains? m i)
m
(assoc m i (-tempid connection))))
ident (str (storage/get-name connection) id)]
(get (swap! ids id-for ident) ident))))