Extensions

Note: a generated documentation is available here: generated documentation page.

Extras

org.apache.batchee.extras.locator.BeanLocator

Each time an implementation/reference needs to be resolved this API is used. The default one respects the same rules as the implementation used to resolve ref attributes of the batch xml file (it means you can use qualified names, CDI names if you are in a CDI container...).

A word on extensions

Readers, writers, processors have always a shortname which will only work with batchee implementation. To use it with other JBatch implementation use the full qualified name.

org.apache.batchee.extras.chain.ChainProcessor

Allow to set multiple javax.batch.api.chunk.ItemProcessor through a single processor. The n+1 processor processes the returned value of the n processor.

Sample:

Note: org.apache.batchee.extras.chain.ChainBatchlet does the same for javax.batch.api.Batchlet.

Shortname: chainProcessor

org.apache.batchee.extras.flat.FlatFileItemReader

A reader reading line by line a file. By default the line is returned as a java.lang.String. To return another object just override protected Object preReturn(String line, long lineNumber) method:

Sample:

Configuration:

  • comments: a comma separated list of prefixes marking comment lines
  • input: the input file path
  • locator: the BeanLocator used to find the lineMapper
  • lineMapper: an implementation of org.apache.batchee.extras.flat.LineMapper. If noone is provided the read object will be the line (as a String)

Shortname: flatReader

org.apache.batchee.extras.flat.FlatFileItemWriter

A writer writing an item by line. By default toString() is used on items, to change it just override protected String preWrite(Object object) method:

Sample:

Configuration:

  • encoding: the output file encoding
  • output: the output file path
  • line.separator: the separator to use, the “line.separator” system property by default

Shortname: flatWriter

org.apache.batchee.extras.jdbc.JdbcBatchlet

A simple Batchlet to execute sql.

Sample:

Configuration:

  • jndi: jndi name of the datasource to use
  • driver: jdbc driver to use if no jndi name was provided
  • url: jdbc url to use if no jndi name was provided
  • user: jdbc user to use if no jndi name was provided
  • password: jdbc password to use if no jndi name was provided
  • sql: the sql to execute

Shortname: jdbcBatchlet

org.apache.batchee.extras.jdbc.JdbcReader

This reader execute a query while the query returns items.

Sample:

Configuration:

  • jndi: jndi name of the datasource to use
  • driver: jdbc driver to use if no jndi name was provided
  • url: jdbc url to use if no jndi name was provided
  • user: jdbc user to use if no jndi name was provided
  • password: jdbc password to use if no jndi name was provided
  • mapper: the implementation of org.apache.batchee.extras.jdbc.RecordMapper to use to convert java.sql.ResultSet to objects
  • locator: the org.apache.batchee.extras.locator.BeanLocator to use to create the mapper
  • query: the query used to find items

