Search code examples
javatalend

How to add custom JAVA code in tMap in TALEND


I have a requirement to create a TALEND Job to load tens of millions of data from CSV file to my oracle DB Table. In csv I have a column as Entity_Code. In Table I need to write custom code and insert this ENTITY_CODE as

Random rnd = new Random();
int sixDigits = 100000 + rnd.nextInt(900000);
if (ENTITY_CODE != null && ENTITY_CODE.length() > 4) {
    newENTITY_CODE = "SB-" + ENTITY_CODE.substring(0, 4) + sixDigits;
} else {
    newENTITY_CODE = "SB-" + ENTITY_CODE + sixDigits;
}

newENTITY_CODE. I create a job where input is the CSV file, then used tMap and then my Table but how to include this code.


Solution

  • In order to use your custom code in a tMap expression, create a routine :

    Code > create routine
    

    And put your code in a method which takes a String type (ENTITY_CODE) and returns a String type (which is your newENTITY_CODE).
    Then in your tMap column expression call the method like this :

    myRoutine.myMethod(row.ENTITY_CODE)