Configuring a Job using a tJava component - 7.0

Java custom code

author
Talend Documentation Team
EnrichVersion
7.0
EnrichProdName
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
task
Data Governance > Third-party systems > Custom code components (Integration) > Java custom code components
Data Quality and Preparation > Third-party systems > Custom code components (Integration) > Java custom code components
Design and Development > Third-party systems > Custom code components (Integration) > Java custom code components
EnrichPlatform
Talend Studio

A common Job using tJava is generally composed of:

  • a tFileInputDelimited component to read data from a text file,
  • a tLogRow component to print data in the console,
  • a tJava component to retrieve the total number of records processed.

Procedure

  1. In the Palette, drag and drop a tFileInputDelimited , a tLogRow and a tJava component onto the workspace.
  2. Connect tFileInputDelimited to tJava using a Trigger > OnSubjobOk link.
  3. Set the Basic settings of the tFileInputDelimited component.
  4. Double-click on tFileInputDelimited to display its Basic settings. In the file name/steam field, add the source data file path "C:/person.txt".
  5. This file includes the following data:
    1;Shong
    2;Elisa
    3;Sabrina
  6. Click the Edit Schema button and set the two-column schema.
  7. Double-click on tjava to display its Basic settings view and add the following code in the Code area:
    int nb_line=(Integer)globalMap.get("tFileInputDelimited_1_NB_LINE");
    System.out.println("The total number of records are read from the text file is: " +nb_line);
  8. Execute the Job by pressing F6.

Results

The actual records from the input file are printed into the console natively. In addition, due to the use of the tJava component, the number of records also displays onto the console.