Saturday, September 27, 2014

Batch Design pattern

public abstract class BaseToService extends ThatBatchExecutes
{
    public BaseToService()
    {
    }
    public int doExecute(String args[])
    {
        initialize(args);
        try
        {
           // result = execute(args);
        }
        catch(Exception e)
        {
        }
    }

    private void initialize(String args[])
    {
        jobId = args[1].trim();
        RequestObject Ctx = (RequestObject)BatchTool.getBean("RequestObject");
        DateTool datetool = (DateTool)BatchTool.getBean("DateTool");
        Ctx.setDat(datetool.getDatBigDecimal());
        Ctx.setTim(datetool.getTimBigDecimal());
        Ctx.setPgm(jobId);
    }
    public abstract int execute(String as[]);
   //logger  
    private String jobId;

}


public class ThatBatchExecutes
{
    public ThatBatchExecutes()
    {
      //logger
    }
    public static void main(String args[])
    {
        ThatBatchExecutes executor = new ThatBatchExecutes();
        executor.executeService(args);
    }
    public void executeService(String args[])
    {
        if(!checkArgs(args)){
            System.exit(-1);
            //logger
        }
       //logger
        executeBatchService(args);
    }
    protected boolean checkArgs(String args[])
    {
        // if checked  of arguments passed{
     
        jobId = args[1].trim();
        try
        {
            service = (BaseToService)Utils.getBean(jobId);
        }
        catch(Exception e)
        {
        }
     
    }

    // protected int executeBatchService(String args[])
    {
        try
        {
            service.doExecute(args);
        }
        catch(Exception e)
        {
           
        }
    }

   
      //logger
    protected BaseToService service;
    protected String jobId;
}


No comments:

Post a Comment