Fork me on GitHub
#xtdb
<
2020-08-25
>
tolitius23:08:57

is there a recommended Java API approach or documentation about it? I see there is https://github.com/juxt/crux/issues/360 done, but not sure where to find the docs for it. for example: a https://crux-doc.s3.eu-west-2.amazonaws.com/crux-javadoc/20.08-1.10.1/crux/api/ICruxIngestAPI.html#submitTx(java.util.List) takes a list of lists, and it comes down to a https://github.com/juxt/crux/blob/88771f6ab32363a2bf5d54aff6a55924b8887d2c/crux-core/src/crux/tx/conform.clj#L9-L12 function that verifies that each doc in that list is a map however there is also a https://github.com/juxt/crux/blob/b050da6dc412229388869495866aae927dc63f95/crux-core/src/crux/api/alpha/PutOperation.java that conveniently adds keyword("crux.tx/put") and friends, but it is constructed from the https://github.com/juxt/crux/blob/b050da6dc412229388869495866aae927dc63f95/crux-core/src/crux/api/alpha/Document.java and not a map, so they don’t seem to fit the List of Maps expectation of submitTx but.. then it looks like https://github.com/juxt/crux/blob/2b9eeda227820863caca9a74a93a7f6732f8d13d/crux-test/test/crux/java_api_test.clj#L44 in tests.. ))

Nejc08:08:46

I was pointed to this page when I asked for Java examples: https://github.com/juxt/crux/discussions/1012

3
Nejc08:08:57

The idea here is, that you write plain crux statement as a string: e.g.:

String put = "[:crux.tx/put\n" +
            "{:crux.db/id :someId\n" +
            ":foo      \"foo\"\n" +
            ":bar  \"bar\"\n" +
            "}]";
And read it through Clojure read api:
Object datafied = Clojure.read(put);
The output of this function can be passed down the Crux API:
node.submitTx((List<List<?>>) datafied)

tolitius13:08:25

it’s not exactly that simple with real Java nested object ) also hard to compose Java and Clojure functions. I added something to yang that was useful: https://github.com/tolitius/yang#java to get this done, but I have not used ICruxIngestAPI.submitTx I just handrolled some of these:

static IFn submitTx() {
        require.invoke(Clojure.read("crux.api"));
        return Clojure.var("crux.api", "submit-tx");
    }

    static IPersistentVector toTx(Object event) {
        return (PersistentVector) vector.invoke(TX_PUT, event);
    }

refset13:08:24

Hi @U0541KMAZ sorry for the late response. Unfortunately we should have removed / deprecated the /api/alpha code already as it is not going to be supported. We will be working on another Java-friendly implementation soon however

tolitius13:08:42

ah, makes sense, cause it did not seem “together” ) no worries, it’s the same (J)VM anyway

😅 3