Commits

Anonymous committed eeba38a

omit superfluous type hints

  • Participants
  • Parent commits 8538d1e

Comments (0)

Files changed (5)

File src/main/clj/org/bituf/sqlrat/clause.clj

 
 
 (defn merge-key-clauses
-  [prefix ^Keyword k ^IPersistentVector clause & more]
+  [prefix k clause & more]
   (let [clauses (into [clause] more)
         sclause (apply merge-clauses clauses)] ; sclause = super-clause
     (if (empty-clause? sclause) (empty-clause)
 
 (defn enclose
   "Enclose a clause with '(' and ')' characters"
-  [^IPersistentVector clause]
+  [clause]
   (merge-clauses (as-clause "(")
     clause (as-clause ")")))
 
 ;; short hand
 
-(defn SELECT  [^Vector clause & more] (apply merge-key-clauses nil :select
-                                        (into [clause] more)))
-(defn FROM    [^Vector clause & more] (apply merge-key-clauses " " :from
-                                        (into [clause] more)))
-(defn WHERE   [^Vector clause & more] (apply merge-key-clauses " " :where
-                                        (into [clause] more)))
-(defn GROUPBY [^Vector clause & more] (apply merge-key-clauses " " :group-by
-                                        (into [clause] more)))
+(defn SELECT  [clause & more] (apply merge-key-clauses nil :select
+                                (into [clause] more)))
+(defn FROM    [clause & more] (apply merge-key-clauses " " :from
+                                (into [clause] more)))
+(defn WHERE   [clause & more] (apply merge-key-clauses " " :where
+                                (into [clause] more)))
+(defn GROUPBY [clause & more] (apply merge-key-clauses " " :group-by
+                                (into [clause] more)))
 (def ^{:doc "Alias for GROUPBY"}
       GROUP-BY GROUPBY)
 
     (if (clause? v) (merge-clauses (as-clause (str (str-name k) op))
                       (enclose v)) ;; sub-query
       (as-clause [(str (str-name k) op \?) v])))
-  ([op k v ^IFn if-nil-fn1]
+  ([op k v if-nil-fn1]
     (if (nil? v) (if-nil-fn1 k)
       (op2 op k v))))
 
 (defn like?
   "Like
    Example: (like? :flag \"on\") >> [\"flag LIKE ?\" \"on\"]"
-  [k ^String v]
+  [k v]
   (assert v)
   (op2 " LIKE " k v))
 
 (defn begins-with?
   "Begins with
    Example: (begins-with? :name \"ram\") >> [\"name LIKE ?\" \"ram%\"]"
-  [k ^String v]
+  [k v]
   (assert v)
   (like? k (str v \%)))
 
 (defn ends-with?
   "Ends with
    Example: (ends-with? :name \"reynolds\") >> [\"name LIKE ?\" \"%reynolds\"]"
-  [k ^String v]
+  [k v]
   (assert v)
   (like? k (str \% v)))
 
 (defn includes?
   "Includes
    Example: (includes? :name \"matt\") >> [\"name LIKE ?\" \"%matt%\"]"
-  [k ^String v]
+  [k v]
   (assert v)
   (like? k (str \% v \%)))
 
 ;; Convenience functions for parameters in a map
 (defn map-to-clauses
   "Apply function op2fn to a map. Example:
-   (map-to-clauses in=? {:a 10 :b [20 30] :c nil})
-   >> ([\"a=?\" 10] [\"b IN (?, ?)\" 20 30] [\"c IS NULL\"])
+   user=> (map-to-clauses in=? {:a 10 :b [20 30] :c nil})
+   ([\"a=?\" 10] [\"b IN (?, ?)\" 20 30] [\"c IS NULL\"])
    The function op2fn should take 2 operands and must return a clause."
-  [^IFn op2fn ^Map pairs]
-  (map #(op2fn (first %) (last %)) (seq pairs)))
+  [op2fn kvmap]
+  (map #(op2fn (first %) (last %)) (seq kvmap)))
 
 
 (defn ?
   ([value]
     (if (map? value) (? in=? value)
       (as-value-clause value)))
-  ([^IFn op2fn ^IPersistentMap m]
+  ([op2fn m]
     (if *assert-args*
       (assert (fn? op2fn))
       (assert (map? m)))
 (defn sqlfn
   "Example: user=> (sqlfn :AVG :subjectid)
             [\"AVG(subjectid)\"]"
-  [^Keyword fn-name & args]
+  [fn-name & args]
   (merge-clauses
     (apply merge-clauses
       (as-clause (str (str-name fn-name) "("))
 (defn as
   "Example: user=> (as :avgscore \"AVG(score)\")
             [\"AVG(score) AS avgscore\"]"
-  [^Keyword new-colname expr]
+  [new-colname expr]
   (apply merge-clauses
     (map as-clause [expr " AS " new-colname])))
 
 (defn asfn
   "Example: user=> (asfn :avgscore :AVG :score)
             [\"AVG(score) AS avgscore\"]"
-  [^Keyword new-colname ^Keyword fn-name & args]
+  [new-colname fn-name & args]
   (as new-colname (apply sqlfn fn-name args)))

File src/main/clj/org/bituf/sqlrat/clause/internal.clj

    :where becomes \" WHERE \"
    :group-by becomes \" GROUP BY \"
    and so on."
-  [^Keyword clause-key key-prefix]
+  [clause-key key-prefix]
   (if *assert-args* (assert (keyword? clause-key)))
   (.toUpperCase
     (.replace

File src/main/clj/org/bituf/sqlrat/entity.clj

       (db-query [\"SELECT * FROM emp WHERE id=?\" 56]))
     => [{<row1 data>} {<row2 data>} ...] ;; returns the rows as a vector
   See also: with-db-query-results"
-  ([^IFn f ^IPersistentVector query]
+  ([f query]
     (if *assert-args* (do
                         (assert (fn? f))
                         (assert (vector? query))))
     (if *show-sql* (mypp "Executing SQL..." query))
     (sql/with-query-results rows query
       (f rows)))
-  ([^IPersistentVector query]
+  ([query]
     (let [f (fn [rows]
               (let [result (if (nil? rows) nil (into [] rows))]
                 (if *show-sql-results* (mypp "SQL Result..." rows))
         (println rows)))
     => <rows-data>
   See also: db-query"
-  [rows ^IPersistentVector sql-params & body]
+  [rows sql-params & body]
   `(db-query (fn [~rows] ~@body) ~sql-params))
 
 
       (save-row :emp {:empid 197 :code 9667 :name \"Joe Hacker\"} :empid))
     => {:empid 197 :code 1337 :name \"Joe Hacker\"} ;; updated code and name
   See also: save"
-  [^Keyword table ^IPersistentMap row ^Keyword id-column]
+  [table row id-column]
   (let [id=? (str (name id-column) "=?")]
     (let [result (update-or-insert-values-returnid
                    table [id=? (id-column row)] row)]
   Example:
     (relation :orderid item-metadata :itemid true) ;; order to item relation
   See also: one-to-many, many-to-one, one-to-one, one-to-one-depends"
-  ([^Keyword this-col ^EntityMetadata that-ent ^Keyword that-col that-depends?]
-    (RelationMetadata. this-col that-ent that-col that-depends?))
-  ([^Keyword this-col ^EntityMetadata that-ent ^Keyword that-col]
-    (RelationMetadata. this-col that-ent that-col false)))
+  ([this-col that-ent-meta that-col that-depends?]
+    (RelationMetadata. this-col that-ent-meta that-col that-depends?))
+  ([this-col that-ent-meta that-col]
+    (RelationMetadata. this-col that-ent-meta that-col false)))
 
 
 (defn one-to-many
   Example:
     (one-to-many :orderid item-metadata :itemid)
   See also: relation, many-to-one"
-  [^Keyword this-col ^EntityMetadata that-ent-meta ^Keyword that-col]
+  [this-col that-ent-meta that-col]
   (relation this-col that-ent-meta that-col true))
 
 
   Example:
     (many-to-one :itemid order-metadata :orderid)
   See also: relation, one-to-many"
-  [^Keyword this-col ^EntityMetadata that-ent-meta ^Keyword that-col]
+  [this-col that-ent-meta that-col]
   (relation this-col that-ent-meta that-col false))
 
 
     rels-vector  (Vector) of relation specs
   Example: See extend-entity
   See also: relation, extend-entity"
-  [^IPersistentVector rels-vector]
+  [rels-vector]
   {:rel-meta (fn [this] (as-vector rels-vector))} )
 
 
 
 (defn to-row
   "Default implementation for to-row-fn."
-  [^IPersistentMap entity]
+  [entity]
   (into {} entity))
 
 
                [:whenposted \"DATETIME\"     \"NOT NULL\"]
                [:isdeleted  \"BOOLEAN\"      \"NOT NULL DEFAULT false\"]] ))
   See also: Functions take entity metadata as argument."
-  [^Keyword name ^Keyword id ^IFn from-row-fn
-   & {:keys [^IPersistentVector cols ^IFn to-row-fn]
+  [name id from-row-fn
+   & {:keys [cols to-row-fn]
       :or   {to-row-fn to-row}}]
   (EntityMetadata. name id from-row-fn
     {} {:cols cols :to-row-fn to-row-fn}))
   Example:
     (entity-impl e-meta) ;; where e-meta is the entity metadata
   See also: entity-meta"
-  [^EntityMetadata ent-metadata]
+  [ent-metadata]
   {:get-meta (fn [this] ent-metadata)} )
 
 
   relation metadata. This function may typically be called only once after the
   entity data type is defined.
   Arguments:
-    ent-type     The entity data type (not an instance)
-    ent-metadata Entity metadata
-    rel-metadata Relation metadata
+    ent-type     (Class) The entity data type (not an instance)
+    ent-metadata (EntityMetadata) Entity metadata
+    rel-metadata (Vector) Relation metadata
   Example:
     (extend-entity BlogEntry blog-entry-meta
       [(one-to-many :autoid  entry-comment-meta :entryid)] )
   See also: entity-meta"
-  ([^Class ent-type ^EntityMetadata ent-metadata]
+  ([ent-type ent-metadata]
     (extend ent-type
       Entity   (entity-impl ent-metadata)))
-  ([^Class ent-type ^EntityMetadata ent-metadata
-    ^IPersistentVector rel-metadata]
+  ([ent-type ent-metadata rel-metadata]
     (extend ent-type
       Entity   (entity-impl ent-metadata)
       Relation (rel-impl    rel-metadata))))
 
 (defn read-count-col
   "Read the value of count-col from specified row or entity."
-  [^IPersistentMap row-or-entity]
+  [row-or-entity]
   (if *assert-args* (assert-arg #(or (nil? %) (map? %))
                       row-or-entity))
   (:sqlratcnt row-or-entity))
   "Read the value of count-col from the first row/entity of a vector. Useful
   when the count-col is not grouped by some column and hence there is just one
   row in the result set."
-  [^IPersistentVector row-vector]
+  [row-vector]
   (if *assert-args* (assert-arg #(or (nil? %) (vector? %))
                       row-vector))
   (read-count-col (first row-vector)))
 
 (defn get-id-column
   "Return ID column from entity"
-  [^IPersistentMap entity]
+  [entity]
   (if *assert-args* (assert-arg entity? entity))
   (:id (get-meta entity)))
 
 
 (defn get-id-value
   "Return ID column value from entity"
-  [^IPersistentMap entity]
+  [entity]
   (if *assert-args* (assert-arg entity? entity))
   ((get-id-column entity) entity))
 
 
 (defn create-table
   "Create table"
-  [^EntityMetadata entity-meta]
+  [entity-meta]
   (if *assert-args* (assert-as entity-meta EntityMetadata))
   (let [table-name (:name entity-meta)
         cols-spec  (:cols entity-meta)]
 
 (defn drop-table
   "Drop table"
-  [^EntityMetadata entity-meta]
+  [entity-meta]
   (if *assert-args* (assert-as entity-meta EntityMetadata))
   (sql/drop-table (:name entity-meta)))
 
       (println
         (find-by-sql employee-meta [\"SELECT * FROM emp\"])))
   See also: with-find-by-sql-results"
-  ([^IFn f ^EntityMetadata entity-meta ^IPersistentVector sql-vec]
+  ([f entity-meta sql-vec]
     (if *assert-args* (do
                         (assert (fn? f))
                         (assert-as entity-meta EntityMetadata)))
     (let [sql-vector (as-vector sql-vec)]
       (with-db-query-results results sql-vector
         (f (map #((:from-row-fn entity-meta) %) results)))))
-  ([^EntityMetadata entity-meta sql-vec]
+  ([entity-meta sql-vec]
     (let [f (fn [entities] (into [] entities))]
       (find-by-sql f entity-meta sql-vec))))
 
       (with-find-by-sql-results es emp-meta [\"SELECT * FROM emp\"]
         (println es)))
   See also: find-by-sql"
-  [entities ^EntityMetadata entity-meta ^IPersistentVector sql-vec & body]
+  [entities entity-meta sql-vec & body]
   `(find-by-sql (fn [~entities] ~@body) ~entity-meta ~sql-vec))
 
 
     :other [\"ORDER BY whenposted\"]
     | OR | :other (merge-key-clause :order-by (cscols [:whenposted])) ; clause
   See also: with-find-by-criteria-results"
-  ([^IFn f ^EntityMetadata entity-meta
-    ^IPersistentMap {:keys [^IPersistentVector cols    ^IPersistentVector where
-                            ^IPersistentVector groupby ^IPersistentVector other]
-                     :or   {cols    [star-col]     ;; vector of col names
-                            where   (empty-clause) ;; clause
-                            groupby []             ;; vector of expressions
-                            other   (empty-clause) ;; clause
-                            }}]
+  ([f entity-meta {:keys [cols where groupby other]
+                   :or   {cols    [star-col]     ;; vector of col names
+                          where   (empty-clause) ;; clause
+                          groupby []             ;; vector of expressions
+                          other   (empty-clause) ;; clause
+                          }}]
     (if *assert-args* (do
                         (assert (fn? f))
                         (assert-as entity-meta EntityMetadata)
                          (GROUP-BY (csnames groupby))
                          other-clause)]
       (find-by-sql (fn [entities] (f entities)) entity-meta sql-vector)))
-  ([^EntityMetadata entity-meta ^IPersistentMap criteria]
+  ([entity-meta criteria]
     (find-by-criteria as-vector entity-meta criteria))
-  ([^EntityMetadata entity-meta]
+  ([entity-meta]
     (find-by-criteria entity-meta {})))
 
 
                                                   :where [\"salary>?\" 10000]}
         (println es)))
   See also: find-by-criteria"
-  [entities ^EntityMetadata entity-meta ^IPersistentMap criteria & body]
+  [entities entity-meta criteria & body]
   `(let [{cols# :cols where# :where groupby# :groupby other# :other} ~criteria]
     (find-by-criteria (fn [~entities] ~@body) ~entity-meta
       {:cols cols# :where where# :groupby groupby# :other other#})))
     (in-db mysql
       (println (find-by-idemp-meta 1197)))
   See also: find-by-criteria"
-  ([^EntityMetadata entity-meta id
-    ^IPersistentMap {:keys [^IPersistentVector cols    ^IPersistentVector where
-                            ^IPersistentVector groupby ^IPersistentVector other]
-                     :or   {cols    [star-col]     ;; vector of col names
-                            where   (empty-clause) ;; clause
-                            groupby []             ;; vector of expressions
-                            other   (empty-clause) ;; clause
-                            }}]
+  ([entity-meta id {:keys [cols where groupby other]
+                    :or   {cols    [star-col]     ;; vector of col names
+                           where   (empty-clause) ;; clause
+                           groupby []             ;; vector of expressions
+                           other   (empty-clause) ;; clause
+                           }}]
     (if *assert-args* (do
                         (assert-as entity-meta EntityMetadata)
                         (assert (not (nil? id)))
                           :groupby groupby :other   other} )]
       (if (empty? rows) nil
         ((:from-row-fn entity-meta) (first rows)))))
-  ([^EntityMetadata entity-meta id]
+  ([entity-meta id]
     (find-by-id entity-meta id {})))
 
 
       (let [e (Employee. {} {:name \"Billy Norman\" :code 5564})]
         (save e)))
   See also: find-by-id"
-  [^Entity entity]
+  [entity]
   (if *assert-args* (assert-arg entity? entity))
   (let [ent-meta (get-meta entity)
         from-row-fn (:from-row-fn ent-meta)]
     (if *assert-args* (assert-as entity-meta EntityMetadata))
     (sql/delete-rows (:name entity-meta)
       [(str (name (:id entity-meta)) "=?") id]))
-  ([^Entity entity]
+  ([entity]
     (if *assert-args* (assert-arg entity? entity))
     (delete (get-meta entity) (get-id-value entity))))
 
 
 (defn- assert-same-type-entities
   "Assert that all entities are of the same type."
-  [^IPersistentVector entities]
+  [entities]
   (assert (vector? entities))
   (if (or
         (nil?   entities)
   {e1 [e1r1 e1r2]
    e2 [e2r1 e2r2 e2r3]}
   Note: e3 is not a key in the map as it has no corresponding related entities"
-  [^IPersistentVector entities ^IPersistentVector rel-entities]
+  [entities rel-entities]
   (if *assert-args* (do
                       (assert-same-type-entities entities)
                       (assert-same-type-entities rel-entities)))
             rs (find-rels es order-line-meta {:where (>? :qty 5)})] ; qty > 5
         (println rs)))
   See also: with-find-rels-results"
-  ([^IFn f ^IPersistentVector entities ^EntityMetadata that-meta
-    ^IPersistentMap {:keys [^IPersistentVector cols    ^IPersistentVector where
-                            ^IPersistentVector groupby ^IPersistentVector other]
-                     :or   {cols    [star-col]     ;; vector of col names
-                            where   (empty-clause) ;; clause
-                            groupby []             ;; vector of expressions
-                            other   (empty-clause) ;; clause
-                            }}]
+  ([f entities that-meta {:keys [cols where groupby other]
+                          :or   {cols    [star-col]     ;; vector of col names
+                                 where   (empty-clause) ;; clause
+                                 groupby []             ;; vector of expressions
+                                 other   (empty-clause) ;; clause
+                                 }}]
     (if *assert-args* (do
                         (assert (fn? f))
                         (assert (vector? entities))
           where-clause   (if (empty-clause? where) new-where
                            (AND new-where where))
           ;; add 'that-col' to the cols being fetched
-          add-rel-column (fn [^IPersistentVector few-cols]
+          add-rel-column (fn [few-cols]
                            (if (some #(or
                                         (= that-column %)  ;; that-col
                                         (= star-col %))    ;; OR star-col
           ]
       (with-find-by-criteria-results ents that-meta criteria
         (f ents))))
-  ([^IPersistentVector entities ^EntityMetadata that-meta
-    ^IPersistentMap criteria]
+  ([entities that-meta criteria]
     (find-rels as-vector entities that-meta criteria))
-  ([^IPersistentVector entities ^EntityMetadata that-meta]
+  ([entities that-meta]
     (find-rels entities that-meta {})))
 
 
         (with-find-rels-results rs es order-line-meta {:where (>? :qty 5)}
           (println rs))))
   See also: find-rels"
-  [rel-entities ^IPersistentVector entities ^EntityMetadata that-meta
-   ^IPersistentMap criteria & body]
+  [rel-entities entities that-meta criteria & body]
   `(let [{cols# :cols where# :where groupby# :groupby other# :other} ~criteria]
     (find-rels (fn [~rel-entities] ~@body) ~entities ~that-meta
       {:cols cols# :where where# :groupby groupby# :other other#})))
   "Find related entities for the given set of entities and return a map of
   entity versus related-entities (see entity-rel-map function for details).
   See also: entity-rel-map, find-rels"
-  ([^IPersistentVector entities ^EntityMetadata that-meta
-    ^IPersistentMap criteria]
+  ([entities that-meta criteria]
     (entity-rels-map entities (find-rels entities that-meta criteria)))
-  ([^IPersistentVector entities ^EntityMetadata that-meta]
+  ([entities that-meta]
     (find-entity-rels-map entities that-meta {})))
 
 
 (defn save-deps
   "Save dependents (dep-entities) in a 1-to-many scenario for a given entity."
-  [^Entity entity ^IPersistentVector dep-entities]
+  [entity dep-entities]
   (if *assert-args* (do
                       (assert (map? entity))
                       (assert (vector? dep-entities))
             r (find-siblings e department-meta)]
         (println r)))
   See also: with-find-siblings-results"
-  ([^IFn f ^Entity entity ^EntityMetadata rel-entity-meta
-    ^IPersistentMap {:keys [cols where groupby other]
-                     :or   {cols    [star-col]     ;; vector of col names
-                            where   (empty-clause) ;; clause
-                            groupby []             ;; vector of expressions
-                            other   (empty-clause) ;; clause
-                            }}]
+  ([f entity rel-entity-meta {:keys [cols where groupby other]
+                              :or   {cols    [star-col]     ;; vector of col names
+                                     where   (empty-clause) ;; clause
+                                     groupby []             ;; vector of expressions
+                                     other   (empty-clause) ;; clause
+                                     }}]
     (if *assert-args* (do
                         (assert (fn? f))
                         (assert (map? entity))
           ]
       (with-find-by-criteria-results ents this-meta criteria
         (f ents))))
-  ([^Entity entity ^EntityMetadata rel-entity-meta ^IPersistentMap criteria]
+  ([entity rel-entity-meta criteria]
     (find-siblings #(into [] %) entity rel-entity-meta criteria))
-  ([^Entity entity ^EntityMetadata rel-entity-meta]
+  ([entity rel-entity-meta]
     (find-siblings #(into [] %) entity rel-entity-meta {})))
 
 
         (with-find-siblings-results sib e department-meta {}
           (println sib))))
   See also: find-rels"
-  [sibling-entities ^Entity entity ^EntityMetadata rel-entity-meta
-   ^IPersistentMap criteria & body]
+  [sibling-entities entity rel-entity-meta criteria & body]
   `(find-siblings (fn [~sibling-entities] ~@body) ~entity ~rel-entity-meta
      ~criteria))
 
 
 (defn delete-cascade
   "Delete a given entity (cascaded, i.e. also deep-delete dependent relations)"
-  [^Entity entity]
+  [entity]
   (if *assert-args* (assert-arg entity? entity))
   (let [rels (rel-meta entity)]
     (doseq [each rels]
   used as title. Passing an empty sequence of entities prints nothing at all.
   Arguments:
     entities  (Vector) of entities"
-  [^IPersistentVector entities]
+  [entities]
   (mypp "\nENTITIES ***\n" entities)
   (if *assert-args*
     (do

File src/main/clj/org/bituf/sqlrat/entity/internal.clj

 
 (defn get-original-entity
   "Find parent entity for the specified child-entity from a group of entities"
-  [^IPersistentVector entities ^Keyword this-column
-   ^IPersistentMap rel-entity  ^Keyword that-column]
+  [entities this-column rel-entity that-column]
   (let [foreign-key (that-column rel-entity)]
     (first (filter #(= (this-column %) foreign-key)
              entities))))

File src/main/clj/org/bituf/sqlrat/util.clj

 (defn arg
   "Apply f? (must return Boolean) to arg - return true when asserted true,
    throw exception otherwise."
-  [^IFn f? arg]
+  [f? arg]
   (if (f? arg) true
     (bad-arg! "Invalid argument " (vstr arg) " (Expected: " (:name (meta f?))
       ", Found: " (vstr (type arg)) ")")))
 
 (defn assert-arg
   "Assert specified argument using the function f?, which must return Boolean."
-  [^IFn f? param]
+  [f? param]
   (assert (arg f? param)))
 
 
 (defn assert-as
-  [item ^Class expected-type]
+  [item expected-type]
   (assert (instance? Class expected-type))
   (try
     (assert (isa? (type item) expected-type))