
Component family |
Custom Code |
|
Function |
tJavaFlex enables you to enter |
|
Objective |
tJavaFlex lets you add Java code |
|
Basic settings |
Schema and Edit |
A schema is a row description. It defines the number of fields to be processed and passed on Since version 5.6, both the Built-In mode and the Repository mode are Click Sync columns to retrieve This component offers the advantage of the dynamic schema feature. This allows you to This dynamic schema feature is designed for the purpose of retrieving unknown columns |
|
|
Built-In: You create and store the schema locally for this |
|
|
Repository: You have already created the schema and When the schema to be reused has default values that are integers or functions, ensure that For more details, see https://help.talend.com/display/KB/Verifying+default+values+in+a+retrieved+schema. |
Click Edit schema to make changes to the schema. If the
|
||
|
Data Auto Propagate |
Select this check box to automatically propagate the data to the |
|
Start code |
Enter the Java code that will be called during the initialization |
|
Main code |
Enter the Java code to be applied for each line in the data |
|
End code |
Enter the Java code that will be called during the closing |
Advanced settings |
Import |
Enter the Java code that helps to import, if necessary, external |
|
tStatCatcher Statistics |
Select this check box to gather the Job processing metadata at a |
Global Variables |
ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see Talend Studio |
|
Usage |
You can use this component as a start, intermediate or output |
|
Limitation |
You should know the Java language. |
This scenario describes a two-components Job that generates a three-line data flow
describing different personal titles (Miss, Mrs, and Mr) and displaying them on the
console.

-
Drop tJavaFlex and tLogRow from the Palette
onto the design workspace. -
Connect the components together using a Row > Main link.
-
Double-click tJavaFlex to display its
Basic settings view and define its
properties. -
Click
the three-dot button next to Edit schema to
open the corresponding dialog box where you can define the data structure to
pass to the component that follows. -
Click the [+] button to add two columns:
key and value and then set
their types to Integer and String respectively. -
Click OK to validate your changes and
close the dialog box. -
In the Basic settings view of tJavaFlex, select the Data
Auto Propagate check box to automatically propagate data to
the component that follows.In this example, we do not want to do any transformation on the retrieved
data. -
In the Start code field, enter the code
to be executed in the initialization phase.In this example, the code indicates the initialization of tJavaFlex by displaying the START message and
sets up the loop and the variables to be used afterwards in the Java
code:12345System.out.println("## START#");<span></span>String [] valueArray = {"Miss", "Mrs", "Mr"};<span></span><span></span>for (int i=0;i<valueArray.length;i++) { -
In the Main code field, enter the code
you want to apply on each of the data rows.In this example, we want to display each key with its value:
12row1.key = i;<span></span>row1.value = valueArray[i];Warning
In the Main
code field, “row1” corresponds to the name of the
link that comes out of tJavaFlex.
If you rename this link, you have to modify the code of this field
accordingly. -
In the End code field, enter the code
that will be executed in the closing phase.In this example, the brace (curly bracket) closes the loop and the code
indicates the end of the execution of tJavaFlex by displaying the END message:123}<span></span>System.out.println("### END"); -
If needed, double-click tLogRow and in
its Basic settings view, click the
[…] button next to Edit schema to make sure that the schema has been
correctly propagated.
This scenario describes a two-component Job that generates random data and then
collects that data and does some transformation on it line by line using Java code
through the tJavaFlex component.

