Informatica Java Transformation to Leverage the Power of Java Programming

Johnson Cyriac Sep 17, 2013

Informatica Java Transformation
Java is, one of the most popular programming languages in use, particularly for client-server web applications. With the introduction of PowerCenter Java Transformation, ETL developers can get their feet wet with Java programming and leverage the power of Java. In this article lets learn more about Java Transformation, its components and its usage with the help of a use case.

What is Java Transformation

With Java transformation you can define transformation logic using java programming language without advanced knowledge of the Java programming language or an external Java development environment.

The PowerCenter Client uses the Java Development Kit (JDK) to compile the Java code and generate byte code for the transformation. The PowerCenter Client stores the byte code in the PowerCenter repository. When the Integration Service runs a session with a Java transformation, the Integration Service uses the Java Runtime Environment (JRE) to execute the byte code and process input rows and generate output rows.

Developing Code in Java Transformation

You can use the code entry tabs to enter Java code snippets to define Java transformation functionality. Using the code entry tabs with in the transformation, you can import Java packages, write helper code, define Java expressions, and write Java code that defines transformation behavior for specific transformation events. 

Below image shows different code entry tabs under 'Java Code'.
Informatica Java Transformation
  • Import Packages :- Import third-party Java packages, built-in Java packages, or custom Java packages. 
  • Helper Code :- Define variables and methods available to all tabs except Import Packages. After you declare variables and methods on the Helper Code tab, you can use the variables and methods on any code entry tab except the Import Packages tab.
  • On Input Row :- Define transformation behavior when it receives an input row. The Java code in this tab executes one time for each input row
  • On End of Data :- Use this tab to define transformation logic when it has processed all input data. 
  • On Receiving Transaction :- Define transformation behavior when it receives a transaction notification. You can use this only with active Java transformations. 
  • Java Expressions : - Define Java expressions to call PowerCenter expressions. You can use this in multiple code entry tabs.

Java Transformation Use Case 

Lets take a simple example for our demonstration. The employee data source contains the employee ID, name, Age, Employee description, and the manager ID. We need to create an ETL transformation to find the manager name for a given employee based on the manager ID and generates output file that contain employee ID, name, Employee description, and the Manager name.

Below shown is the complete structure of the mapping to build the functionality we described above. We are using only Java Transformation other than source, target and source qualifier.
Informatica Java Transformation
Step 1 :- Once you have the source and source qualifier pulled in to the Java Transformation and create input and output ports as shown in below image. Just like any other transformation, you can drag and drop ports from other transformations to create new ports.
Informatica Java Transformation
Step 2 :- Now move to the 'Java Code' tab and from 'import package' tab import the external java classes required by the java code. This tab can be used to import any third party java classes or build in java classes.
Informatica Java Transformation
As shown in above image here is the import code used.
import java.util.Map;
import java.util.HashMap;
Step 3 :- In the 'Helper Code' tab, define the variables, objects and functions required by the java code, which will be written in 'On Input Row'. Here we have created four objects.
Informatica Java Transformation
Below is the code used.
private static Map <Integer, String> empMap = new HashMap <Integer, String> ();
private static Object lock = new Object();
private boolean generateRow;
private boolean isRoot;
Step 4 :- In the 'On Input Row' tab, define the ETL logic, which will be executed for every input record.
Informatica Java Transformation
Below is the complete code we need to place it in the 'On Input Row'
generateRow = true;
isRoot = false;
if (isNull ("EMP_ID_INP") || isNull ("EMP_NAME_INP"))
{
     incrementErrorCount(1);
     generateRow = false;
} else {
     EMP_ID_OUT = EMP_ID_INP;
     EMP_NAME_OUT = EMP_NAME_INP;
}
if (isNull ("EMP_DESC_INP"))
{
     setNull("EMP_DESC_OUT");
} else {
     EMP_DESC_OUT = EMP_DESC_INP;
}
boolean isParentEmpIdNull = isNull("EMP_PARENT_EMPID");
if(isParentEmpIdNull)
{
     isRoot = true;
     logInfo("This is the root for this hierarchy.");
     setNull("EMP_PARENT_EMPNAME");
}
synchronized(lock)
{
     if(!isParentEmpIdNull)
          EMP_PARENT_EMPNAME = (String) (empMap.get(new Integer (EMP_PARENT_EMPID)));
     empMap.put (new Integer(EMP_ID_INP), EMP_NAME_INP);
}
if(generateRow)
     generateRow();
With this we are done with the coding required in Java Transformation and only left with code compilation. Remaining tabs in this java transformation do not need any code for our use case.

Compile the Java Code

To compile the full code for the Java transformation, click Compile on the Java Code tab. The Output window displays the status of the compilation. If the Java code does not compile successfully, correct the errors in the code entry tabs and recompile the Java code. After you successfully compile the transformation, save the transformation to the repository.

Completed Mapping  

Remaining tabs do not need any code for our use case and all the ports from the java transformation can be connected from the source qualifier and to the target. Below shown is the completed structure of the mapping.
Informatica Java Transformation
Hope you enjoyed this tutorial, Please let us know if you have any difficulties in trying out this java code and java transformation or share us if you use any different use cases you want to implement using java transformation.




About US Contact US Advertise Guest Post Terms and Conditions Privacy Policy Disclaimer

© 2012-2013 Data Intelligence Solution, All Rights Reserved
The contents in this site is copyrighted to Data intelligence Solution and may not be reproduced on other websites.