Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Pass File name to spring bath job from servlet on demand basis

  1. #11
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    looks like the exception comes from your own code (SeparatorCompositeItemWriter class). What are you doing in this class? Don't forget you can't manipulate the delegates with their class names, as they're step-scoped proxies (i.e. don't cast the delegates as FileFileItemWriter).

  2. #12

    Default

    Quote Originally Posted by arno View Post
    looks like the exception comes from your own code (SeparatorCompositeItemWriter class). What are you doing in this class? Don't forget you can't manipulate the delegates with their class names, as they're step-scoped proxies (i.e. don't cast the delegates as FileFileItemWriter).
    Hi arno,

    I am doing separation of the files based on careerLength condition.
    Code:
    @SuppressWarnings("unchecked")
    public class SeparatorCompositeItemWriter implements ItemWriter 
    {
     
    private List delegates;
     
    public void setDelegates(ItemWriter[] delegates) {
    this.delegates = Arrays.asList(delegates);
    }
     
    public void write(List items) throws Exception 
    {
    FlatFileItemWriter write1 = (FlatFileItemWriter)delegates.get(0);
    FlatFileItemWriter write2 = (FlatFileItemWriter)delegates.get(1);
     
    List file1Items = new ArrayList<Player>();
    List file2Items = new ArrayList<Player>();
     
    for(Object player: items)
    {
    Player pl = (Player)player;
    if(pl.getCareerLength()< 25 ) file1Items.add(player);
    else file2Items.add(player);
    }
     
    write1.write(file1Items);
    write2.write(file2Items);
    }
    }
    actaully this file going smoothly before the multiple fine name change. But now its showing error ? what is wrong in this file? Can you please help on this.

  3. #13
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    ok, so you're doing exactly what I mentioned in my previous post:
    Code:
    FlatFileItemWriter write1 = (FlatFileItemWriter)delegates.get(0);
    FlatFileItemWriter write2 = (FlatFileItemWriter)delegates.get(1);
    First, it can't work because the delegates are proxies (they're step-scoped). Second, you don't need to do that. Do it this way:
    Code:
    ItemWriter write1 = (ItemWriter)delegates.get(0);
    ItemWriter write2 = (ItemWriter)delegates.get(1);
    so try to make it work and then we'll see how to use generics.

  4. #14

    Default

    Hi Arno,

    Greatful thanks to you arno.
    So nice of you!. Your ideas help's me a lot.

    Actually, while processing a input csv file, - for each record/row in the csv file - can we validate it against a DB table, before pushing it to DB.

    Regards,
    Rams

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •