Permalink
Browse files

new functions to work with RMI repos

  • Loading branch information...
1 parent e778a75 commit 089f39da2fefdcab7d2ac02c79a31411f6df4855 @videlalvaro committed Oct 11, 2011
Showing with 47 additions and 0 deletions.
  1. +47 −0 src/cljcr/rmi.clj
View
@@ -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))))

0 comments on commit 089f39d

Please sign in to comment.