Advertisement
newm4n

Database Component

Feb 4th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns coresystem.system.database
  2.   (:require [clojure.tools.logging :refer [info]]
  3.             [com.stuartsierra.component :as component]
  4.             [coresystem.seed :as seeder]
  5.             [clojurewerkz.titanium.graph :as tg]))
  6.  
  7. (defrecord Database [graphConfig]
  8.   component/Lifecycle
  9.   (start [component]
  10.          (info "Starting titan")
  11.          (let [graph (tg/open graphConfig)]
  12.            (if (= (graphConfig "storage.backend") "inmemory")
  13.              (do
  14.                (info "Inmemory implementation is executed. Populating SEED data.")
  15.                (seeder/run graph)
  16.                (def debuggraph graph)))
  17.            (assoc component :graph graph)))
  18.   (stop [component]
  19.         (info "Stopping titan")
  20.         (when-let [titan (:jetty component)]
  21.           (when-not (.isStopped titan)
  22.             (.stop titan)))
  23.         component))
  24.  
  25. (defn database [graphConfig]
  26.   (map->Database {:graphConfig graphConfig}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement