Java Transformation Java Properties
Use the code entry tabs in the Java view to write and compile Java code that defines transformation behavior for specific transformation events.
The following tabs are code entry tabs:
- •Imports
- •Helpers
- •On Input
- •At End
- •Functions
- •Optimizer Interfaces
View the full class code for the Java transformation on the Full Code tab.
Imports Tab
On the Imports tab, you can import third-party, built-in, or custom Java packages for active or passive Java transformations.
To import a Java package, enter the code to import the package in the Java code window in the Code properties on the Imports tab.
For example, you might enter the following code to import the java.io package:
import java.io.*;
To compile the code that imports Java packages, click Compile in the Compilation properties on the Imports tab. The results of the compilation appear in the Results window on the Imports tab.
After you import Java packages, you can use them on the other code entry tabs.
Helpers Tab
On the Helpers tab, you can declare user-defined variables and methods for the Java transformation class in an active or passive Java transformation.
To declare user-defined variables and methods, enter the code in the Java code window in the Code properties on the Helpers tab.
To compile the helper code for the Java transformation, click Compile in the Compilation properties on the Helpers tab. The results of the compilation appear in the Results window on the Helpers tab.
After you declare variables and methods, you can use them in any other code entry tab except the Imports tab.
On Input Tab
On the On Input tab, you define how an active or passive Java transformation behaves when it receives an input row. On this tab, you can also access and use input and output port data, variables, and Java transformation API methods.
The Java code that you define on this tab runs one time for each input row.
To define how a Java transformation behaves when it receives an input row, enter the code in the Java code window in the Code properties on the On Input tab.
From the navigator on the On Input tab, you can access and define the following variables and API methods:
- •Input port and output port variables. Access input and output port data as a variable by using the name of the port as the name of the variable. For example, if “in_int” is an Integer input port, you can access the data for this port by referring as a variable “in_int” with the Java primitive datatype int. You do not need to declare input and output ports as variables.
Do not assign a value to an input port variable. If you assign a value to an input variable on the On Input tab, you cannot get the input data for the corresponding port in the current row.
- •Instance variables and user-defined methods. Use any instance or static variable or user-defined method you declared on the Helpers tab.
For example, an active Java transformation has two input ports, BASE_SALARY and BONUSES, with an integer datatype, and a single output port, TOTAL_COMP, with an integer datatype. You create a user-defined method on the Helpers tab, myTXAdd, that adds two integers and returns the result. Use the following Java code in the On Input tab to assign the total values for the input ports to the output port and generate an output row:
TOTAL_COMP = myTXAdd (BASE_SALARY,BONUSES);
generateRow();
When the Java transformation receives an input row, it adds the values of the BASE_SALARY and BONUSES input ports, assigns the value to the TOTAL_COMP output port, and generates an output row.
- •Java transformation API methods. You can call API methods provided by the Java transformation.
To compile the code for the Java transformation, click Compile in the Compilation properties on the On Input tab. The results of the compilation appear in the Results window on the On Input tab.
At End Tab
On the At End tab, you define how an active or passive Java transformation behaves after it processes all input data. On this tab, you can also set output data for active transformations, and call Java transformation API methods.
To define how a Java transformation behaves after it processes all input data, enter the code in the Java code window in the Code properties on the At End tab.
You can access and define the following variables and API methods on the At End tab:
- •Output port variables. You can use the names of any output ports that you defined on the Ports tab as variables, or set output data for active Java transformations.
- •Instance variables and user-defined methods. Use any instance variables or user-defined methods you declared on the Helpers tab.
- •Java transformation API methods. Call API methods provided by the Java transformation.
For example, use the following Java code to write information to the log when the end of data is reached:
logInfo("Number of null rows for partition is: " + partCountNullRows);
To compile the code for the Java transformation, click Compile in the Compilation properties on the At End tab. The results of the compilation appear in the Results window on the At End tab.
Functions Tab
On the Functions tab, you define functions that invoke expressions in a Java transformation with the Java programming language.
For example, you can define a function that invokes an expression that looks up the values of input or output ports or looks up the values of Java transformation variables.
To define a function, you can manually define functions in the Java code window in the Code properties on the Functions tab, or you can click New Function to invoke the Define Function dialog box, which enables you to easily define a function.
To compile the code, click Compile in the Compilation properties on the Functions tab. The results of the compilation appear in the Results window on the Functions tab.
Full Code Tab
On the Full Code tab, you can view, but not edit, the full class code for the Java transformation and compile the code.
You can view the full class code in the Java code window in the Code properties.
To compile the full code for the Java transformation, click Compile in the Compilation properties on the Full Code tab. The results of the compilation appear in the Results window on the Full Code tab.