Hi guys,

I am looking for some general guidance on how I should structure my JPA
endpoint route. i.e. what would be a standard approach to my issue.

My camel route parses an XML document containing many items then inserts the
items into a db using a JPA enpoint. The way I did this was to structure the
route something like this....

        from("file:src/data?fileName=FIT32.XML&noop=true")      
            .convertBodyTo(
                        ItemDocument.class)             
            .split().method(
                        ItemDocumentService.class,
                        "splitItemDocument")
                        .to("jpa:org.apache.camel.auski.etl.entity.ItemEntity");

ItemDocumentService > splitItemDocument...

        public List<Item> splitItemDocument(ItemDocument doc) {
                List<Item> items = new ArrayList<Item>();
                List<Items> itemDocumentsList = doc.getItems();
                for (Items itemDocuments : itemDocumentsList) {
                      items.addAll(itemDocuments.getItems());
                 }
                return items;
    }

And then my Type Converter would run through each individual item returned
by the split and return an ItemEntity. JPA would then take care of the rest
and insert into the item table.

Now I have decided to change the structure of my db and have a table which
records batch import runs. For example the batch table would have...

id,LoadDateTime,Filename
1,10:50am,items_20131116.xml

And the item table would have...
id,item_price,item_code,import_id
9,$5,99999,1

To achieve try and achieve this I've restructured my route to look like...

        from("file:src/data?fileName=FIT32.XML&noop=true")  
                        .process(new Processor() {
                            public void process(Exchange exchange) throws 
Exception {                           
                                String filename = (String)
exchange.getIn().getHeader("CamelFileName");
                                String body = 
exchange.getIn().getBody(String.class);

                                ImportPayloadEntity importPayloadEntity = new
ImportPayloadEntity();
                                importPayloadEntity.setFilename(filename);
                                importPayloadEntity.setLoadDateTime(new Date());
                                
exchange.getIn().setHeader("importPayloadEntity",
importPayloadEntity);
                            }
                        })    
            .convertBodyTo(
                        ItemDocument.class)             
            .split().method(
                        ItemDocumentService.class,
                        "splitItemDocument")
                        
.to("jpa:org.apache.camel.auski.etl.entity.ImportPayloadEntity");
    }

So what I have done is to add a new object inside the header which I can
access in my TypeConverter. And my TypeConverter definitely gets the new
header object. 

Now here comes the question....

How do I best persist the ImportPayloadEntity and the items from here. If I
keep the route as per what I have changed it to, in my type converter I
would need to loop through all the items that JaxB has parsed (could be as
many as 200) and then associate them to the batch table entity
(ImportPayloadEntity). I can't help thinking this is a bad thing to do...

Or perhaps there is a better way to persist the items and the batch record.
Could I please get your thoughts?

I hope I have explained the problem well. Please let me know if more info is
required.

thanks


So what that would mean is that if my xml document has 120 individual items
in it the type converter would have tun
 



--
View this message in context: 
http://camel.465427.n5.nabble.com/Ideas-on-how-to-structure-JPA-endpoint-application-tp5743372.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to