+

Search Tips   |   Advanced Search

JPAReaderPattern

The JPAReaderPattern pattern is used to retrieve data from a database using OpenJPA.


Support classes

The JPAReader class performs the tasks of obtaining an entity manager, running user provided queries, and iterating over the results of the query. A persistence.xml file needs to be packaged with the user application.


Required properties

The following properties are required for the pattern.

properties. The table includes the name and value of
Property name Value
PATTERN_IMPL_CLASS Class implementing JPAReader Pattern interface
PERSISTENT_UNIT The OpenJPA persistent unit name.


Optional properties

The following properties are optional for the pattern.

properties. The table includes the name, value, and description
Property name Value Description
debug true or false (default is false) Enables detailed tracing on this batch data stream.
openjpa.Log DefaultLevel=WARN,SQL=TRACE JPA log settings
EnablePerformanceMeasurement true or false (default is false) Calculates the total time spent in the batch data streams and the processRecord method, if you are using the GenericXDBatchStep.
EnableDetailedPerformanceMeasurement true or false (default is false) Provides a more detailed breakdown of time spent in each method of the batch data streams.


Interface definition

public interface JPAReaderPattern {
  /**
  * This method is invoked during the job setup phase.    *    * @param props properties provided in the xJCL    */
   public void initialize(Properties props);
   /**
  * This method should retrieve values for the various columns for the current row from    * the given Iterator object. Typically this data would be used to populate an intermediate
   * object which would be returned.
  * @param listIt
  * @return
  */
 public Object fetchRecord(Iterator listIt);
   /**
  * This method should return a JPQL query that will be used during setup of the stream to    * retrieve all relevant data that would be processed part of the job steps.
  * @return object to be used during process step.
  */
 public String getInitialLookupQuery();
   /**
  * This method gets called during Job Restart. The restart token should be used to create    * a JPQL query that retrieves previously unprocessed records. Typically the restart token    * is the primary key in the table and the query would get all rows with    * primary key value > restarttoken
  * @param restartToken
  * @return The restart query   */
 public String getRestartQuery(String restartToken);
   /**
  * This method gets called just before a checkpoint is taken.
  * @return The method should return a string value identifying the last record read by the stream.
  */
 public String getRestartTokens();
   }


xJCL example

<batch-data-streams>  <bds>  <logical-name>inputStream</logical-name>  <props>  <prop name="PERSISTENT_UNIT" value="hellojpa"/>
<prop name="debug" value="true"/>
<prop name="PATTERN_IMPL_CLASS" value="com.ibm.websphere.samples.JPAInputStream"/>
</props>  <impl-class>com.ibm.websphere.batch.devframework.datastreams.patterns.JPAReader</impl-class>  </bds>  </batch-data-streams>


Related concepts

  • Batch data stream framework and patterns


    Related tasks

  • Use the batch data stream framework

  • JDBCReaderPattern
  • ByteReaderPattern
  • ByteWriterPattern
  • FileReaderPattern
  • FileWriterPattern
  • JPAWriterPattern

    (zos) RecordOrientedDatasetReaderPattern

    (zos) RecordOrientedDataSetWriterPattern