1

I'm trying to use lmdbjava in Clojure, but I'm struggling.

(import '[org.lmdbjava Env])
(def path (clojure.java.io/file "/tmp"))
(.open (.setMaxDbs (.setMapSize (Env/create) 10485760) 1) path)

(p.s. I realise there are cleaner ways. This is just for testing purposes.)

This is the error:

IllegalArgumentException No matching method found: open for class java.lang.Class  clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:53)

I've also tried this:

(.open (.setMaxDbs (.setMapSize (Env/create) 10485760) 1) path org.lmdbjava.EnvFlags/MDB_NOLOCK)

and this:

(.. (Env/create) (setMapSize 10485760) (setMaxDbs 1) (open path org.lmdbjava.EnvFlags/MDB_NOLOCK))

And I get this error:

ClassCastException org.lmdbjava.EnvFlags (in module: Unnamed Module) cannot be cast to [Lorg.lmdbjava.EnvFlags; (in module: Unnamed Module)  user/eval1339 (form-init2868059116743223586.clj:1)

I realise I'm probably doing something daft, because I'm new to both Java and Clojure. Any help would be greatly appreciated!

By the way, this is the tutorial I'm following:

https://github.com/lmdbjava/lmdbjava/blob/master/src/test/java/org/lmdbjava/TutorialTest.java

Thanks!

user989266
  • 91
  • 1
  • 6
  • Can you start from the beginning, so see if there's a problem with `(Env/create)`? Also does `.setMapSize` return an object? From your code it would have to. Do things one at a time with intermediate *variables*, and use `_ (println intermediate-var)`. Also `(type intermediate-var)` for each step would be handy. – Chris Murphy Aug 24 '17 at 01:53
  • Thanks Chris. I did try breaking it up into intermediate steps when debugging. It was the .open part that was causing me problems. I also originally used 'doto', but rewrote it this way to try and make sure that it matched the tutorial as much as it possible. I used 'type' and also tried to do inspection when I was debugging this. – user989266 Aug 24 '17 at 09:14

1 Answers1

3

From the signature of the Env.Builder class:

Env<T>  open(File path, int mode, EnvFlags... flags)

you also have to supply a EnvFlags varargs parameter. This is how you do it in Clojure:

(.open (.setMaxDbs (.setMapSize (Env/create) 10485760) 1) path (into-array org.lmdbjava.EnvFlags []))

Also see How to handle java variable length arguments in clojure?

Jürgen Hötzel
  • 18,997
  • 3
  • 42
  • 58