Here is a sample record mapper deleting items once read (Note: you probably don't want to do so or at least not without a managed datasource):

Shortname: jdbcReader

org.apache.batchee.extras.jdbc.JdbcWriter

A writer storing items in a database.

Sample:

Configuration:

  • jndi: jndi name of the datasource to use
  • driver: jdbc driver to use if no jndi name was provided
  • url: jdbc url to use if no jndi name was provided
  • user: jdbc user to use if no jndi name was provided
  • password: jdbc password to use if no jndi name was provided
  • mapper: the implementation of org.apache.batchee.extras.jdbc.ObjectMapper to use to convert objects to JDBC through java.sql.PreparedStatement
  • locator: the org.apache.batchee.extras.locator.BeanLocator to use to create the mapper
  • sql: the sql used to insert records

Here is a sample object mapper:

Shortname: jdbcWriter

org.apache.batchee.extras.jpa.JpaItemReader

Reads items from a JPA query.

Sample:

Configuration:

  • entityManagerProvider: the org.apache.batchee.extras.jpa.EntityManagerProvider (BeanLocator semantic), note you can set a jndi name if the value starts with jndi (for instance jndi:java:comp/env/em).
  • parameterProvider: the org.apache.batchee.extras.jpa.ParameterProvider (BeanLocator semantic)
  • locator: the org.apache.batchee.extras.locator.BeanLocator used to create org.apache.batchee.extras.jpa.EntityManagerProvider and org.apache.batchee.extras.jpa.ParameterProvider
  • namedQuery: the named query to use
  • query: the JPQL query to use if no named query was provided
  • pageSize: the paging size
  • detachEntities: a boolean to ask the reader to detach entities
  • jpaTransaction: should em.getTransaction() be used or not

Shortname: jpaReader

org.apache.batchee.extras.jpa.JpaItemWriter

Write items through JPA API.

Sample:

Configuration:

  • entityManagerProvider: the org.apache.batchee.extras.jpa.EntityManagerProvider (BeanLocator semantic), note you can set a jndi name if the value starts with jndi (for instance jndi:java:comp/env/em).
  • locator: the org.apache.batchee.extras.locator.BeanLocator used to create org.apache.batchee.extras.jpa.EntityManagerProvider
  • useMerge: a boolean to force using merge instead of persist
  • jpaTransaction: should em.getTransaction() be used or not

Shortname: jpaWriter

org.apache.batchee.extras.noop.NoopItemWriter

A writer doing nothing (in a writer is mandatory so it can mock one if you don't need one).

Sample:

Shortname: noopWriter

org.apache.batchee.extras.typed.Typed[Reader|Processor|Writer]

Just abstract class allowing to use typed items instead of Object from the JBatch API.

org.apache.batchee.extras.stax.StaxItemReader

A reader using StAX API to read a XML file.

Sample:

Configuration:

  • input: the input file
  • tag: the tag marking an object to unmarshall
  • marshallingClasses: the comma separated list of JAXB classes to use to create the JAXBContext
  • marshallingPackage: if no marshallingClasses are provided this package is used to create the JAXBContext

Shortname: staxReader

org.apache.batchee.extras.stax.StaxItemWriter

A writer using StAX API to write a XML file.

Sample:

Configuration:

  • output: the output file
  • encoding: the output file encoding (default UTF-8)
  • version: the output file version (XML, default 1.0)
  • rootTag: the output rootTag (default “root”)
  • marshallingClasses: the comma separated list of JAXB classes to use to create the JAXBContext
  • marshallingPackage: if no marshallingClasses are provided this package is used to create the JAXBContext

Shortname: staxWriter

org.apache.batchee.beanio.BeanIOReader

A reader using BeanIO.

Sample:

Here is the associated beanio.xml:

Configuration:

  • file: the input file
  • streamName: the stream name (from beanio xml file)
  • configuration: the beanio xml configuration file
  • locale: the locale to use
  • errorHandler: the BeanIO error handler to use

Shortname: beanIOReader

org.apache.batchee.beanio.BeanIOWriter

A writer using BeanIO.

Sample:

Configuration:

  • file: the output file
  • streamName: the stream name (from beanio xml file)
  • configuration: the beanio xml configuration file (from the classloader)
  • encoding: the output file encoding
  • templateLocator: the org.apache.batchee.camel.CamelTemplateLocator to find the org.apache.camel.ProducerTemplate to use

Shortname: beanIOWriter

org.apache.batchee.camel.CamelItemProcessor

A processor reusing Camel logic.

Sample:

Configuration:

  • endpoint: the endpoint to use
  • templateLocator: the org.apache.batchee.camel.CamelTemplateLocator to find the org.apache.camel.ProducerTemplate to use

Shortname: camelProcessor

org.apache.batchee.camel.CamelChainItemProcessor

Same as previous one but with a chain

Sample:

Configuration: mainly the chain configuration excepted “chain” value is a list of endpoints.

Shortname: camelChainProcessor

org.apache.batchee.camel.CamelItemReader

A reader using camel consumers.

Sample:

Configuration:

  • endpoint: the input camel endpoint URI
  • templateLocator: the org.apache.batchee.camel.CamelTemplateLocator to find the org.apache.camel.ConsumerTemplate to use

Shortname: camelReader

org.apache.batchee.camel.CamelItemWriter

A writer using camel producer.

Sample:

Configuration:

  • endpoint: the input camel endpoint URI
  • templateLocator: the org.apache.batchee.camel.CamelTemplateLocator to find the org.apache.camel.ProducerTemplate to use

Shortname: camelWriter

Camel component

batchee-camel includes a Camel component. Here is its format:

jbatch:name[?synchronous=xxx]

with name the batch name. By default it is not intended to be synchronous but it can be forced (by polling) using synchronous attribute. Synchronous attribute is the polling period and needs to be > 0 to be active.

After this endpoint (even in asynchrnous mode) the exchange will get the headers:

  • JBatchOperator: the operator used to launch this job (normally not useful but some implmentations can depend on it)
  • JBatchExecutionId: the job execution id

Note: if you set JBatchExecutionId in the headers before this endpoint you can use ?restart=true or ?stop=true or ?abandon=true to restart/stop/abandon the job instead of starting it.

org.apache.batchee.groovy.GroovyItemReader

A reader delegating to a groovy script.

Sample:

Configuration:

  • scriptPath: path to the groovy file

Shortname: groovyReader

org.apache.batchee.groovy.GroovyItemProcessor

A processor delegating to a groovy script.

Sample:

Configuration:

  • scriptPath: path to the groovy file

Shortname: groovyProcessor

org.apache.batchee.groovy.GroovyItemWriter

A writer delegating to a groovy script.

Sample:

Configuration:

  • scriptPath: path to the groovy file

Shortname: groovyWriter

org.apache.batchee.groovy.GroovyBatchlet

A batchlet delegating to a groovy script.

Sample:

Configuration:

  • scriptPath: path to the groovy file

Shortname: groovyBatchlet

org.apache.batchee.extras.validation.BeanValidationItemProcessor (JSR 330/349)

A simple processor validating an item using bean validation.

Sample:

Configuration:

  • group: the group to use to validate the item
  • skipNotValidated: set to true not validated items are skipped (replaced by null)

Shortname: beanValidationProcessor

org.apache.batchee.jsefa.JSefaCsvReader

Use JSefa to read a CSV file.

Sample:

Configuration (excepted for file see org.jsefa.csv.config.CsvConfiguration for detail):

  • file: the file to read
  • objectTypes: type to take into account in the unmarshalling
  • validationMode: see org.jsefa.common.config.ValidationMode
  • lineFilter: org.jsefa.common.lowlevel.filter.LineFilter
  • lowLevelConfiguration; org.jsefa.csv.lowlevel.config.CsvLowLevelConfiguration
  • objectAccessorProvider: org.jsefa.common.accessor.ObjectAccessorProvider
  • simpleTypeProvider: org.jsefa.common.converter.provider.SimpleTypeConverterProvider
  • typeMappingRegistry; org.jsefa.common.mapping.TypeMappingRegistry
  • validationProvider; org.jsefa.common.validator.provider.ValidatorProvider
  • quoteCharacterEscapeMode: org.jsefa.csv.lowlevel.config.EscapeMode
  • lineFilterLimit
  • specialRecordDelimiter
  • lineBreak
  • defaultNoValueString
  • defaultQuoteMode
  • fieldDelimiter
  • quoteCharacter
  • useDelimiterAfterLastField

Shortname: jsefaCsvReader

org.apache.batchee.jsefa.JSefaCsvWriter

Use JSefa to write a CSV file.

Sample:

Configuration (excepted for file and encoding see org.jsefa.csv.config.CsvConfiguration for detail):

  • file: the file to write
  • encoding: the output file encoding
  • objectTypes: type to take into account in the marshalling
  • validationMode: see org.jsefa.common.config.ValidationMode
  • lineFilter: org.jsefa.common.lowlevel.filter.LineFilter
  • lowLevelConfiguration; org.jsefa.csv.lowlevel.config.CsvLowLevelConfiguration
  • objectAccessorProvider: org.jsefa.common.accessor.ObjectAccessorProvider
  • simpleTypeProvider: org.jsefa.common.converter.provider.SimpleTypeConverterProvider
  • typeMappingRegistry; org.jsefa.common.mapping.TypeMappingRegistry
  • validationProvider; org.jsefa.common.validator.provider.ValidatorProvider
  • quoteCharacterEscapeMode: org.jsefa.csv.lowlevel.config.EscapeMode
  • lineFilterLimit
  • specialRecordDelimiter
  • lineBreak
  • defaultNoValueString
  • defaultQuoteMode
  • fieldDelimiter
  • quoteCharacter
  • useDelimiterAfterLastField

Shortname: jsefaCsvWriter

org.apache.batchee.jsefa.JSefaFlrReader

Use JSefa to read a FLR file.

Sample:

Configuration (excepted for file see org.jsefa.flr.config.FlrConfiguration for detail):

  • file: the file to read
  • objectTypes: type to take into account in the unmarshalling
  • validationMode: see org.jsefa.common.config.ValidationMode
  • lineFilter: org.jsefa.common.lowlevel.filter.LineFilter
  • lowLevelConfiguration; org.jsefa.flr.lowlevel.config.FlrLowLevelConfiguration
  • objectAccessorProvider: org.jsefa.common.accessor.ObjectAccessorProvider
  • simpleTypeProvider: org.jsefa.common.converter.provider.SimpleTypeConverterProvider
  • typeMappingRegistry; org.jsefa.common.mapping.TypeMappingRegistry
  • validationProvider; org.jsefa.common.validator.provider.ValidatorProvider
  • lineFilterLimit
  • specialRecordDelimiter
  • lineBreak
  • defaultPadCharacter

Shortname: jsefaFlrReader

org.apache.batchee.jsefa.JSefaFlrWriter

Use JSefa to write a FLR file.

Sample:

Configuration (excepted for file see org.jsefa.flr.config.FlrConfiguration for detail):

  • file: the file to write
  • encoding: output file encoding
  • objectTypes: type to take into account in the marshalling
  • validationMode: see org.jsefa.common.config.ValidationMode
  • lineFilter: org.jsefa.common.lowlevel.filter.LineFilter
  • lowLevelConfiguration; org.jsefa.flr.lowlevel.config.FlrLowLevelConfiguration
  • objectAccessorProvider: org.jsefa.common.accessor.ObjectAccessorProvider
  • simpleTypeProvider: org.jsefa.common.converter.provider.SimpleTypeConverterProvider
  • typeMappingRegistry; org.jsefa.common.mapping.TypeMappingRegistry
  • validationProvider; org.jsefa.common.validator.provider.ValidatorProvider
  • lineFilterLimit
  • specialRecordDelimiter
  • lineBreak
  • defaultPadCharacter

Shortname: jsefaFlrWriter

org.apache.batchee.jsefa.JSefaXmlReader

Use JSefa to read a XML file.

Sample:

Configuration (excepted for file see org.jsefa.flr.config.FlrConfiguration for detail):

  • file: the file to read
  • objectTypes: type to take into account in the unmarshalling
  • validationMode: see org.jsefa.common.config.ValidationMode
  • objectAccessorProvider: org.jsefa.common.accessor.ObjectAccessorProvider
  • simpleTypeProvider: org.jsefa.common.converter.provider.SimpleTypeConverterProvider
  • typeMappingRegistry; org.jsefa.common.mapping.TypeMappingRegistry
  • validationProvider; org.jsefa.common.validator.provider.ValidatorProvider
  • lowLevelConfiguration: org.jsefa.xml.lowlevel.config.XmlLowLevelConfiguration
  • dataTypeDefaultNameRegistry: org.jsefa.xml.mapping.support.XmlDataTypeDefaultNameRegistry
  • namespaceManager: org.jsefa.xml.namespace.NamespaceManager
  • dataTypeAttributeName: QName with the format {uri}localName
  • lineBreak
  • lineIndentation

Shortname: jsefaXmlReader

org.apache.batchee.jsefa.JSefaXmlWriter

Use JSefa to write a XML file.

Sample:

Configuration (excepted for file see org.jsefa.flr.config.FlrConfiguration for detail):

  • file: the file to write
  • encoding: the output file encoding
  • objectTypes: type to take into account in the marshalling
  • validationMode: see org.jsefa.common.config.ValidationMode
  • objectAccessorProvider: org.jsefa.common.accessor.ObjectAccessorProvider
  • simpleTypeProvider: org.jsefa.common.converter.provider.SimpleTypeConverterProvider
  • typeMappingRegistry; org.jsefa.common.mapping.TypeMappingRegistry
  • validationProvider; org.jsefa.common.validator.provider.ValidatorProvider
  • lowLevelConfiguration: org.jsefa.xml.lowlevel.config.XmlLowLevelConfiguration
  • dataTypeDefaultNameRegistry: org.jsefa.xml.mapping.support.XmlDataTypeDefaultNameRegistry
  • namespaceManager: org.jsefa.xml.namespace.NamespaceManager
  • dataTypeAttributeName: QName with the format {uri}localName
  • lineBreak
  • lineIndentation

Shortname: jsefaXmlWriter

org.apache.batchee.jackson.JacksonJsonReader

Use Jackson to read a JSon file.

Sample:

Configuration (excepted for file see org.jsefa.flr.config.FlrConfiguration for detail):

  • file: the file to read
  • type: the type to use to unmarshall objects, note: without it readValueAsTree will be used
  • configuration: the ObjectMapper configuration (comma separated list with for each config the syntax name=value. Name can be in DeserializationFeature, SerializationFeature and MapperFeature values and value is a boolean (true/false))
  • skipRoot: should root be read as an item or not

Shortname: jacksonJSonReader

org.apache.batchee.jackson.JacksonJSonWriter

Use Jackson to write a JSon file.

Sample:

Configuration (excepted for file see org.jsefa.flr.config.FlrConfiguration for detail):

  • file: the file to write
  • encoding: output file encoding
  • configuration: the ObjectMapper configuration (comma separated list with for each config the syntax name=value. Name can be in DeserializationFeature, SerializationFeature and MapperFeature values and value is a boolean (true/false))
  • skipRoot: should root be written. If fieldNameGeneratorClass is not null it will use a root object and if not set root will be an array.
  • fieldNameGeneratorClass: if skipRoot is not true or null it will be used to generate the field name (and force the root to be an object). “default” means use “item1”, “item2”, .... Otherwise set a qualified name org.apache.batchee.jackson.FieldNameGenerator.

Shortname: jacksonJSonWriter

org.apache.batchee.modelmapper.ModelMapperItemProcessor

Just a simple item processor mapping input to another type based on ModelMapper library. To customize the modelMapper just override newMapper() method.

Sample:

Configuration (excepted for file see org.jsefa.flr.config.FlrConfiguration for detail):

  • destinationType: the target type for the mapping (qualified name)

Shortname: modelMapperProcessor

org.apache.batchee.hazelcast.HazelcastLockBatchlet

A batchlet getting a hazelcast lock.

Sample:

Configuration (excepted for file see org.jsefa.flr.config.FlrConfiguration for detail):

  • local: a boolean to determine if the HazelcastInstance is local or remote (ie if the HazelcastInstance is a member of the cluster or a client)
  • instanceName: the instance name when local = true
  • xmlConfiguration: the xml configuration of the instance
  • lockName: the lock name to use
  • tryDuration: if set the lock is tried to be hold for this duration
  • tryDurationUnit: the unit to use to try to get the lock (see tryDuration)

Shortname: hazelcastLock

org.apache.batchee.hazelcast.HazelcastUnlockBatchlet

A batchlet releasing a hazelcast lock.

Sample:

Configuration (excepted for file see org.jsefa.flr.config.FlrConfiguration for detail):

  • local: a boolean to determine if the HazelcastInstance is local or remote (ie if the HazelcastInstance is a member of the cluster or a client)
  • instanceName: the instance name when local = true
  • xmlConfiguration: the xml configuration of the instance
  • lockName: the lock name to use

Shortname: hazelcastUnlock

CDI scopes

@org.apache.batchee.cdi.scope.JobScoped allows you to define a bean scoped to a job execution. @org.apache.batchee.cdi.scope.StepScoped allows you to define a bean scoped to a step execution.

To activate these scopes you need to define 4 listeners:

  • org.apache.batchee.cdi.listener.BeforeJobScopeListener
  • org.apache.batchee.cdi.listener.AfterJobScopeListener
  • org.apache.batchee.cdi.listener.BeforeStepScopeListener
  • org.apache.batchee.cdi.listener.AfterStepScopeListener

If your implementation supports ordering on listeners use them to ensure Before* are executed first and After* are executed last. This will let you use these scopes in your own listeners. *JobScopeListener are javax.batch.api.listener.JobListener and *StepScopeListener are javax.batch.api.listener.StepListener.

NB: these listeners are @Named so you can use their CDI name to reference them (not mandatory)

If the implementation doesn't provide any ordering of the listeners be aware these scopes will only work in steps.

For BatchEE you can add them in batchee.properties this way: