JPAReaderPattern

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

Supporting classes

JPAREADERThe
  1. JPAReader: Currently, JPAReader does not participate in the global transaction. It uses a JDBC connection URL and driver name to communicate with a database.

Required properties

Table 1. Required properties
Property Value
PATTERN_IMPL_CLASS Class implementing JPAReader Pattern interface
openjpa.ConnectionDriverName The JDBC driver. For example, org.apache.derby.jdbc.EmbeddedDriver
openjpa.ConnectionURL The JDBC URL. For example, jdbc:derby:C:\\mysample CREDITREPORT
openjpa.jdbc.SynchronizeMappings JPA-specific property. For example, buildSchema
openjpa.ConnectionUserName The user ID for the database. For example, Myid
openjpa.ConnectionPassword User password. For example, mypwd.
PERSISTENT_UNIT The OpenJPA persistent unit name.

Optional properties

Table 2. Optional properties
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 an JPQL query that will
	 * retrieve previously unprocessed records. 
	 * Typically the restart token would be 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="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<prop name="openjpa.ConnectionURL" value="jdbc:derby:/opt/tmp/hellojpadb;create=true"/>
<prop name="openjpa.ConnectionUserName" value="" />
<prop name="openjpa.ConnectionPassword" value="" />
<prop name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
<prop name="openjpa.Log" value="DefaultLevel=WARN,SQL=TRACE"/>
<prop name="PERSISTENT_UNIT" value="hellojpa"/>
<prop name="debug" value="true"/>
<prop name="PATTERN_IMPL_CLASS" value="com.ibm.websphere.samples.JPAOutputStream"/>
</props>  
<impl-class>com.ibm.websphere.batch.devframework.datastreams.patterns.LocalJDBCReader</impl-class>  
</bds>  
</batch-data-streams>