package camelinaction;

import javax.sql.DataSource;

import org.apache.camel.Consume;
import org.springframework.jdbc.core.JdbcTemplate;

public class InventoryUpdater {

    private JdbcTemplate jdbc;

    public InventoryUpdater(DataSource ds) {
        jdbc = new JdbcTemplate(ds);
    }
    
    @Consume(uri = "jms:partnerInventoryUpdate")
    public void updateInventory(Inventory inventory) {
        jdbc.execute(toSql(inventory));
    }    
    
    private String toSql(Inventory inventory) {
        Object[] args = new Object[] {inventory.getSupplierId(), inventory.getPartId(), inventory.getName(), inventory.getAmount()};
        return String.format("insert into partner_inventory (supplier_id, part_id, name, amount) values ('%s', '%s', '%s', '%s')", args);
    }
}

@@ -535,16 +535,29 @@
 ject%5B%5D %7B
+%0A            
 inventor
@@ -594,24 +594,37 @@
 etPartId(), 
+%0A            
 inventory.ge
@@ -716,16 +716,34 @@
 ventory 
+%22 + %0A            %22
 (supplie
@@ -778,16 +778,34 @@
  values 
+%22 + %0A            %22
 ('%25s', '

reformat to fit book page width