Wednesday Mar 13, 2013

OWB - Compressing Files in Parallel using Java Activity

Yesterday I posted a user function for compressing/decompressing files using parallel processes in ODI. The same code you can pick up and use from an OWB process flow. Invoking the java function from within a Java activity from within the flow.

The JAR used in the example below can be downloaded here, from the process flow OWB invokes the main method within the ZipFile class for example - passing the parameters to the function for the input, output directories and also the number of threads. The parameters are passed as a string in OWB, each parameter is wrapped in ?, so we have a string like ?param1?param2?param3? and so on. In the example I pass the input directory d:\inputlogs as the first parameter and d:\outputzips as the second, the number of processes used is 4 - I have escaped my backslash in order to get this to work on Windows.

 The classpath has the JAR file with the class compiled in it and the classpath value can be specified specified on the activity, carefully escaping the path if on windows.

Then you can define the actual class to use;

That's it, pretty easy. The return value from the method will use the exit code from your java method - normally 0 is failure and other values are error (so if you exit the java using a specific error code value you can return this code into a variable in OWB or perform a complex transition condition). Any standard output/error is also capture from within the OWB activity log in the UI, for example below you can see an exception that was thrown and also messages output to the standard output/error;

 That's a quick insight to the java activity in OWB.

Monday Jun 13, 2011

OWB – Calling Java from Process Flows

Although the doc shows how to call java from process flows it still may not be clear enough..or even correct, here’s a quick illustration to plug the gap. The section on the JAVA activity is here just in case you didn’t know. Below is the simple example java class I fabricated…

public class javatest {
public static void main(String args[]) {
  System.out.println("In main of my java, with " + args.length + " arguments.");
  for (int i = 0; i < args.length; i++) {
    System.out.println("  arg  " + i + " : " + args[i]);
  if (args.length == 2) {
    int rslt = new Integer(args[0]) + new Integer(args[1]);

The java I will call is the static main method which takes an array of arguments and adds the first and second argument and uses that as the status. A silly example I know…but at least you see how parameters are passed into and out of the java call. There is also some debug to print the parameters etc so you can see where it goes in OWB. I compiled this class with JDK 1.5 (it must be 1.5 or less than) and jar’d the class file into a jar file.



The classpath, class_name and result_code parameters to the JAVA activity are pretty much standard as you would setup any activity in process flow. The parameter passing into the java activity is done via the PARAMETER_LIST activity parameter, see the value ,$(PARAM1),$(PARAM2) this uses the custom parameters PARAM1 and PARAM2 that I added to the JAVA activity in my flow.

In the above screenshot I have tried to show all of the important parts for configuring this example, the JAVA activity input parameters are bound to the process flow parameters PROC_ARG1 and PROC_ARG2 respectively.

So when I execute the flow, the arguments used will be passed to the java class. So if I pass 0 and 0 for the arguments the result of the java will be 0+0, 0 is a success code for the java activity. I can see what happened in the audit, I can see the process parameters and the activity parameters, I can also see the std output from the java, see the ‘Execution Details’ dialog and the Log panel for that output…


If I execute the process flow passing the values 1 and 2, then the result of the java is 1+2 which is an error code in java. See below for when the values 1 and 2 are passed ….


There is another parameter that has not been used and that was the RUN_DIRECTORY parameter, this is simply the working directory to where the java command is invoked from. So this is course grained integration of java using process flows, in 11gR2 its also possible to invoke EJBs from a process flow, and there are other integration techniques from java stored procedures or tables functions to java in 11gR2 Code Templates.


ETL, CDC, Real-Time DI and Data Quality for the Oracle Database from the inside.


« August 2016