aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Java Batch Program Design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Java Batch Program Design" Watch "Java Batch Program Design" New topic
Author

Java Batch Program Design

Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

Hello Everyone!

I have to work on the Java Design of a simple application which extracts data from database and create CSV file. Is there any industry standard Java Design Patterns used for a batch application?

Currently, I use Singleton and DataAccessObject patterns for Business classes and Data Access classes respectively. Though it seems quite simple, I thought of posing this question before workin on.

Can anyone shed some light on this?

Thanks in anticipation.

Cheers,
Naren


Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Personally, I would not bother with a Singleton. The point of a batch application is that it starts at the beginning, runs until the work is done, and then stops.

The database connection needs to be set up at the start, so why not just set it up at the start.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Gabriel Claramunt
Ranch Hand

Joined: May 26, 2007
Posts: 375

Martin Fowler's Patterns of Enterprise Application Architecture (P of EAA) has some patterns that can be useful. Maybe you can get some inspiration.
Although if is a stand alone process and you don't need to do any special processing or validation, keep it as simple as possible: for each row put whatever comes from the recordset into the cvs file. As much as I like OOAD, sometimes is not required, and patterns shouldn't be applied always...


Gabriel
Software Surgeon
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577

Thanks for your replies.

Though it's very easy to create a .CSV immediately after fetching data from database in DAO. I'd prefer to wrap this data in a Value Object and send it back, then the business class uses some other bean to really create the file. This way I feel I can keep Data Access Layer and Business Layer independent. I'm going to use Singleton Patterns for Business and Data Access classes. Please add something to make it more efficiet.

Regards,
Naren
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
I don't see why you want to use singletons.

And if you want efficiency, then the structure of the database or the SQL queries may have the greatest impact on efficiency.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Originally posted by Naren Chivukula:
Though it's very easy to create a .CSV immediately after fetching data from database in DAO. I'd prefer to wrap this data in a Value Object and send it back, then the business class uses some other bean to really create the file. This way I feel I can keep Data Access Layer and Business Layer independent. I'm going to use Singleton Patterns for Business and Data Access classes. Please add something to make it more efficiet.


Are you planning on re-using any of this code for anything else? If not, then all the effort of creating separate layers and stuff is not only a waste of time, it can also get in the way of seeing what the code is doing, which in turn makes any future maintenance harder rather than easier.

Here's an example of a simple batch program to read stuff from a database and write it to a CSV file. This happens to use my Stringtree DatabaseWrapper class, but even using "raw" JDBC it's not a tricky problem.



The bottom line is don't make things more complicated than they need be.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Frank Carver:
The bottom line is don't make things more complicated than they need be.


Agreed.

If anything "copying to a csv file" reminds of the "OO Copy Program" in Robert C. Martin's The Dependency Inversion Principle.

However the additional work of abstracting a reader and writer is only worthwhile if you already know that in addition to a "CsvWriter", you also need an "XmlWriter", "HtmlWriter" etc. The other consideration is that the Reader/Writer setup may be easier to test.

Otherwise "Your Aren't Gonna Need it" (YAGNI).
Don Morgan
Ranch Hand

Joined: Jul 24, 2003
Posts: 84
Sometimes things like this, particularly if they are very small, simple, and/or single use, are easier to do in a little shell script instead of a full blown java program.


Don Morgan, Founder
www.DeveloperAdvantage.com - FREE Audiobooks for Software Developers
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Originally posted by Don Morgan:
Sometimes things like this, particularly if they are very small, simple, and/or single use, are easier to do in a little shell script instead of a full blown java program.


I agree, but with small, potentially simple programs unfamiliarity with tools and libraries can have a disproportionate effect. Often going with a familiar language and development environment can work out quicker than trudging into unfamiliar territory.

For example, it would probably take me longer to work out how to get results from a database query into a shell script for processing than it did to knock together the Java example above. But that's because I do that sort of database access from Java pretty much every day.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Batch Program Design