Posted by: michaelverzijl | 27/02/2012

ODI Working with Groovy editor

One of the new enhancements of Oracle Data Integrator is a Groovy Editor.
From the documentation:

The Groovy editor provides a single environment for creating, editing, and executing Groovy scripts within the ODI Studio context. It provides all standard features of a code editor such as syntax highlighting and common code editor commands.

Building interfaces through the ODI SDK was also available in previous releases, but you needed external tooling like Eclipse Editor for this.

Once ODI Studio is opnend you can find the Editor on the Tools menu (Tools -> Groovy -> New Script):

So what can you do with this editor?

With this editor you can create scripts to populate the ODI repository. A complete SDK can be installed while installing ODI to your machine.

In this post I will be using the Groovy Editor to create an interface between a source table and a staging table.
Because I was unfamiliar with Groovy I did some research and used these sites:

So before we start the script we need to import classes provided by Oracle:

// Context operators:
import oracle.odi.domain.topology.OdiContext
import oracle.odi.domain.topology.finder.IOdiContextFinder

// Folder operators:
import oracle.odi.domain.project.OdiFolder
import oracle.odi.domain.project.finder.IOdiFolderFinder

// Interface operators:
import oracle.odi.domain.project.OdiInterface

// Interface helpers:

// Transaction operators:
import oracle.odi.core.persistence.transaction.ITransactionDefinition;
import oracle.odi.core.persistence.transaction.ITransactionManager;
import oracle.odi.core.persistence.transaction.ITransactionStatus;

// Data set:
import oracle.odi.domain.project.interfaces.DataSet;

// Data store:
import oracle.odi.domain.model.OdiDataStore;
import oracle.odi.domain.model.finder.IOdiDataStoreFinder;

For this project I defined 2 vars:

// Define VARS:
def project = new String("Staging") // What is the target project?
def folder = new String("Source_1") // Which folder in target project?

Just like the blog from Oracle, a file is created which specifies the interface/source etc:

def file = new File('e:/interfaces.txt')
def s = 0

The file looks like this:


So now for the Real code:

// Get default context:
OdiContext context = ((IOdiContextFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class)).findDefaultContext();

// Get Folder:
Collection odiFolders = ((IOdiFolderFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiFolder.class)).findByName(folder);
if (odiFolders.size() == 0)
  println("Error: cannot find folder "+folder+" in project "+project)
OdiFolder odiFolder = (OdiFolder) (odiFolders.toArray()[0]);

// Print default settings:
println ("Context used = " + context.getName())
println ("Folder for interface = " + odiFolder.getName())

file.eachLine { line ->
        toks = line.split(",")

        if (toks.length != 5)
          println("Error in input, line: "+s)
          iname = toks[0]
          srcmodel = toks[1]
          srctab = toks[2]
          tgtmodel = toks[3]
          tgttab = toks[4]

          // Transactie:
          ITransactionDefinition txnDef = new DefaultTransactionDefinition()
          ITransactionManager tm = odiInstance.getTransactionManager()
          ITransactionStatus txnStatus = tm.getTransaction(txnDef)

          OdiInterface odiInterface = new OdiInterface(odiFolder, iname, context);

          InteractiveInterfaceHelperWithActions interactiveHelper = new InteractiveInterfaceHelperWithActions(odiInterface, odiInstance, odiInstance.getTransactionalEntityManager());

          DataSet dataSet = odiInterface.getDataSets().get(0);
          OdiDataStore odiDatastore1 = ((IOdiDataStoreFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).findByName(srctab, srcmodel);
          OdiDataStore targetDatastore = ((IOdiDataStoreFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).findByName(tgttab, tgtmodel);

          interactiveHelper.performAction(new InterfaceActionAddSourceDataStore(odiDatastore1, dataSet, new AliasComputerDoubleChecker(), new ClauseImporterLazy(), new AutoMappingComputerLazy()));
          interactiveHelper.performAction(new InterfaceActionSetTargetDataStore(targetDatastore, new MappingMatchPolicyLazy(), new AutoMappingComputerLazy(), new AutoMappingComputerLazy(), new TargetKeyChooserPrimaryKey()));

          interactiveHelper.performAction(new InterfaceActionOnTargetDataStoreComputeAutoMapping())


So what have we done?

We created an interface between two datastores with the default Knowledge Modules selected.
Building default interfaces is now as easy as running a script within Oracle Data Integrator.

A log file is also created

context used = Development
Folder for interface = Source_1
Interface INTFC1 created

I’m not a Groovy/Java expert so I’ve done my best. Tips? Please help me!


  1. Hi Michael

    Good to see you using the groovy console, it’s a great way for accelerated development.


  2. “ODI Working with Groovy editor | Michael Verzijl Blog”
    truly got me personally hooked on ur web-site!
    I reallywill probably wind up being returning much more regularly.
    Thanks ,Lesli

  3. Thanks for this post Michael. I have a quick question for you. How do you debug in ODI Groovy editor. I have done some println stuff but can’t seem to visualize them. Any pointer

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: