lundi 9 novembre 2015

Design Pattern to handle following scenario

I am searching for a good design pattern for the following scenario,

I need to follow the below steps, after each step i need to update the status in DB. For that i made a separate class UpdateStatusDAO in that updateStatus(String status) will update the details in DB. The steps are,

1. Update Status as Processing Started
2. Read File
3. Update Status as Reading Completed
4. Process File 
5. Update Status as File Processing Completed
6. Rename File
7. Update Status as File Rename Completed
8. Update Status as Processing Completed


try{

    UpdateStatusDAO updateStatusDAO = new UpdateStatusDAO();

    updateStatusDAO.updateStatus("Process Started");

    // Read File
    try{

    } catch(Exception e){
    } finally{
    }

    updateStatusDAO.updateStatus("Reading Completed");

    // Process File
    try{

    } catch(Exception e){
    } finally{
    }

    updateStatusDAO.updateStatus("File Processing Completed");

    // Rename File
    try{

    } catch(Exception e){
    } finally{
    }

    updateStatusDAO.updateStatus("File Rename Completed");

    updateStatusDAO.updateStatus("Processing Completed");


} catch(Exception e){

} finally{

}

The thing is that, suppose due to some reason file Processing got failed. Then i need to update status as Reading Completed. Not File Processing Completed. I added as follows,

  1. If any Exception happens On ReadFile / Process File i will throw an exception then the further updation will not happens.

Is there any other better way to handle this scenario. ?

Aucun commentaire:

Enregistrer un commentaire