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!

2
  • 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. Commented Aug 24, 2017 at 1: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. Commented Aug 24, 2017 at 9:14

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

3 Comments

@user989266 your should accept his answer if it does the job.
Apologies, this is the first stackoverflow question I've posted. I assumed I just needed to upvote it.
Oh, it was that greyed-out tick? What a crappy interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.