-
Drop tRowGenerator and tJavaFlex from the Palette
onto the design workspace. -
Connect the components together using a Row
Main link.
-
Double-click tRowGenerator to display its
Basic settings view and the [RowGenerator Editor] dialog box where you can
define the component properties. -
Click the plus button to add four columns: number,
txt, date and
flag. -
Define the schema and set the parameters to the four columns according to
the above capture. -
In the Functions column, select the
three-dot function […] for each of the
defined columns. -
In the Parameters column, enter 10
different parameters for each of the defined columns. These 10 parameters
corresponds to the data that will be randomly generated when executing
tRowGenerator. -
Click OK to validate your changes and
close the editor.
-
Double-click tJavaFlex to display its
Basic settings view and define the
components properties. -
Click Sync columns to retrieve the schema
from the preceding component. -
In the Start code field, enter the code
to be executed in the initialization phase.In this example, the code indicates the initialization of the tJavaFlex component by displaying the START
message and defining the variable to be used afterwards in the Java
code:123System.out.println("## START#");<span></span>int i = 0; -
In the Main code field, enter the code to
be applied on each line of data.In this example, we want to show the number of each line starting from 0
and then the number and the random text transformed to upper case and
finally the random date set in the editor of tRowGenerator. Then, we create a condition to show if the
status is true or false and we increment the number of the line:12345678System.out.print(" row" + i + ":");<span></span>System.out.print("# number:" + row1.number);<span></span>System.out.print (" | txt:" + row1.txt.toUpperCase());<span></span>System.out.print(" | date:" + row1.date);<span></span>if(row1.flag) System.out.println(" | flag: true");<span></span>else System.out.println(" | flag: false");<span></span><span></span>i++;Warning
In the Main
code field, “row1” corresponds to the name of the
link that connects to tJavaFlex. If
you rename this link, you have to modify the code. -
In the End code field, enter the code
that will be executed in the closing phase.In this example, the code indicates the end of the execution of tJavaFlex by displaying the END message:
12System.out.println("### END");
This scenario describes a three-component Job that uses Java code through a tJavaFlex component to display the content of a file being
transferred from the source to the target. As all the components in this Job support the
dynamic schema feature, we can leverage this feature to save the time of configuring
each column of the schema.
-
Drop tFileInputDelimited, tJavaFlex, and tFileOutputDelimited from the Palette
onto the design workspace. -
Connect the components in a series using Row > Main links.
-
Label the components according to their roles in the Job.
-
Double-click the tFileInputDelimited
component, which is labeled Source, to
display its Basic settings view where you
can define the component properties.Warning
The dynamic schema feature is only supported in Built-In mode and requires the input file
to have a header row. -
In the File name/Stream field, type in
the path to the input file in double quotation marks, or browse to the path
by clicking the […] button. -
In the Header field, type in 1 to use the first line of the file as the
header. -
Click the […] button next to Edit schema to open the [Schema] dialog box.
-
Click the [+] button to add a column,
give a name to the column, dyna in this
example, and select Dynamic from the
Type list. This dynamic column will
retrieve the three columns, FirstName,
LastName and Address, of the input file. -
Click OK to validate the setting and
close the dialog box. -
Double-click the tFileOutputDelimited
component, which is labeled Target, to
display its Basic settings view where you
can define the component properties. -
Define the output file path in the File
Name field. -
Select the Include Header check box to
include the header in the output file. Leave all the other settings are they
are.
-
Double-click tJavaFlex to display its
Basic settings view and define the
components properties. -
Click Sync columns to make sure that the
schema is correctly retrieved from the preceding component. -
In the Start code field, enter the
following code:12System.out.println("Content of file being transferred:"); -
In the Main code field, enter the code to
be applied on each line of data.In this example, we want to display the content of the source file based
on the defined dynamic schema column:1System.out.println(row1.dyna);Warning
In the Main
code field, “row1” refers to the name of the link
that connects to tJavaFlex. If you
rename this link, you have to modify the code. -
In the End code field, enter the code
that will be executed in the closing phase.In this example, the code indicates the end of the execution of tJavaFlex by displaying the “End of file”
message:12System.out.println("End of file");
-
Save your Job by pressing Ctrl+S.
-
Execute the Job by pressing F6 or
clicking Run on the Run tab.The console displays the content of the input file. As the Data Auto Propagate check box is selected by
default, the content of the file is intactly transferred to the output
component.