File tree Expand file tree Collapse file tree 3 files changed +33
-18
lines changed Expand file tree Collapse file tree 3 files changed +33
-18
lines changed Original file line number Diff line number Diff line change 44
44
(common/-read-from-cursor cursor)))
45
45
46
46
(nth [_ i not-found]
47
- (try
48
- (let [cursor (.getCursor ral (long i))]
49
- (if cursor
50
- (common/-read-from-cursor cursor)
51
- not-found))
52
- (catch Exception _
47
+ (let [cursor (.getCursor ral (long i))]
48
+ (if cursor
49
+ (common/-read-from-cursor cursor)
53
50
not-found)))
54
51
55
52
clojure.lang.ILookup
Original file line number Diff line number Diff line change 38
38
(common/-read-from-cursor cursor)))
39
39
40
40
(nth [_ i not-found]
41
- (try
42
- (let [cursor (.getCursor rlal (long i))]
43
- (if cursor
44
- (common/-read-from-cursor cursor)
45
- not-found))
46
- (catch Exception _
41
+ (let [cursor (.getCursor rlal (long i))]
42
+ (if cursor
43
+ (common/-read-from-cursor cursor)
47
44
not-found)))
48
45
49
46
clojure.lang.ILookup
Original file line number Diff line number Diff line change 56
56
Uses the MessageDigest from the database."
57
57
^bytes [^Database jdb v]
58
58
(if (nil? v)
59
- (byte-array (-> jdb .-header .hashSize))
60
- (let [hash-code (hash v)
61
- buffer (ByteBuffer/allocate Integer/BYTES)
62
- _ (.putInt buffer hash-code)
63
- bytes (.array buffer)]
64
- (.digest (.md jdb) bytes))))
59
+ (byte-array (-> jdb .md .getDigestLength))
60
+ (do
61
+ ; ; add type name
62
+ (.update (.md jdb) (-> v .getClass .getCanonicalName (.getBytes " UTF-8" )))
63
+ ; ; add null byte as separator
64
+ (.update (.md jdb) (byte-array 1 ))
65
+ ; ; add the value
66
+ (cond
67
+ (validation/lazy-seq? v)
68
+ (throw (IllegalArgumentException. " Lazy sequences can be infinite and not allowed!" ))
69
+
70
+ (bytes? v)
71
+ (.update (.md jdb) v)
72
+
73
+ (instance? Database$Bytes v)
74
+ (.update (.md jdb) (.value v))
75
+
76
+ (coll? v)
77
+ (with-open [os (java.security.DigestOutputStream. (java.io.OutputStream/nullOutputStream ) (.md jdb))]
78
+ (with-open [writer (java.io.OutputStreamWriter. os)]
79
+ (binding [*out* writer]
80
+ (pr v))))
81
+
82
+ :else
83
+ (.update (.md jdb) (.getBytes (str v) " UTF-8" )))
84
+ ; ; finish hash
85
+ (.digest (.md jdb)))))
65
86
66
87
(defn ^Slot primitive-for
67
88
" Converts a Clojure primitive value to its corresponding XitDB representation.
You can’t perform that action at this time.
0 commit comments