Java-based framework design.

Source: Internet
Author: User

We have done a lot of projects, and we usually need to solve some slightly complicated problems through a little design model. For example, reading a data file contains multiple rows of data. Some special situations may occur during the reading process. The requirement is that, if there are other situations, you need to write the data that has been read to the database, and the error location must be recorded in the system, the next read time goes down from this location. This record has an error location and is executed next time. These basic services may be processed in the framework, this does not need to be known to programmers who write business programs.

 

Design:

Maybe we only need to write an ibasebatchcontroller interface to provide some open interfaces. This may be the case for programmers.

Public interface ibasebatchcontroller {

 

Public int execute ();

 

}

The program outside is called through this method.

For example, ibasebatchcontroller cc = new aaabatchcontroller ():

Cc.exe cute ();

We need to solve the problem by adding a abstractbasecatchcontroller between the interface and the implementation class. The goal is to provide basic services in the middle.

Public void execute (string [] ARGs ){
Try {
Init (ARGs );
If (getsyntaxcheckfirst ()){
// File first before doing biz Processing
Boolean validationok = validatesyntax ();
If (validationok ){
Initfilehandler (ARGs );
Processsinglefile (ARGs );
} Else {
Updatetxinfo (ibatchstatusconstant. job_status_aborted );
}
} Else {
Processsinglefile (ARGs );
}
} Catch (exception e ){
Throw new ecustomsunchkexception (E );
}
}
 

Protected void processsinglefile (string ARGs []) {
Try
{
List errlist = NULL;
Errlist = parseheader ();
If (errlist! = NULL & errlist. Size ()! = 0)
{
Processerror (errlist );

If (isabortonheaderfail ()){
Throw new batchabortprocessingexception (header_fail_msg );
}
}

Int commitcount = 0;
Boolean notendofcontent = true;
Do
{
If (logger. isinfoenabled ()){
Logger.info ("Commit count:" + (commitcount + 1 ));
}

Try
{
Parsebatchcontent ();
}
Catch (ecustomschkexception E)
{
If (E. getmessage (). Equals (batch_eof )){
Notendofcontent = false;
}
Else {
Throw E;
}
}
Commitcount ++;
} While (notendofcontent &&! Fileabortindicator );

If (fileabortindicator ){
Throw new batchabortprocessingexception (record_fail_msg );
}

Errlist = parsetrailer ();
If (errlist! = NULL & errlist. Size ()! = 0)
{
Processerror (errlist );
If (isabortontrailerfail ()){
Throw new batchabortprocessingexception (trailer_fail_msg );
}
}
Updatetxinfo (ibatchstatusconstant. job_status_completed );
}
Catch (batchabortprocessingexception e ){
Updatetxinfo (ibatchstatusconstant. job_status_aborted, E. getmessage ());
Throw new ecustomsunchkexception (E );
}
Catch (exception E)
{
Updatetxinfo (ibatchstatusconstant. job_status_aborted );
Logger. Error (this, e );
Throw new ecustomsunchkexception (E );
}

 

 

Public abstract parsebatchcontent (); // used for implementation class. For example, you can decide what table the data is stored in.

 

Public list parseheader () throws ecustomschkexception, ioexception {
Debug ("parseheader ");
Results = readheader ();
List errorlist = NULL;
If (results! = NULL ){
Errorlist = results. geterrorlist ();
} Else {
Errorrecinfo errinfo = new errorrecinfo ();
Errinfo. seterrormessage ("invalid file, file has no content ");
Errorlist = new arraylist ();
Errorlist. Add (errinfo );
}
Return errorlist;
}
}

What needs to be done is to write the business logic for data processing in the parsecontent method and write the parsed data to the table.

 

Aside from the question, if we use spring to manage beans,

If you need to add some beans in abstractbasecatchcontroller by injecting them, define them in the aaabatchcontroller implementation class.

 

 

<Bean id = "invstatementmgr" parent = "txproxytemplate">
<Property name = "target">
<Bean
Class = "eCustoms. ics. App. Inventory. biz. inventorystatementmgr">
<Property name = "Dao"> ------------- is in abstractbatchcontroller.
<Ref local = "inventorystatementdao"/>
</Property>
<Property name = "syntaxcheckcmd"> ------------- is in abstractbatchcontroller.
<Ref bean = "inventorysyntaxcheckcmd"/>
</Property>
<Property name = "bizvalidationcmd">
<Ref local = "inventorybizvalidationcmd"/>
</Property>
<Property name = "uploaddao"> --------------- is in abstractbatchcontroller.
<Bean class = "eCustoms. ics. App. Upload. Dao. uploaddao"/>
</Property>
<Property name = "icationicationmgr" ref = "notificationmgr"/> ------------- is in abstractbatchcontroller.
<Property name = "referencedao">
<Bean class = "eCustoms. ics. App. Ref. Dao. referencedao"/> ------------- is defined in the Implementation class inventorystatementmgr.
</Property>
<Property name = "contactmgr" ref = "contactmgr"/>
<Property name = "usermgr" ref = "usermgr"/>
<Property name = "aamgr" ref = "aamanager"/>
</Bean>
</Property>
</Bean>

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.