-
Notifications
You must be signed in to change notification settings - Fork 4
/
spec_query.clj
79 lines (68 loc) · 2.9 KB
/
spec_query.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(ns clj-jargon.spec-query
(:import [org.irods.jargon.core.exception DataNotFoundException JargonException]
[org.irods.jargon.core.pub IRODSAccessObjectFactory
SpecificQueryAO]
[org.irods.jargon.core.pub.domain SpecificQueryDefinition]
[org.irods.jargon.core.query SpecificQuery
IRODSQueryResultRow]))
(defn- ^SpecificQueryAO get-query-ao
"Gets the specific query AO for the current iRODS session."
[{^IRODSAccessObjectFactory ao-factory :accessObjectFactory
irods-account :irodsAccount}]
(.getSpecificQueryAO ao-factory irods-account))
(defn- define-query
"Defines a specific query in iRODS. This function ignores exceptions thrown by Jargon because
Jargon will throw an exception if the query already exists."
[^SpecificQueryAO query-ao [alias query]]
(try
(.addSpecificQuery query-ao (SpecificQueryDefinition. alias query))
(catch JargonException _)))
(defn define-specific-queries
"Defines the specific queries in a map indexed by query alias."
[cm queries]
(dorun (map (partial define-query (get-query-ao cm)) queries)))
(defn- delete-query
"Deletes a specific query in iRODS."
[^SpecificQueryAO query-ao [alias query]]
(.removeSpecificQuery query-ao (SpecificQueryDefinition. alias query)))
(defn delete-specific-queries
"Deletes the queries in a map indexed by query alias."
[cm queries]
(dorun (map (partial delete-query (get-query-ao cm)) queries)))
(defn query-specifically
[cm ^SpecificQueryAO query-ao ^SpecificQuery query-inst limit]
(try
(->> (.executeSpecificQueryUsingAlias query-ao query-inst limit)
(.getResults)
(map (fn [^IRODSQueryResultRow rs] (vec (.getColumnsAsList rs)))))
(catch DataNotFoundException _ [])))
(defn- get-specific-query-page
[cm alias offset limit args]
(let [query-ao (get-query-ao cm)
args (conj (vec (or args [])) (str limit) (str offset))
query (SpecificQuery/instanceArguments alias args 0 "")]
(query-specifically cm query-ao query limit)))
(defn get-specific-query-results
[cm alias & args]
(let [query-ao (get-query-ao cm)
args (vec (or args []))
query (SpecificQuery/instanceArguments alias args 0 "")]
(query-specifically cm query-ao query 1000000)))
(defn specific-query?
[cm alias]
(try
(.findSpecificQueryByAlias (get-query-ao cm) alias)
true
(catch Exception _ false)))
(defn paged-query
[cm alias limit offset & args]
(let [page (get-specific-query-page cm alias offset limit args)]
(if (seq page) page [])))
(defn execute-specific-query
[cm alias page-size & args]
(letfn [(get-seq [offset]
(let [page (get-specific-query-page cm alias offset page-size args)]
(if (seq page)
(lazy-cat page (get-seq (+ offset page-size)))
[])))]
(get-seq 0)))