When I first started using Camel, I expected something like this to automatically batch SQL update statements:
.aggregate(constant("all"), new StringCollector())
.completionSize(20) // batch size = 20
.to("sql:insert into foo values (#)?dataSourceRef=ds")
I was surprised when this wasn't the case, because in general batching SQL update statements is much more efficient than executing them individually, and is best practice when there is a lot of data involved.
The attached patch adds a "batch" attribute to the SQL component (default value is false), which should only be set to true for SQL update statements (insert, update, delete). If the "batch" attribute is true, then the interpretation of the inbound message body changes slightly – instead of an Iterator of parameters, the component expects an Iterator that contains the parameter Iterators; the size of the outer Iterator determines the batch size.