WebSphere Application Server & Liberty

Jakarta Batch Post 146: Extras – Using JPA Readers and Writers

By David Follis posted Thu July 15, 2021 07:57 AM

  
This post is part of a series delving into the details of the JSR-352 (Java Batch) specification. Each post examines a very specific part of the specification and looks at how it works and how you might use it in a real batch application.

To start at the beginning, follow the link to the first post.

The next post in the series is here.

This series is also available as a podcast on iTunesGoogle PlayStitcher, or use the link to the RSS feed
-----

Both JBeret and BatchEE provide JPA based readers and writers.  JPA is essentially a layer built on top of JDBC that provides an abstraction between the application code and the code that interacts with the database itself.

This layer of abstraction allows the application to be less concerned about the specific database implementation provided.  Anybody that has dealt with several different database products over the years knows that while SQL is a standard, there is a lot of gray in how it is implemented.  Things that work just fine with one database will require some tweaking to work with another.  Which means you can’t just switch your underlying database without having to change the application (or write some complicated application code to handle the differences).

JPA abstracts that away.  It worries about the specific syntax differences and lets you just write your application code.  Now it is certainly unlikely that one day your management will tell you they are moving all their production databases from one vendor to another, so you probably won’t have to go change all your production batch applications overnight.  But you might want to write applications that work for different parts of your company that might use different database products and not have multiple versions.  Or maybe you want to write applications used by different companies.

Additionally, JPA just makes it easier to deal with an underlying database.  You worry less about the details and focus on the application things you need to do. 

The readers and writers provided by JBeret and BatchEE don’t just magically work for you (nothing every just magically works :-).  But they provide the basics into which you can insert the JPA application stuff that you have to write.  You give it the name of the named query you need to run, and it handles actually doing that and pulling out the result set. 

Like a lot of the readers and writers we’ve looked at, these, at the very least, provide some sample code to build your own application on top if, even if you can’t just use it as-is. 

0 comments
44 views

Permalink