ArangoDB Java Driver:在事务中放置多个参数

时间:2016-12-20 09:46:29

标签: java arangodb

我需要在ArangoDB驱动的JAVA中为事务中放置多个参数;

它适用于单个参数:

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);
}

但是如果我需要传递多个参数,那么我就被卡住了。试图传递地图,arraylist或数组,但它似乎不起作用:

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 个答案:

答案 0 :(得分:2)

不再需要您的解决方法。 TransactionOptions中缺少自动序列化map / list / array是java驱动程序中的一个错误,该错误已在4.1.5版本中修复

答案 1 :(得分:0)

必须序列化地图:

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