     (println "Database opened")
     (println)
 
-    (if (not database-exists)
+    (def topType (. (. @database getTypeSystem) getTop))
+    (def userThreadRelType (HGQuery$hg/assertAtom @database (HGRelType. "user-thread" (into-array HGHandle [topType topType]))))
+    (def userPostRelType (HGQuery$hg/assertAtom @database (HGRelType. "user-post" (into-array HGHandle [topType topType]))))
+    (def threadPostRelType (HGQuery$hg/assertAtom @database (HGRelType. "thread-post" (into-array HGHandle [topType topType]))))
+
+    (if (= database-exists 0)
       (do
         (def saveTime (Long. 0))
 

           (java.text SimpleDateFormat)
           (java.io File)
           (model User ForumThread Post)
           (org.joda.time DateTime))
  (:require [clojure.string :as string]
            [clojure.xml :as xml]
            [clj-time.format :as f]

    (println "użytkownik wypowiadający się w największej liczbie tematów")
    (let [operationStart (System/currentTimeMillis)]
      (def userHandles (HGQuery$hg/findAll @database (HGQuery$hg/type User)))
      (def uniqueThreadsCount (map (fn [userHandle] (. (HGQuery$hg/findAll @database (HGQuery$hg/and (into-array HGQueryCondition [(HGQuery$hg/incident userHandle) (HGQuery$hg/type userThreadRelType)]))) size)) userHandles))
      ;(def uniqueThreadsCount (map (fn [user] (reduce (fn [count thread] (if (> (. (HGQuery$hg/findAll @database (HGQuery$hg/link (into-array HGHandle [user thread]))) size) 0) (+ count 1) count)) 0 (HGQuery$hg/findAll @database (HGQuery$hg/type ForumThread)))) userHandles))
      (def mostActiveUser (reduce (fn [x y] (if (> (last x) (last y)) x y)) (map vector userHandles uniqueThreadsCount)))
      (println (. (. @database get (first mostActiveUser)) getLogin) (last mostActiveUser))
      (println (string/join " " ["Operation took" (String/valueOf (/ (- (System/currentTimeMillis) operationStart) 1000.0)) "seconds"]))
