Inlining, part 2

This commit is contained in:
Michael S. Klishin 2012-06-09 00:20:55 +04:00
parent 2a64afa6ff
commit 91d967b592

View file

@ -379,14 +379,17 @@
(monger.collection/save \"people\" { :first_name \"Ian\" :last_name \"Gillan\" }) (monger.collection/save \"people\" { :first_name \"Ian\" :last_name \"Gillan\" })
" "
([^String collection ^Map document] ([^String collection ^Map document]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (.save ^DBCollection (.getCollection monger.core/*mongodb-database* collection)
(.save coll (to-db-object document) monger.core/*mongodb-write-concern*))) (to-db-object document)
monger.core/*mongodb-write-concern*))
([^String collection ^Map document ^WriteConcern write-concern] ([^String collection ^Map document ^WriteConcern write-concern]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (.save ^DBCollection (.getCollection monger.core/*mongodb-database* collection)
(.save coll document write-concern))) document
write-concern))
([^DB db ^String collection ^Map document ^WriteConcern write-concern] ([^DB db ^String collection ^Map document ^WriteConcern write-concern]
(let [^DBCollection coll (.getCollection db collection)] (.save ^DBCollection (.getCollection db collection)
(.save coll document write-concern)))) document
write-concern)))
;; monger.collection/remove ;; monger.collection/remove
@ -402,14 +405,11 @@
" "
([^String collection] ([^String collection]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (.remove ^DBCollection (.getCollection monger.core/*mongodb-database* collection) (to-db-object {})))
(.remove coll (to-db-object {}))))
([^String collection ^Map conditions] ([^String collection ^Map conditions]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (.remove ^DBCollection (.getCollection monger.core/*mongodb-database* collection) (to-db-object conditions)))
(.remove coll (to-db-object conditions))))
([^DB db ^String collection ^Map conditions] ([^DB db ^String collection ^Map conditions]
(let [^DBCollection coll (.getCollection db collection)] (.remove ^DBCollection (.getCollection db collection) (to-db-object conditions))))
(.remove coll (to-db-object conditions)))))
(defn ^WriteResult remove-by-id (defn ^WriteResult remove-by-id
@ -437,14 +437,15 @@
" "
([^String collection ^Map keys] ([^String collection ^Map keys]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (.createIndex ^DBCollection (.getCollection monger.core/*mongodb-database* collection) (to-db-object keys)))
(.createIndex coll (to-db-object keys))))
([^String collection ^Map keys options] ([^String collection ^Map keys options]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (.createIndex ^DBCollection (.getCollection monger.core/*mongodb-database* collection)
(.createIndex coll (to-db-object keys) (to-db-object options)))) (to-db-object keys)
(to-db-object options)))
([^DB db ^String collection ^Map keys ^Map options] ([^DB db ^String collection ^Map keys ^Map options]
(let [^DBCollection coll (.getCollection db collection)] (.createIndex ^DBCollection (.getCollection db collection)
(.createIndex coll (to-db-object keys) (to-db-object options))))) (to-db-object keys)
(to-db-object options))))
;; ;;
@ -463,14 +464,16 @@
(monger.collection/ensure-index \"pages\" { :url 1 } {:unique true}) (monger.collection/ensure-index \"pages\" { :url 1 } {:unique true})
" "
([^String collection, ^Map keys] ([^String collection, ^Map keys]
(let [coll ^DBCollection (.getCollection monger.core/*mongodb-database* collection)] (.ensureIndex ^DBCollection (.getCollection monger.core/*mongodb-database* collection) (to-db-object keys)))
(.ensureIndex ^DBCollection coll ^DBObject (to-db-object keys))))
([^String collection, ^Map keys ^Map options] ([^String collection, ^Map keys ^Map options]
(let [coll ^DBCollection (.getCollection monger.core/*mongodb-database* collection)] (.ensureIndex ^DBCollection (.getCollection monger.core/*mongodb-database* collection)
(.ensureIndex ^DBCollection coll ^DBObject (to-db-object keys) (to-db-object options)))) (to-db-object keys)
(to-db-object options)))
([^String collection ^Map keys ^String name ^Boolean unique?] ([^String collection ^Map keys ^String name ^Boolean unique?]
(let [coll ^DBCollection (.getCollection monger.core/*mongodb-database* collection)] (.ensureIndex (.getCollection monger.core/*mongodb-database* collection)
(.ensureIndex coll ^DBObject (to-db-object keys) ^String name unique?)))) (to-db-object keys)
name
unique?)))
;; ;;
@ -486,8 +489,7 @@
" "
[^String collection] [^String collection]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (from-db-object (.getIndexInfo ^DBCollection (.getCollection monger.core/*mongodb-database* collection)) true))
(from-db-object (.getIndexInfo coll) true)))
;; ;;
@ -497,11 +499,9 @@
(defn drop-index (defn drop-index
"Drops an index from this collection." "Drops an index from this collection."
([^String collection ^String name] ([^String collection ^String name]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (.dropIndex ^DBCollection (.getCollection monger.core/*mongodb-database* collection) name))
(.dropIndex coll name)))
([^DB db ^String collection ^String name] ([^DB db ^String collection ^String name]
(let [^DBCollection coll (.getCollection db collection)] (.dropIndex ^DBCollection (.getCollection db collection) name)))
(.dropIndex coll name))))
(defn drop-indexes (defn drop-indexes
"Drops an indices from this collection." "Drops an indices from this collection."
@ -543,11 +543,9 @@
(monger.collection/drop \"collection-to-drop\") (monger.collection/drop \"collection-to-drop\")
" "
([^String collection] ([^String collection]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (.drop ^DBCollection (.getCollection monger.core/*mongodb-database* collection)))
(.drop coll)))
([^DB db ^String collection] ([^DB db ^String collection]
(let [^DBCollection coll (.getCollection db collection)] (.drop ^DBCollection (.getCollection db collection))))
(.drop coll))))
(defn rename (defn rename
"Renames collection. "Renames collection.
@ -557,14 +555,11 @@
(monger.collection/rename \"old_name\" \"new_name\") (monger.collection/rename \"old_name\" \"new_name\")
" "
([^String from, ^String to] ([^String from, ^String to]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* from)] (.rename ^DBCollection (.getCollection monger.core/*mongodb-database* from) to))
(.rename coll to)))
([^String from ^String to ^Boolean drop-target] ([^String from ^String to ^Boolean drop-target]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* from)] (.rename ^DBCollection (.getCollection monger.core/*mongodb-database* from) to drop-target))
(.rename coll to drop-target)))
([^DB db ^String from ^String to ^Boolean drop-target] ([^DB db ^String from ^String to ^Boolean drop-target]
(let [^DBCollection coll (.getCollection db from)] (.rename ^DBCollection (.getCollection db from) to drop-target)))
(.rename coll to drop-target))))
;; ;;
;; Map/Reduce ;; Map/Reduce
@ -587,14 +582,11 @@
(defn distinct (defn distinct
"Finds distinct values for a key" "Finds distinct values for a key"
([^String collection ^String key] ([^String collection ^String key]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (.distinct ^DBCollection (.getCollection monger.core/*mongodb-database* collection) ^String (to-db-object key)))
(.distinct coll ^String (to-db-object key))))
([^String collection ^String key ^Map query] ([^String collection ^String key ^Map query]
(let [^DBCollection coll (.getCollection monger.core/*mongodb-database* collection)] (.distinct ^DBCollection (.getCollection monger.core/*mongodb-database* collection) ^String (to-db-object key) ^DBObject (to-db-object query)))
(.distinct coll ^String (to-db-object key) ^DBObject (to-db-object query))))
([^DB db ^String collection ^String key ^Map query] ([^DB db ^String collection ^String key ^Map query]
(let [^DBCollection coll (.getCollection db collection)] (.distinct ^DBCollection (.getCollection db collection) ^String (to-db-object key) ^DBObject (to-db-object query))))
(.distinct coll ^String (to-db-object key) ^DBObject (to-db-object query)))))
;; ;;