 ;;--------------------------------------------------------------------------------
 ;; data model
 
+(def whale-attributes
+     (list
+      [:id       (Integer/TYPE) false]
+      [:version  (Integer/TYPE) true]
+      ;;[:time     Date           true]
+      ;;[:reporter String         true]
+      [:type     clojure.lang.Keyword         false]	;a whale cannot change type
+      [:ocean    clojure.lang.Keyword         true]
+      [:length   (Float/TYPE)   true]
+      ;;[:weight   (Float/TYPE)   true]
+      ))
+
 (def whale-data
-     ;;[id, version, type, ocean, length]
      [[0 0 :blue :atlantic 100]
       [1 0 :blue :pacific  100]
       [2 0 :grey :atlantic 50]
       [3 0 :grey :pacific  50]])
 
-(def whales (model "Whales" (seq-metadata (count (first whale-data)))))
+;;(def whale-metadata (seq-metadata (count (first whale-data))))
+(def whale-metadata (custom-metadata "org.dada.core.tmp.Whale" 
+				     Object
+				     [:id]
+				     [:version] 
+				     int-version-comparator 
+				     whale-attributes))
+
+(def whales (model "Whales" whale-metadata))
 (insert *metamodel* whales)
-(insert-n whales whale-data)
+
+;;(insert-n whales whale-data)
+(let [creator (.getCreator whale-metadata)]
+      (insert-n
+       whales
+       (map (fn [datum] (.create creator (into-array Object datum))) whale-data)))
 
 ;;--------------------------------------------------------------------------------
 ;; utils

    [[key]
     (if (every? (fn [value] (instance? Result value)) values) ;TODO - is this the best I can do ?
       (reduce (fn [map value] (conj map (nested-split-values2 value))) {} values)
       values)]))

(defn nested-split-values [[metadata-fn data-fn]]
    (second (nested-split-values2 (data-fn))))

	value (first (.getExtant (.getData model)))]
    (.get (.getGetter #^Attribute (nth (.getAttributes (.getMetadata model)) 1)) value)))

(defn to-list [#^Whale whale]
  (map (fn [#^Attribute attribute] (.get (.getGetter attribute) whale)) (.getAttributes whale-metadata)))

(defn flat-split-values [[metadata-fn data-fn]]
  (reduce
   (fn [values #^Result result]
       (println (.getModel result) (.getPrefix result) "," (.getPairs result) "," (.getOperation result))
       (conj values [(map second (.getPairs result)) 
		     (map to-list (.getExtant (.getData (.getModel result))))]))
   {}
   (.getExtant (.getData (.getModel (data-fn))))))

