EnsLib.RecordMap.Service.FileService row?
When using a EnsLib.RecordMap.Service.FileService business service, is there a way to tell which row number that is being read in? I want to read in a csv, but on the first record, trigger a truncate on the External SQL Table that it is being written to through JDBC.
Thanks
Scott
Comments
One way to do that would be to use EnsLib.RecordMap.Service.BatchFileService and configure it with BatchHandling = Whole Batch.
If you do that your Business Process will receive a Batch object that serves as parent to the individual Records in the file. You can do the truncate, then loop over the records and process each one.
Since the first line contains the column headers, I am using that to key off of.
If you're using a custom business process to handle the message, you could perform the truncate in an OnRequest() callback.
If you're using a BPL, you would add an action near the beginning of the process to perform the truncate. The request object will be a single batch object containing a collection of records; the next step would be to iterate over the collection and perform the inserts.
You could do essentially the same thing in a DTL; use an SQL rule at the beginning to truncate, then add a foreach to iterate over the batch and populate the DB.
The key is the fact that your BP is getting all of the records in a single object. So when that object arrives, it's time to truncate the table and repopulate it. You will have to skip the first record if it contains headers, of course.