 (ns dbmgmt
-  (:require 
+  (:require
     [clojure.edn          :as     edn    ]
     [clojure.data.json    :as     json   ]
     [clojure.java.io      :as     io     ])
   (:import
-    [clojure.lang                           PersistentHashMap PersistentArrayMap ]
-    [java.sql                               Connection DriverManager 
-                                            SQLException Statement ResultSet     ]
-    [java.util                              Properties Date                      ]
-    [java.io                                File BufferedReader                  ]
-    [java.lang.management                   ManagementFactory  RuntimeMXBean     ])
-  (:gen-class 
+    [clojure.lang                           PersistentHashMap PersistentArrayMap  ]
+    [java.sql                               Connection DriverManager
+                                            SQLException Statement ResultSet      ]
+    [java.util                              Properties Date                       ]
+    [java.io                                File BufferedReader                   ]
+    [java.nio                               ByteBuffer                            ]
+    [java.nio.charset                       Charset                               ]
+    [com.amazonaws.services.kms             AWSKMS AWSKMSClientBuilder            ]
+    [com.amazonaws.services.kms.model       DecryptRequest                        ]
+    [com.amazonaws.services.lambda.runtime  Context                               ]
+    [com.amazonaws.util                     Base64                                ]
+    [java.lang.management                   ManagementFactory  RuntimeMXBean      ])
+  (:gen-class
     :methods [^:static [handler [String] String]]))
-
 
 ;; misc
 
 (defn system-properties
   "Returns system-properties as a hashmap {}"
-  ^PersistentHashMap [] 
+  ^PersistentHashMap []
   (reduce (fn [x [y z]] (assoc x y z)) {} (System/getProperties)))
 
 (defn read-file

  []
  (.getInputArguments (ManagementFactory/getRuntimeMXBean)))

(defn exec 
  []
  (let [sql-ret (exec-sql)]
    (println (str "Start time :: " (start-time)))
    (println (str "Input args :: " (get-input-args)))
    (cond
      (contains? sql-ret :ok)
        (println (str "now :: " (.getString (:ok (exec-sql)) "now")))
    :else
      (println (str "Error while executing SQL :: " sql-ret)))))

(defn -handler 
  [s]
  (exec)
  s)

(defn -main 
  [& args] 
  (exec))

  [^ResultSet res]
  (if (.next res) res :err))

(defn get-db-connection
  [db]
  (connect-to-db (get-jdbc-url db)))

(defn exec-sql
  [db-connection statement]
  (try
    {:ok
      (get-fst-result
        (execute-query
          (.createStatement db-connection statement))) }
  (catch Exception e
    {:error "Exception" :fn "exec-sql" :exception (.getMessage e) })))

(defn start-time
  ^Date []
  (Date. (.getStartTime (ManagementFactory/getRuntimeMXBean))))

