Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add generated data (e.g. uuids)
  • Loading branch information
clayton committed Oct 7, 2017
1 parent e1108c4 commit ee652be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions src/main/clojure/de/mpg/shh/util_datomic_peer/impl/push.clj
Expand Up @@ -50,9 +50,20 @@
(conj accumulator [(first (last accumulator)) item next-sym] (conj accumulator [(first (last accumulator)) item next-sym]
[next-sym component-id-attr component-id-attr-val]))) [next-sym component-id-attr component-id-attr-val])))


(defn namespace-attrs
[attr-paths-lookup id-attr]
(for [[k v] attr-paths-lookup :when (and (= (namespace k) (namespace id-attr))
(not= k id-attr))] k))

(defn generate-attr-tx-data
[dt-value-type-lookup attr]
(when-let [value-type (get dt-value-type-lookup attr)]
(cond
(= value-type :db.type/uuid) [:db/add -1 attr (dt/squuid)])))

;; query for the id of the parent entity ;; query for the id of the parent entity
(defn cache-row (defn cache-row
[ds-conn attr-paths-lookup component-attr-id-attr-map row] [ds-conn dt-value-type-lookup attr-paths-lookup component-attr-id-attr-map row]
(let [;;_ (info "attr-paths-lookup: " attr-paths-lookup) (let [;;_ (info "attr-paths-lookup: " attr-paths-lookup)
insertion-order (sort-by namespace (filter #(contains? attr-paths-lookup %) (keys row))) insertion-order (sort-by namespace (filter #(contains? attr-paths-lookup %) (keys row)))
;;_ (info "insertion-order: " insertion-order) ;;_ (info "insertion-order: " insertion-order)
Expand All @@ -65,7 +76,10 @@
first) first)
;;_ (info "root-result: " root-result) ;;_ (info "root-result: " root-result)
_ (when (nil? root-result) _ (when (nil? root-result)
(ds/transact ds-conn [[:db/add -1 (first insertion-order) (get row (first insertion-order))]]))] (let [other-root-attrs (namespace-attrs attr-paths-lookup (first insertion-order))
generated-tx-data (vec (remove nil? (map (partial generate-attr-tx-data dt-value-type-lookup) (remove #(contains? row %) other-root-attrs))))]
(ds/transact ds-conn (concat [[:db/add -1 (first insertion-order) (get row (first insertion-order))]]
generated-tx-data))))]
(doseq [field (rest insertion-order)] (doseq [field (rest insertion-order)]
;;(dorun (map (partial cache-field conn attr-paths-lookup component-attr-id-attr-map row) insertion-order)) ;;(dorun (map (partial cache-field conn attr-paths-lookup component-attr-id-attr-map row) insertion-order))
(let [field-attr-paths (get attr-paths-lookup field) (let [field-attr-paths (get attr-paths-lookup field)
Expand Down Expand Up @@ -95,8 +109,9 @@
[:db/add -1 component-id-attr component-id-attr-val] [:db/add -1 component-id-attr component-id-attr-val]
[:db/add -1 field (get row field)]])) [:db/add -1 field (get row field)]]))
;;_ (info "tx-data: " tx-data) ;;_ (info "tx-data: " tx-data)
] other-attrs (namespace-attrs attr-paths-lookup component-id-attr)
(ds/transact ds-conn tx-data)) generated-tx-data (vec (remove nil? (map (partial generate-attr-tx-data dt-value-type-lookup) (remove #(contains? row %) other-attrs))))]
(ds/transact ds-conn (concat tx-data generated-tx-data)))
(not= (get result field) (get row field)) (not= (get result field) (get row field))
(ds/transact ds-conn [[:db/add (:db/id result) field (get row field)]]))))) (ds/transact ds-conn [[:db/add (:db/id result) field (get row field)]])))))
)) ))
Expand Down
Expand Up @@ -14,5 +14,5 @@
ds-conn (ds/conn-from-db (ds/init-db datoms schema)) ds-conn (ds/conn-from-db (ds/init-db datoms schema))
attr-paths (peer-push/push->path [] [] push-pattern) attr-paths (peer-push/push->path [] [] push-pattern)
attr-paths-lookup (into {} (map #(vector (last %) (vec (butlast %))) attr-paths)) attr-paths-lookup (into {} (map #(vector (last %) (vec (butlast %))) attr-paths))
_ (dorun (map (partial peer-push/cache-row ds-conn attr-paths-lookup component-attr-id-attr-map) rows))] _ (dorun (map (partial peer-push/cache-row ds-conn dt-value-type-lookup attr-paths-lookup component-attr-id-attr-map) rows))]
(peer-push/datascript->datomic-tx-data ds-conn dt-partition dt-value-type-lookup)))) (peer-push/datascript->datomic-tx-data ds-conn dt-partition dt-value-type-lookup))))

0 comments on commit ee652be

Please sign in to comment.