Set ODI KM option value using SDK

Set ODI KM option value using SDK:

Happy New Year my friends.
Wish you all have a prosperous new year ahead. So how was the celebration ?? 😀 I know you must have enjoyed it.

Here we go the with first post of 2013. I wrote this as I got a request from Juriaan in otn forum.
As the post name says I have done this using ODI SDK.

Note: If you are copying the code you might face problem with single quote and double quote. So just replace it in your system.


package com.bhabani.OdiTool;

import java.util.Collection;
import java.util.Iterator;

import oracle.odi.core.OdiInstance;
import oracle.odi.core.config.MasterRepositoryDbInfo;
import oracle.odi.core.config.OdiInstanceConfig;
import oracle.odi.core.config.PoolingAttributes;
import oracle.odi.core.config.WorkRepositoryDbInfo;
import oracle.odi.core.persistence.transaction.ITransactionStatus;
import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition;
import oracle.odi.core.security.Authentication;
import oracle.odi.domain.project.OdiInterface;
import oracle.odi.domain.project.finder.IOdiInterfaceFinder;
import oracle.odi.interfaces.interactive.support.InteractiveInterfaceHelperWithActions;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKM.KMType;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKMOptionValue;

public class UpdateInterfaceFlowOption {
private static OdiInterface odiInterface;

public static void main(String[] args) {
String Url = "jdbc:oracle:thin:@localhost:1521:xe";
String Driver="oracle.jdbc.OracleDriver";
String Master_User="ODI_MASTER2";
String Master_Pass="odimaster2";
String WorkRep="WORKREP91";
String Odi_User="SUPERVISOR";
String Odi_Pass="SUNOPSIS";

MasterRepositoryDbInfo masterInfo = new MasterRepositoryDbInfo(Url, Driver, Master_User,Master_Pass.toCharArray(), new PoolingAttributes());
WorkRepositoryDbInfo workInfo = new WorkRepositoryDbInfo(WorkRep, new PoolingAttributes());
OdiInstance odiInstance=OdiInstance.createInstance(new OdiInstanceConfig(masterInfo,workInfo));
Authentication auth = odiInstance.getSecurityManager().createAuthentication(Odi_User,Odi_Pass.toCharArray());
odiInstance.getSecurityManager().setCurrentThreadAuthentication(auth);

ITransactionStatus trans = odiInstance.getTransactionManager().getTransaction(new DefaultTransactionDefinition());
Collection interfaces =((IOdiInterfaceFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiInterface.class)).findByProject("PRO_SCOTT", "SCD");
for (Iterator it = interfaces.iterator(); it.hasNext();)
{
odiInterface = (OdiInterface) it.next();
InteractiveInterfaceHelperWithActions helper = new InteractiveInterfaceHelperWithActions(odiInterface, odiInstance, odiInstance.getTransactionalEntityManager());
helper.performAction(new InterfaceActionSetKMOptionValue(odiInterface.getTargetDataStore(), KMType.IKM,"TRUNCATE", true));
try {helper.preparePersist();}
catch (oracle.odi.interfaces.interactive.exceptions.OdiInterfaceNotReadyForPersistException e) {e.printStackTrace();}
}
odiInstance.getTransactionalEntityManager().persist(odiInterface);
odiInstance.getTransactionManager().commit(trans);
odiInstance.close();
System.out.println("Interface Option set Completed");
}
}

Console Output

Thats all guys. Let me know how it is going.
Bhabani

About Bhabani 86 Articles
Bhabani has 12 plus years of experience in Data warehousing and Analytics projects that has span across multiple domains like Travel, Banking and Financial, Betting and Gaming Industries. Solution areas he focuses on designing the data warehouse and integrating it with cloud platforms like AWS or GCP. He is also a Elite level contributor at OTN forum more than 9 years. He loves to do experiment and POC on different integration tools and services. Some of his favorite skills are Redshift, Big Query, Python, Apache Airflow, Kafka, HDFS, Map Reduce ,HIVE, Habse, Sqoop, Drill, Impala.

