0

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" +
            "&parameters=#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?

Johan Vergeer
  • 5,208
  • 10
  • 48
  • 105
  • I answered that here https://stackoverflow.com/questions/40503184/camel-how-to-add-something-to-registry-with-java-in-general/40506256. – Souciance Eqdam Rashti Jul 15 '18 at 20:56
  • @SoucianceEqdamRashti I was looking for a fluent way. I have created something in Kotlin that might help. I'll add this code snippet to the original answer. – Johan Vergeer Jul 16 '18 at 19:35

0 Answers0