forked from jukka/cljcr
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new functions to work with RMI repos
- Loading branch information
1 parent
e778a75
commit 089f39d
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(ns cljcr.rmi | ||
(:use [clojure.contrib.except :only (throwf)]) | ||
(:import (org.apache.jackrabbit.rmi.repository URLRemoteRepository) | ||
(javax.jcr SimpleCredentials) | ||
(javax.jcr.query Query))) | ||
|
||
(defn get-credentials [username password] | ||
(SimpleCredentials. username (.toCharArray password))) | ||
|
||
;; TODO implicitly add /rmi to the url | ||
(defn get-repository [url] | ||
(URLRemoteRepository. url)) | ||
|
||
(defn get-session | ||
([repo creds] | ||
(.login repo creds)) | ||
([repo creds workspace] | ||
(.login repo creds workspace))) | ||
|
||
(defn get-workspace [session] | ||
(.getWorkspace session)) | ||
|
||
(defn get-query-manager [workspace] | ||
(.getQueryManager workspace)) | ||
|
||
(defn create-query [qm statement language] | ||
(.createQuery qm statement language)) | ||
|
||
(defn execute [query] | ||
(.execute query)) | ||
|
||
(defn get-nodes [result] | ||
(iterator-seq (.getNodes result))) | ||
|
||
(defn get-query-type [type] | ||
(if (= type :sql) | ||
Query/JCR_SQL2 | ||
Query/XPATH)) | ||
|
||
(defn get-test-qm [] | ||
(let [url "http://localhost:8080/rmi" | ||
wk-name "nzz" | ||
credentials (SimpleCredentials. "admin" (.toCharArray "admin"))] | ||
(.. (cljcr.rmi/get-repository "http://localhost:8080/rmi") | ||
(login credentials "nzz") | ||
(getWorkspace) | ||
(getQueryManager)))) |