Source

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

Diff from to

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