WebSphere Application Server & Liberty

 View Only

Jakarta Batch Post 114: Batch Properties Object (Issue 133)

By David Follis posted Wed October 28, 2020 08:07 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 can be found here.

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

This issue can be found here.

The current behavior allows you to specify a batch property in the JSL and have that value injected into a batch artifact like a Batchlet.  Batch properties are all strings.  When you inject a property you give it a name and a value.  To get the value injected into the Java code you need to know the name given to it in the JSL.

For example, in the JSL you might have this:


   <property name=”outputType” value=”PDF” />


And in the Java code you would have this:

@BatchProperty(name = "outputType")
String inputDir;

That makes the JSL and the Java code pretty tightly wound together.  It would be nice if the Java code could just pick up a Properties object that had whatever properties were specified in the JSL and then extract the keys to find out what properties were specified and react accordingly. 

It would also let you group a set of related batch properties together.  That would help if, for example, your reader was reading from two different data sources.  You could have two groups of properties, one for each source, that would be injected into two Properties objects, keeping them together without requiring some naming convention or something.

The JSL might look like this:

<properties-object name=”Prop1”>
<property name=”outputType” value=”PDF”/>
<properties-object name=”Prop2”>
<property name=”outputType” value=”PDF”/>

And then in the Java code you could have something like this:

Properties prop1;

Properties prop2;

Of course that’s just a proposal and it might have to change to actually work.