Saturday, 26 October 2013

Struts 1.3 with COBOL Stored Procedure Implementation with searching, Pagination, Export to Excel and Multilingual

     Struts 1.3 with COBOL Stored Procedure Implementation  


Struts 1.3 is the MVC framework to reduce the work of the developers to develop the web application.


ActionForm : Forms in Struts 1 framework are the java bean classes that extends ActionForm class.

Model : Model classes holds the state of the internal and external system.

View : Views are web components that are shown to the web browser users. In Struts 1, it can be jsp page or any view render technique such as Tiles.

Controller : Controllers are the components that handles are the requests that comes from users and decides which view is to send back to the use as response. In Struts 1 the controller part is handled by ActionServlet class and a subclass of Action class that is developer defined. The controller may interact with the application specific business logic or some code that persists data in database or with an EJB.

Flow of Struts 1.2 


1. When first time user request comes from the browser, ActionServlet invoked which reads struts-config.xml configuration file and creates configuration objects. struts-config.xml contains information about the FormBeans, that are subclasses of ActionForm, Actions and view that can be send as response to the browser.
2. In the second step ActionServlet instantiate the specified form bean and puts the value of the form attributes, submitted by the browser, to form bean.
3. Then ActionServlet calls the Action class’s execute method, which returns ActionForward instance. ActionForward instance contains the detail of the view to be return as response.
4. ActionServlet renders the view and return to the browser as response.

Flow of Struts 1.3
1. When first time user request comes from the browser, ActionServlet invoked which reads struts-config.xml configuration file and creates configuration objects. struts-config.xml contains information about the FormBeans, that are subclasses of ActionForm.
2. In the second step ActionServlet instantiate the specified form bean and puts the value of the form attributes, submitted by the browser, to form bean.
3. Then FormBean calls the Delegate class and delegate class call’s DAO class which return as response.
4. ActionServlet renders the view and return to the browser as response.
We will perform following changes to the application to make it work with LookupDispatchAction.
Our action class  will extend LoopupDispatchAction instead of DispatchAction.
Add a application properties file that will contain the detail of the method to be executed when a particular value will come from the request parameter which is defined in attribute parameter in action tag.
Some basic changes to jsp for making the ui more perfect.
       
Stored Procedure

A stored procedure is a subroutine available to the applications that access relational database systems. Stored procedure used for data validation and access mechanism.
Stored procedure mainly used for centralize the logic that is originally implemented in applications.

Extensive and complex processing that requires execution of several sql statements is moved into stored procedure and all the application will call the stored procedure.

Procedure Wrapper :

Wrapper class is used to execute stored procedure  doesn't have exactly one out parameter.
The default number of output parameters is one.

The database connection is acquired using ConnectionFactory. Default connection factory is used for connecting to the database.

public class ProceedureWrapper{
     
 private static ConnectionFactory defaultConnectionFactory = new  SRSConnectionFactory(); private ConnectionFactory connectionFactory=defaultConnectionFactory;

private String name;
private ProceedureCommand command;
private int outputParameterCount=1;    

// For one portion key

public ProceedureResult execute(Caller sourceUser, String key, String inParameter,List errorsList, ResultSetConsumer resultSetConsumer) throws Exception{

      return execute(sourceUser,true,key,inParameter,errorsList,resultSetConsumer); 
  } 

// Not contain any one portion key

public ProceedureResult execute(Caller sourceUser, String inParameter,List errorsList, ResultSetConsumer resultSetConsumer) throws Exception{

      return execute(sourceUser,false,null,inParameter,errorsList,resultSetConsumer); 
  } 
       
}

FormBean :

   Formbean class will contain the getter and setter code for input data. Formbean is used to call the handler class. We need to instantiate handler class in the Formbean class.

public class SearchReasonCodesForm  extends SRSForm{

     public static final String CLASS_NAME=SearchReasonCodesForm.class.getName();  
     
      SearchReasonCodesHandler handler=new  SearchReasonCodesHandler(); 

      public void populateSearchReasonCodes(){

                 handler.populateSearchReasonCodes();
           }

Action Class :

     Action class is used for the navigation of the request. Action class will not contain any business logic. We will use addNavigationMethods for navigation in the action class.

  public class SearchReasonCodesAction extends Action{

     protected void addNavigationMethods(){
       }

Inquiry Object :

  All the input data is used to capture in the getter and setter methods of the inquiry object.

   public class inquiry implements Serializable{

         }

PartsConstant :

  We need to create constant value class for the field parameters. These parameters are passed to the COBOL store procedure as input parameter in the DAO class.

public class PartsConstant{

       private PartsConstant(){}
       public static final String PLANT_CODE="plantCode";
    }

PartsFieldConstant :

   We need to create field parameter class which describes the length of the field input parameters we are passing to the COBOL store procedure for processing.

The field constant will pass to the DAO class as input parameter along with the constant field.

public class PartsFieldConstant{

              public static final int PLANT_CODE_LENGTH=5;     

         }

          
PartsBO :

   Business object class will call the DAO class.

public class PartsBO{

    public List populateSearchReasonCodes(){

                 PartsDAO.populateSearchReasonCodes();
           }
  }

PartsDAO :

   PartsDAO class will invoke the store procedure using inquiry,parts constant and partsfields constant.

 We are populating errors from the COBOL store procedure  using the ArrayList.

public class PartsDAO{

          public List<PartsBO> populateSearchReasonCodes(){

                 final String METHOD_NAME="populateSerachReasonCodes";
                 List<PartsBO> parts=null;
                 ProceedureWrapper wrapper=new ProceedureWrapper(PROCEEDURE_NAME,                          ProceedureCommand.Inquiry);
                 ProceedureResult result=wrapper.execute(inqury.getCaller(),ALL_PARTS.getString(inquiry), new ArrayList(),  new GenericResultSetConsumer(new PartRecordFactory()));

                 parts=result.getResults();
                 return parts;
                 
           

Struts-Config.xml

   We need to configure the form bean class in the struts configuration file.

   <form-bean name="searchReasonCodesForm"  type="com.satya.form.searchReasonCodesForm"/>

JSP Page :

  We can populate data in the JSP page using struts logic tag.

<logic:iterate id="result" name="searchReasonCodesForm" scope="session">
     <tr>
          <td>
                    <bean:write name="result" property="description"/>
             </td>
       </tr>
</logic:iterate>


    

    

   

   


No comments:

Post a Comment

Spring 3 Rest Web Service Batch Update with JQuery & Ajax Integration

                      Spring 3  Rest Web Service Batch Update with JQuery & Ajax Integration Hi     In this blog I will describe the...