August 15, 2023

Configuring the tJavaFlex and tJava components – Docs for ESB 6.x

Configuring the tJavaFlex and tJava components

  1. Double-click the tJavaFlex component to open its
    Basic settings view on the Component tab.

    Use_Case_tMemorizeRows6.png

  2. In the Start code area, enter the Java code that will
    be called during the initialization phase. In this example, type in int
    count=0;
    in order to declare a variable count and assign the
    value 0 to it.
  3. In the Main code area, enter the Java code to be
    applied to each row in the data flow. In this scenario, type
    in:if(!age_tMemorizeRows_1[0].equals(age_tMemorizeRows_1[1]))
    {
    count++;
    }
    System.out.println(age_tMemorizeRows_1[0]);
    This
    code compares two ages memorized by the tMemorizeRows
    component each time and counts one change every time the ages are found to be different.
    This code then displays the age that has been indexed as 0 by the tMemorizeRows component. When the tJavaFlex
    component is in the same flow of the tMemorizeRows
    component, the variable format is ColumnName_ComponentName[index].
  4. In the End code area, enter the Java code that will
    be called during the closing phase. In this example, type in globalMap.put("number",
    count);
    to initialize the global variable number with the value of the count
    variable.
  5. Double-click the tJava component to open its
    Basic settings view on the Component tab.

    Use_Case_tMemorizeRows7.png

  6. In the Code area, enter the flollowing code to
    display the number of occurrences of different ages and the lowest age within the
    customers on the
    console:System.out.println("Different ages:
    "+globalMap.get("number"));

    System.out.println("Lowest age: " + ((Integer[])globalMap.get("tMemorizeRows_1_age"))[0]);

    The method globalMap.get() is used by the tJava to retrieve the array values. Note that here, the tJava is used outside the subjob tMemorizeRows so the variable format should be
    ComponentName_ColumnName, which is different from the variable format used
    by a component placed in the same flow.

Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x