From 5916642b2b6ea74c5cf5653c4bf925751792fb30 Mon Sep 17 00:00:00 2001 From: Divyansh Prakash Date: Thu, 7 Apr 2016 13:29:09 +0530 Subject: [PATCH] Fix reflection warnings. --- src/clojure/monger/collection.clj | 14 ++++++++------ src/clojure/monger/core.clj | 29 +++++++++++++++-------------- src/clojure/monger/util.clj | 7 ++++++- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/clojure/monger/collection.clj b/src/clojure/monger/collection.clj index f9c3c9c..81c27db 100644 --- a/src/clojure/monger/collection.clj +++ b/src/clojure/monger/collection.clj @@ -61,7 +61,8 @@ (:require [monger.core :as mc] [monger.result :as mres] [monger.conversion :refer :all] - [monger.constraints :refer :all])) + [monger.constraints :refer :all] + [monger.util :refer [into-array-list]])) ;; @@ -450,9 +451,9 @@ (defn drop-index "Drops an index from this collection." [^DB db ^String coll idx] - (.dropIndex (.getCollection db (name coll)) (if (string? idx) - idx - (to-db-object idx)))) + (if (string? idx) + (.dropIndex (.getCollection db (name coll)) ^String idx) + (.dropIndex (.getCollection db (name coll)) (to-db-object idx)))) (defn drop-indexes "Drops all indixes from this collection." @@ -524,6 +525,7 @@ ;; (defn- build-aggregation-options + ^AggregationOptions [{:keys [^Boolean allow-disk-use cursor ^Long max-time]}] (cond-> (AggregationOptions/builder) allow-disk-use (.allowDiskUse allow-disk-use) @@ -543,7 +545,7 @@ [^DB db ^String coll stages & opts] (let [coll (.getCollection db coll) agg-opts (build-aggregation-options opts) - pipe (java.util.ArrayList. (to-db-object stages)) + pipe (into-array-list (to-db-object stages)) res (.aggregate coll pipe agg-opts)] (map #(from-db-object % true) (iterator-seq res)))) @@ -554,7 +556,7 @@ [^DB db ^String coll stages & opts] (let [coll (.getCollection db coll) agg-opts (build-aggregation-options opts) - pipe (java.util.ArrayList. (to-db-object stages)) + pipe (into-array-list (to-db-object stages)) res (.explainAggregate coll pipe agg-opts)] (from-db-object res true))) ;; diff --git a/src/clojure/monger/core.clj b/src/clojure/monger/core.clj index 1c82d8b..6ec2fa5 100644 --- a/src/clojure/monger/core.clj +++ b/src/clojure/monger/core.clj @@ -42,11 +42,12 @@ * http://clojuremongodb.info/articles/commands.html * http://clojuremongodb.info/articles/gridfs.html" (:refer-clojure :exclude [count]) - (:require [monger.conversion :refer :all]) + (:require [monger.conversion :refer :all] + [monger.util :refer [into-array-list]]) (:import [com.mongodb MongoClient MongoClientURI MongoCredential DB WriteConcern DBObject DBCursor Bytes MongoClientOptions MongoClientOptions$Builder ServerAddress MapReduceOutput MongoException] [com.mongodb.gridfs GridFS] - [java.util Map ArrayList])) + [java.util Map])) ;; ;; Defaults @@ -77,18 +78,18 @@ ([server-address ^MongoClientOptions options] (if (coll? server-address) ;; connect to a replica set - (let [server-list ^ArrayList (ArrayList. ^java.util.Collection server-address)] + (let [server-list (into-array-list server-address)] (MongoClient. server-list options)) ;; connect to a single instance (MongoClient. ^ServerAddress server-address options))) ([server-address ^MongoClientOptions options credentials] - (let [creds (if (coll? credentials) - credentials - [credentials])] + (let [creds (into-array-list (if (coll? credentials) + credentials + [credentials]))] (if (coll? server-address) - (let [server-list ^ArrayList (ArrayList. ^java.util.Collection server-address)] - (MongoClient. server-list creds options)) - (MongoClient. ^ServerAddress server-address creds options)))) + (let [server-list (into-array-list server-address)] + (MongoClient. server-list ^java.util.List creds options)) + (MongoClient. ^ServerAddress server-address ^java.util.List creds options)))) ([{ :keys [host port uri] :or { host *mongodb-host* port *mongodb-port* }}] (if uri (MongoClient. (MongoClientURI. uri)) @@ -100,11 +101,11 @@ (connect-with-credentials *mongodb-host* *mongodb-port* credentials)) ([^String hostname credentials] (connect-with-credentials hostname *mongodb-port* credentials)) - ([^String hostname port credentials] - (MongoClient. [(ServerAddress. hostname port)] - (if (coll? credentials) - credentials - [credentials])))) + ([^String hostname ^long port credentials] + (MongoClient. (into-array-list [(ServerAddress. hostname port)]) + (into-array-list (if (coll? credentials) + credentials + [credentials]))))) (defn get-db-names "Gets a list of all database names present on the server" diff --git a/src/clojure/monger/util.clj b/src/clojure/monger/util.clj index 3128ffa..70aeb4f 100644 --- a/src/clojure/monger/util.clj +++ b/src/clojure/monger/util.clj @@ -57,7 +57,7 @@ "Returns a new BSON object id, or converts str to BSON object id" ([] (ObjectId.)) - ([s] + ([^String s] (ObjectId. s))) (defprotocol GetDocumentId @@ -73,3 +73,8 @@ (get-id [^IPersistentMap object] (or (:_id object) (object "_id")))) + +(defn into-array-list + "Coerce a j.u.Collection into a j.u.ArrayList." + ^java.util.ArrayList [^java.util.Collection coll] + (java.util.ArrayList. coll))