5 minutes tutorial

From UbikWiki


Setup Project

  • 1) In your Eclipse workspace base folder run:
mvn archetype:create 
  • 2) Go to created folder
  • 3) Run:
mvn eclipse:eclipse
  • 4)Open Eclipse and import created project

Create a Batch

Extend com.ubikingenierie.console.apiconsole.BaseBatch:

Configure the Batch

package com.ubikingenierie;
import java.text.ParseException;
import org.quartz.CronTrigger;
import org.quartz.Trigger;
import salto.batch.appender.JdbcErrorAppender;
import salto.batch.lanceur.BatchException;
import salto.batch.lanceur.builder.TraitementConfiguration;
import salto.batch.lanceur.init.SqlBatchStart;
import com.ubikingenierie.console.apiconsole.BaseBatch;
public class MyFirstBatch extends BaseBatch {
	public MyFirstBatch() {
	/* (non-Javadoc)
	 * @see com.ubikingenierie.console.apiconsole.BaseBatch#createConfiguration()
	public TraitementConfiguration createConfiguration() throws BatchException {
		try {
			TraitementConfiguration lanceur = new TraitementConfiguration();
			lanceur.setBatchAppender(new JdbcErrorAppender());
			SqlBatchStart batchStart = new SqlBatchStart(
					"select COLUMN1, COLUMN2 as PAR_VALUE from TABLE1 t1 INNER JOIN TABLE2 t2 ON t1.id=t2.fk_id", 
					new String[] {"COL1, COL2"});
			// Work with 100 lines in memory max
			CronTrigger firstDayOfEveryMonth = new CronTrigger("ORDER_MANAGEMENT", "MyFirstBatch_TRIGGER", "MyFirstBatch", "ORDER_MANAGEMENT", "0 0 5 1 * ?");
			lanceur.setTriggers(new Trigger[]{firstDayOfEveryMonth});
			return lanceur;
		} catch (ParseException e) {
			throw new BatchException("Error creating CronTrigger ", e);
	/* (non-Javadoc)
	 * @see com.ubikingenierie.console.apiconsole.BaseBatch#executeAfterDataEnd()
	protected void executeAfterDataEnd() throws Exception {
	/* (non-Javadoc)
	 * @see com.ubikingenierie.console.apiconsole.BaseBatch#executeBeforeData()
	protected void executeBeforeData() throws Exception {
		// TODO Auto-generated method stub
	/* (non-Javadoc)
	 * @see com.ubikingenierie.console.apiconsole.BaseBatch#executeOnBlock(java.lang.Object[])
	protected void executeOnBlock(Object[] data) throws Exception {
		// Code my business logic using data


  • SqlBatchStart : Is the data extractor that handles extraction of data from a source (Here a database) and gives it to Batch class in executeOnBlock() method
  • CronTrigger : The Trigger that starts the batch (in this example, Fire at 10:15am on the last Friday of every month)

Configure Project Metadata

Edit file src/main/resources/bar.xml and modify:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bar-configuration PUBLIC "-//Ubik-Ingenierie //DTD BAR Configuration 1.0//EN" 
		The display-name must be unique for all bars deployed in the console
		server. It is recommanded that display-name is the same as the BAR
		file name for better convenience.
	<!-- Groups of batches -->
		<group name="ORDER_MANAGEMENT">
	<!-- Resources -->
		<bar-resource name="jdbc/orderManagementPool" type="javax.sql.DataSource" />
	<!--  Log4J Configuration -->


    • jdbc/orderManagementPool : The pool that will be used to access database
    • group : You can group batches business logic

Develop your business Logic

Code at least executeOnBlock() method:

  • The method has only one parameter which contains part of the result of the SQL Query execution
  • Batch server handles extraction in data block of 100 lines

And optionally :

  • executeBeforeData : Called at batch startup before Query execution
  • executeAfterDataEnd : Called at end of batch

Create the Deployment unit


mvn clean deploy

This generates a BAR that you can give to your deployment team for PRODUCTION deployment.

That's it

Now here is what you get:

  • Automatic error management
  • Multithreading of your batch
  • Hot management of your batch configuration
  • History of your batch execution and its status
  • Alert if your batch takes too much time to execute
  • ... see features
Personal tools