I'm looking for a way to use parameters in a JPA query to set a value in the database after retrieving and processing some data.
Using the fluent builder I'm looking for a way to get the id of a record that was fetched, so a flag can be set in de database.
public void configure() throws Exception {
Map<String, Object> params = new HashMap<>();
from("timer:number?period=1s")
.routeId("ccmd-route")
.to("jpa:com.example.Person?namedQuery=getNonFetched")
.split(body())
.process(exchange -> log.info(exchange.getMessage().getBody().toString() + "exchange id: " + exchange.getExchangeId()))
.process(exchange -> params.put("id", exchange.getMessage().getBody(Person.class).getId()))
.to(String.format("jpa:%1$s" +
"?namedQuery=setIsFetched" +
"¶meters=#params", Person.class));
}
So far I have been able to set the id value in a Map, but I think it needs to be added to the registry in order to be used in #params
Therefore I figured to just add the Map to the registry:
...
Map<String, Object> params = new HashMap<>();
CamelContext context = getContext();
Registry registry = context.getRegistry();
registry.put("params", params);
from("timer:number?period=1s")
...
But that gives an error Cannot resolve method put()
.
I got this from an example on Github, but there they use the SimpleRegistry
Is there a "fluent" way to tackle this?