5 minutes tutorial
From UbikWiki
(Difference between revisions)
(→Configure Batch) |
(→Setup Project) |
||
(13 intermediate revisions not shown.) | |||
Line 2: |
Line 2: | ||
= Setup Project = | = Setup Project = | ||
- | In your | + | * 1) In your Eclipse workspace base folder run: |
- | <source lang="text"> | + | <source lang="text"> mvn archetype:create |
- | mvn archetype:create -DgroupId=com.ubikingenierie | + | -DgroupId=com.ubikingenierie |
+ | -DartifactId=MyFirstBatch | ||
+ | -DarchetypeGroupId=com.ubikingenierie.console | ||
+ | -DarchetypeArtifactId=UbikBarArtifact | ||
+ | -DarchetypeVersion=6.0.0 | ||
</source> | </source> | ||
- | + | * 2) Go to created folder | |
- | Go to created folder | + | * 3) Run: |
- | + | <source lang="text">mvn eclipse:eclipse</source> | |
- | Run: | + | * 4)Open Eclipse and import created project |
- | <source lang="text"> | + | |
- | mvn eclipse:eclipse | + | |
- | </source> | + | |
- | + | ||
- | Open Eclipse and import created project | + | |
= Create a Batch = | = Create a Batch = | ||
== Extend com.ubikingenierie.console.apiconsole.BaseBatch: == | == Extend com.ubikingenierie.console.apiconsole.BaseBatch: == | ||
- | == Configure Batch == | + | == Configure the Batch == |
<source lang="java"> | <source lang="java"> | ||
package com.ubikingenierie; | package com.ubikingenierie; | ||
Line 104: |
Line 103: | ||
</source> | </source> | ||
- | + | <u>Notice</u>: | |
- | * SqlBatchStart : Is the data extractor that handles extraction of data from a source (Here a database) and | + | * 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) | * CronTrigger : The Trigger that starts the batch (in this example, Fire at 10:15am on the last Friday of every month) | ||
== Configure Project Metadata == | == Configure Project Metadata == | ||
- | Edit file src/main/resources/bar.xml and modify: | + | Edit file <big>src/main/resources/bar.xml</big> and modify: |
<source lang="xml"> | <source lang="xml"> | ||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
Line 144: |
Line 143: | ||
== Develop your business Logic == | == Develop your business Logic == | ||
Code at least executeOnBlock() method: | Code at least executeOnBlock() method: | ||
- | * The method has only one parameter which | + | * 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 | * Batch server handles extraction in data block of 100 lines | ||
And optionally : | And optionally : | ||
- | * executeBeforeData | + | * executeBeforeData : Called at batch startup before Query execution |
- | * executeAfterDataEnd | + | * executeAfterDataEnd : Called at end of batch |
= Create the Deployment unit = | = Create the Deployment unit = | ||
Line 159: |
Line 158: | ||
This generates a BAR that you can give to your deployment team for PRODUCTION deployment. | 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 |
Current revision
Contents |
Setup Project
- 1) In your Eclipse workspace base folder run:
mvn archetype:create -DgroupId=com.ubikingenierie -DartifactId=MyFirstBatch -DarchetypeGroupId=com.ubikingenierie.console -DarchetypeArtifactId=UbikBarArtifact -DarchetypeVersion=6.0.0
- 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() { super(); } /* (non-Javadoc) * @see com.ubikingenierie.console.apiconsole.BaseBatch#createConfiguration() */ @Override public TraitementConfiguration createConfiguration() throws BatchException { try { TraitementConfiguration lanceur = new TraitementConfiguration(); lanceur.setGroup("ORDER_MANAGEMENT"); lanceur.setName("MyFirstBatch"); lanceur.setBatchAppender(new JdbcErrorAppender()); lanceur.setTrtClassName(MyFirstBatch.class.getName()); SqlBatchStart batchStart = new SqlBatchStart( "jdbc/orderManagementPool", "select COLUMN1, COLUMN2 as PAR_VALUE from TABLE1 t1 INNER JOIN TABLE2 t2 ON t1.id=t2.fk_id", false, new String[] {"COL1, COL2"}); // Work with 100 lines in memory max batchStart.setNbTraitement(100); lanceur.setBatchStart(batchStart); 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() */ @Override protected void executeAfterDataEnd() throws Exception { } /* (non-Javadoc) * @see com.ubikingenierie.console.apiconsole.BaseBatch#executeBeforeData() */ @Override protected void executeBeforeData() throws Exception { // TODO Auto-generated method stub } /* (non-Javadoc) * @see com.ubikingenierie.console.apiconsole.BaseBatch#executeOnBlock(java.lang.Object[]) */ @Override protected void executeOnBlock(Object[] data) throws Exception { // Code my business logic using data } }
Notice:
- 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" "http://www.ubik-ingenierie.com/consolebatch/config/bar.dtd"> <bar-configuration> <!-- 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. --> <display-name>ECommerceBatches</display-name> <!-- Groups of batches --> <groups> <group name="ORDER_MANAGEMENT"> <batches> <batch-classname>com.ubikingenierie.MyFirstBatch</batch-classname> </batches> </group> </groups> <!-- Resources --> <bar-resources> <bar-resource name="jdbc/orderManagementPool" type="javax.sql.DataSource" /> </bar-resources> <!-- Log4J Configuration --> <logging-file>log.xml</logging-file> </bar-configuration>
Notice:
- 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
Run:
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