0

I need to put multiple parameters in transaction in JAVA drived for ArangoDB;

It works with single parameter:

public String save(User user) throws ArangoDBException {

    TransactionOptions options = new TransactionOptions().params(user).writeCollections(collectionName);
    String action = "function (params) { "
            + "var db = require('internal').db; "
            + "var doc = params;"
            + "db.users.save(doc);"
            + "}";

    return db.transaction(action, String.class, options);
}

But if I need to pass multiple parameters, then I'm stuck. Tried to pass map, arraylist or array, but it doesn't seem to work:

public void save(User user, User user2) throws ArangoDBException {
    Map<String, Object> parameters = new MapBuilder()
            .put("user", user)
            .put("user2" user2)
            .get();


    TransactionOptions options = new TransactionOptions().params(parameters).writeCollections(collectionName);
    String action = "function (params) { "
            + "var db = require('internal').db; "
            + "var doc = params['user'];"
            + "var doc2 = params['user2'];"
            + "db.users.save(doc);"
            + "db.users.save(doc2);"
            + "}";

    db.transaction(action, String.class, options);
}

2 Answers 2

2

The need of your workaround is not necessary any more. The missing automatic serialization of map/list/array within TransactionOptions was a bug in the java-driver which is fixed with version 4.1.5

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

Comments

0

Had to serialize the map:

TransactionOptions().params(db.util().serialize(params)).writeCollections(collectionName, "users2");

Comments

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.