简体   繁体   English

如何从Java将参数的Map类型传递给OrientDB Groovy函数

[英]How to pass Map type of parameter to orientdb groovy function from Java

I am trying to pass Map as a input to my orientdb groovy function. 我试图将Map作为输入传递给orientdb groovy函数。 But Groovy function is considering my Map input parameter as String. 但是Groovy函数正在考虑将我的Map输入参数视为String。

Please suggest how to pass Map type of input parameter to orientdb groovy function. 请建议如何将输入参数的Map类型传递给orientdb groovy函数。

code

public void MapInputTest() {
     Map < String, Object > inputMap = new HashMap < String, Object > ();
     inputMap.put("serviceId", "ETHA12721205");
     inputMap.put("serviceId1", "ETHA127212051");
     inputMap.put("serviceId2", "ETHA127212052");

     g.execute(Script.function("MapInputFunction", inputMap));
     System.out.println("returnedString is : ");
}

groovy function: 常规功能:

def MapInputFunction(Map mapInput) {
    println("class type of input parameter" + mapInput.getClass())
    println("class type " + mapInput)
    def tempMap = [: ]
    tempMap = mapInput
    return tempMap.get('serviceId')
}

error 错误

com.orientechnologies.orient.core.exception.OCommandExecutionException: Failed to execute command: function.MapInputFunction Cause:No signature of method: Script1.MapInputFunction() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String) values: [ETHA127212051, ETHA12721205, ETHA127212052]
    Possible solutions: MapInputFunction2(), MapInputFunction(java.lang.Object)
        at platform.orientdb.storage.DataGridStorage.executeCommand(DataGridStorage.java:631)
        at platform.orientdb.storage.DataGridStorage.command(DataGridStorage.java:601)
        at platform.orientdb.storage.message.CommandMessage.processMessage(CommandMessage.java:27)
        at platform.orientdb.storage.message.TxMessage.process(TxMessage.java:52)
        at platform.orientdb.storage.actor.TransactionActor.processMessage(TransactionActor.java:71)
        at platform.orientdb.storage.actor.ExternalStorageActor.onReceive(ExternalStorageActor.java:16)
        at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:165)
        at akka.actor.Actor$class.aroundReceive(Actor.scala:484)
        at akka.actor.UntypedActor.aroundReceive(UntypedActor.scala:95)
        at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
        at akka.actor.ActorCell.invoke(ActorCell.scala:495)
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)
        at akka.dispatch.Mailbox.run(Mailbox.scala:224)
        at akka.dispatch.Mailbox.exec(Mailbox.scala:234)
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)*emphasized text*
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

In the script, let's say the name of the parameter is inputMap 在脚本中,假设参数的名称为inputMap

then send the below 然后发送以下

 Map < String, Object > parameters= new HashMap < String, Object > ();
     parameters.put("serviceId", "ETHA12721205");
     parameters.put("serviceId1", "ETHA127212051");

 Map < String, Object > inputMap = new HashMap < String, Object > ();
inputMap.put("inputMap",inputMap)

     g.execute(Script.function("MapInputFunction", inputMap));
     System.out.println("returnedString is : ");

The script will able to read the inputMap as Map data-structure 该脚本将能够读取inputMap作为Map数据结构

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM