Hi Claus.
Thanks for helping me out. I still don't get it, to be honest. This is my
code:
public class AffaldVarme extends RouteBuilder {
int latestID=1;
String resourceID="some_id";
@Override
public void configure() throws Exception {
from("timer://foo?period=1m")
.routeId("containervejning")
.setHeader("low",constant(latestID-1))
.setHeader("high",constant(latestID+3000))
.to("sql:select * from some_table where Container_Vejning_ID
> :#low and Container_Vejning_ID < :#high order by Container_Vejning_ID
ASC?dataSourceRef=affaldVarme")
//.setBody(constant("select * from some_table where Container_Vejning_ID
>"+(latestID-1)+" and Container_Vejning_ID <"+(latestID+3000)+" order by
Container_Vejning_ID ASC"))
.to("jdbc:affaldVarme")
.process(
new Processor() {
public void process(Exchange exchange) throws
Exception {
JSONArray ja=new JSONArray();
List<Map<String, Object>> data =
exchange.getIn().getBody(List.class);
for(Map<String, Object> row : data){
JSONObject jo=new JSONObject();
for(Map.Entry<String, Object> entry
:row.entrySet()){
jo.put(entry.getKey(),
entry.getValue());
}
ja.put(jo);
}
if(ja.length()>0){
JSONObject
j=(JSONObject)ja.get(ja.length()-1);
latestID=(Integer)j.get("Container_Vejning_ID");
}
exchange.getIn().setBody("{\"resource_id\":\""+resourceID+"\",\"fields\":["
+
"{\"id\":\"Container_Vejning_ID\",\"type\":\"int\"},"
+
"{\"id\":\"Indlaes_Vejning_ID\",\"type\":\"int\"},"
+ "{\"id\":\"Dato\",\"type\":\"text\"},"
+ "{\"id\":\"Tid\",\"type\":\"text\"},"
+
"{\"id\":\"Vejning\",\"type\":\"float\"},"
+
"{\"id\":\"Opd_Init\",\"type\":\"text\"},"
+
"{\"id\":\"Opd_Dato\",\"type\":\"text\"},"
+
"{\"id\":\"GPSLongitude_2\",\"type\":\"float\"},"
+
"{\"id\":\"GPSLatitude_2\",\"type\":\"float\"},"
+
"{\"id\":\"Container_Vejning_Faktura_Opstil_id\",\"type\":\"int\"},"
+
"{\"id\":\"FrivaegtKg\",\"type\":\"text\"}"
+ "] ,\"records\": " + ja.toString() +
"}");
}
}).setHeader("CamelHttpMethod", constant("POST"))
.setHeader("Authorization", constant("some_value"))
.to("http4://some_url");
}
}
As you can see, I have these two versions of calling the database:
.setHeader("low",constant(latestID-1))
.setHeader("high",constant(latestID+3000))
.to("sql:select * from some_table where Container_Vejning_ID > :#low and
Container_Vejning_ID < :#high order by Container_Vejning_ID
ASC?dataSourceRef=affaldVarme")
.setBody(constant("select * from some_table where Container_Vejning_ID
>"+(latestID-1)+" and Container_Vejning_ID <"+(latestID+3000)+" order by
Container_Vejning_ID ASC"))
.to("jdbc:affaldVarme")
Neither of these works (well... I can make the route active and run without
errors, but "latestID" will not increment past 3000), and to be hones, even
with the link you just posted, I can't make sense of it. As far as I can
see, I am using a different language, than constant, in my first example.
The thing is that both ways of doing the calls yields the same result.
Any suggestion?
Regards
Lasse Vestergaard
--
View this message in context:
http://camel.465427.n5.nabble.com/Change-timer-runtime-tp5738484p5738610.html
Sent from the Camel - Users mailing list archive at Nabble.com.