7 Comments

    • You have to run it like you execute normal java file with the help of jar files in odisdk lib directory. You can take help of either command prompt or some tools like eclipse/netbeans.

  1. This code is used to modify options for the LKM, but does NOT work. I am trying to update the default values. There is a commit at the end.

    Collection myLKM = ((IOdiLKMFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiLKM.class)).findGlobalByName(v_lkmName);
    if (myLKM.size() == 0) {
    println(“Error: cannot find Global LKM [“+v_lkmName+”]”)
    }
    //else {
    // println(“Found LKM: ” +myLKM)
    //}

    for (Iterator iterator = myLKM.iterator(); iterator.hasNext();) {
    OdiLKM odiLKM = (OdiLKM) iterator.next();

    // Setting the LKM in the interface
    helper.performAction(new InterfaceActionSetKM(odiLKM, srcset, KMType.LKM, new KMOptionRetainerHomonymy()))
    // println(“Set LKM: ” +odiLKM)

    // Modify Some Options
    helper.performAction(new InterfaceActionSetKMOptionValue(srcset, KMType.LKM, “DROP_TARG_TABLE”, true));
    helper.performAction(new InterfaceActionSetKMOptionValue(srcset, KMType.LKM, “CREATE_TARG_TABLE”, true));
    helper.performAction(new InterfaceActionSetKMOptionValue(srcset, KMType.LKM, “CREATE_TARGET_PK”, true));
    helper.performAction(new InterfaceActionSetKMOptionValue(srcset, KMType.LKM, “LOAD_TABLE_OPTIONS”, v_load_table_options.toString()));
    }

    I follow this code with the same for IKM and it works perfectly, using “KMOptionRetainerLazy()” instead of “KMOptionRetainerHomonymy()”.

    Any ideas why this set LKM option is not taking the updates???

    • I have replied to your mail. Here is the code I wrote to test it and the LKM option was set correctly. Make sure you loop through the List. I just hard coded to zero for testing.
      for (Iterator it = interfaces.iterator(); it.hasNext();)
      {
      odiInterface = (OdiInterface) it.next();
      InteractiveInterfaceHelperWithActions helper = new InteractiveInterfaceHelperWithActions(odiInterface, odiInstance, odiInstance.getTransactionalEntityManager());

      for (Iterator it1 = odiInterface.getDataSets().get(0).getSourceSets().iterator(); it1.hasNext();)
      {
      SourceSet srcset = (SourceSet)it1.next();
      helper.performAction(new InterfaceActionSetKMOptionValue(srcset, KMType.LKM,”DELETE_TEMPORARY_OBJECTS”, true));
      try {helper.preparePersist();
      }
      catch (oracle.odi.interfaces.interactive.exceptions.OdiInterfaceNotReadyForPersistException e) {e.printStackTrace();}
      }}

      • Hi
        Can you please help me,
        I am creating interface using ODI SDK where I am setting LKM. But my code is not able to find any value for SourceSet.

        Below given I the method I am using:

        public static void createInterfaces(OdiInstance odiInstance, String sourceSystemName, String src, String targ, OdiFolder parentFolder, OdiContext context, String intPrefix, OdiIKM odiIKM, Map optionsIKM, OdiLKM odiLKM, Map optionsLKM, String startTScolName, String loadTScolName, String loadTSprojVar)
        {

        OdiFolder subFolder = findCreateFolder(odiInstance,parentFolder,sourceSystemName); //find or create sub folder

        OdiModel srcModel = ((IOdiModelFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiModel.class)).findByCode(sourceSystemName + “_” + src);
        OdiGlobalSubModel srcSubModel = srcModel.getGlobalSubModel();

        OdiModel targModel = ((IOdiModelFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiModel.class)).findByCode(sourceSystemName + “_” + targ);

        Iterator iSrcDataStores = srcSubModel.getDataStores().iterator();

        while (iSrcDataStores.hasNext())
        {

        OdiDataStore iSrcDataStore = (OdiDataStore) iSrcDataStores.next();

        OdiInterface iInterface = new OdiInterface(subFolder,intPrefix + “_” + iSrcDataStore.getName(),context);

        InteractiveInterfaceHelperWithActions iInterfaceHelper = new InteractiveInterfaceHelperWithActions(iInterface,odiInstance,odiInstance.getTransactionalEntityManager());

        // Set Source DataStore
        DataSet dataset = iInterface.getDataSets().get(0);

        iInterfaceHelper.performAction(new InterfaceActionAddSourceDataStore(iSrcDataStore,dataset, new AliasComputerDoubleChecker(),new ClauseImporterDefault(),new AutoMappingComputerColumnName()));

        // Set Target DataStore
        OdiDataStore iTargDataStore = ((IOdiDataStoreFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).findByName(iSrcDataStore.getName(),targModel.getCode());

        iInterfaceHelper.performAction(new InterfaceActionSetTargetDataStore(iTargDataStore, new MappingMatchPolicyColumnName(),new AutoMappingComputerColumnName(),new AutoMappingComputerColumnName(), new TargetKeyChooserLazy()));

        iInterfaceHelper.performAction(new InterfaceActionOnTargetDataStoreComputeAutoMapping());

        // For ODS tables, map metadata columns
        if (loadTSprojVar.length() > 1) {
        iInterfaceHelper.performAction(new InterfaceActionOnTargetMappingSetSql(startTScolName,loadTSprojVar,dataset) );
        iInterfaceHelper.performAction(new InterfaceActionOnTargetMappingSetSql(loadTScolName,loadTSprojVar,dataset) );
        }

        iInterfaceHelper.computeSourceSets();

        //Set IKM
        iInterfaceHelper.performAction(new InterfaceActionSetKM(odiIKM, iInterface.getTargetDataStore(), InterfaceActionSetKM.KMType.IKM, new KMOptionRetainerLazy()));

        Set iOpts = optionsIKM.keySet();

        for (Object key : iOpts) {
        iInterfaceHelper.performAction(new InterfaceActionSetKMOptionValue(iInterface.getTargetDataStore(), InterfaceActionSetKM.KMType.IKM, key.toString(), optionsIKM.get(key)));
        }

        println “Next Value ” + dataset.getSourceSets().iterator().next();
        //Set LKM
        if (odiLKM != null) {

        iOpts = optionsLKM.keySet();
        for (Object key : iOpts) {
        iInterfaceHelper.performAction(new iInterfaceHelper.performAction(new InterfaceActionSetKM(odiLKM, dataset.getSourceSets().iterator().next(), InterfaceActionSetKM.KMType.LKM, new KMOptionRetainerLazy()));
        InterfaceActionSetKMOptionValue(iInterface.getTargetDataStore(), InterfaceActionSetKM.KMType.IKM, key.toString(), optionsLKM.get(key)));
        }

        }

        iInterfaceHelper.preparePersist();
        }
        }

        I am getting java.util.NoSuchElementException error on line ‘iInterfaceHelper.performAction(new InterfaceActionSetKM(odiLKM, dataset.getSourceSets().iterator().next(), InterfaceActionSetKM.KMType.LKM, new KMOptionRetainerLazy()));’

        Please help
        Thanks
        Mangal Singh

  2. Hello,

    Thanks for sharing. I can successfully change KM option but after that when I try to execute the interface I get below error in ODI.,

    Any ideas?

    com.sunopsis.dwg.codeinterpretor.SnpGeneratorSQLCIT$SnpGeneratorException: ODI-15037: The interface I_STG_HESAP_KAPSAM_(ATS) has fatal errors.
    at com.sunopsis.dwg.codeinterpretor.SnpGeneratorSQLCIT.preComputePop(SnpGeneratorSQLCIT.java:7730)
    at com.sunopsis.dwg.codeinterpretor.SnpGeneratorSQLCIT.treatJobPop(SnpGeneratorSQLCIT.java:7642)
    at com.sunopsis.dwg.codeinterpretor.SnpGeneratorSQLCIT.mainGenPopInternal(SnpGeneratorSQLCIT.java:3259)
    at com.sunopsis.dwg.codeinterpretor.SnpGeneratorSQLCIT.mainGenPop(SnpGeneratorSQLCIT.java:3215)
    at com.sunopsis.graphical.dialog.SnpsDialogExecution.doInterfaceExecuter(SnpsDialogExecution.java:506)
    at oracle.odi.ui.action.SnpsPopupActionExecuteHandler.actionPerformed(SnpsPopupActionExecuteHandler.java:140)
    at oracle.odi.ui.SnpsFcpActionAdapter.handleEvent(SnpsFcpActionAdapter.java:292)
    at oracle.ide.controller.IdeAction.performAction(IdeAction.java:529)
    at oracle.ide.controller.IdeAction.actionPerformedImpl(IdeAction.java:897)
    at oracle.ide.controller.IdeAction.actionPerformed(IdeAction.java:501)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
    at java.awt.Component.processMouseEvent(Component.java:6297)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
    at java.awt.Component.processEvent(Component.java:6062)
    at java.awt.Container.processEvent(Container.java:2039)
    at java.awt.Component.dispatchEventImpl(Component.java:4660)
    at java.awt.Container.dispatchEventImpl(Container.java:2097)
    at java.awt.Component.dispatchEvent(Component.java:4488)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
    at java.awt.Container.dispatchEventImpl(Container.java:2083)
    at java.awt.Window.dispatchEventImpl(Window.java:2489)
    at java.awt.Component.dispatchEvent(Component.java:4488)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:674)
    at java.awt.EventQueue.access$400(EventQueue.java:81)
    at java.awt.EventQueue$2.run(EventQueue.java:633)
    at java.awt.EventQueue$2.run(EventQueue.java:631)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:647)
    at java.awt.EventQueue$3.run(EventQueue.java:645)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:644)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

    My code is:

    MasterRepositoryDbInfo masterInfo = new MasterRepositoryDbInfo(Url, Driver, Master_User,
    Master_Pass.toCharArray(), new PoolingAttributes());
    WorkRepositoryDbInfo workInfo = new WorkRepositoryDbInfo(WorkRep, new PoolingAttributes());
    OdiInstance odiInstance = OdiInstance.createInstance(new OdiInstanceConfig(masterInfo, workInfo));
    Authentication auth = odiInstance.getSecurityManager().createAuthentication(Odi_User, Odi_Pass.toCharArray());
    odiInstance.getSecurityManager().setCurrentThreadAuthentication(auth);
    ITransactionStatus trans = odiInstance.getTransactionManager()
    .getTransaction(new DefaultTransactionDefinition());

    OdiInterface odiInterface = (OdiInterface) ((IOdiInterfaceFinder) odiInstance.getTransactionalEntityManager()
    .getFinder(OdiInterface.class)).findByName(“I_STG_HESAP_KAPSAM_(ATS)”, Project_Code).iterator().next();

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

    helper.performAction(
    new InterfaceActionSetKMOptionValue(odiInterface.getTargetDataStore(), KMType.IKM, “TRUNCATE”, false));
    try {
    helper.preparePersist();
    } catch (oracle.odi.interfaces.interactive.exceptions.OdiInterfaceNotReadyForPersistException e) {
    e.printStackTrace();
    }

    odiInstance.getTransactionalEntityManager().persist(odiInterface);
    odiInstance.getTransactionManager().commit(trans);

    odiInstance.close();
    System.out.println(“Interface Option set Completed”);

  3. I solved the issue, I added:

    try {
    helper.computeSourceSets();
    } catch (InexistentMappingException e) {
    throw new OdiRuntimeException(e);
    }

    before:

    try {
    helper.preparePersist();
    } catch (oracle.odi.interfaces.interactive.exceptions.OdiInterfaceNotReadyForPersistException e) {
    e.printStackTrace();
    }

    and problem solved.

Comments are closed.