<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ODI Experts</title>
	<atom:link href="http://odiexperts.com/feed" rel="self" type="application/rss+xml" />
	<link>http://odiexperts.com</link>
	<description>The  blog  for  Oracle  Data  Integrator</description>
	<lastBuildDate>Fri, 06 Jan 2012 19:10:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Generate All Scenario for a Particular Project using ODI SDK</title>
		<link>http://odiexperts.com/generate-all-scenario-for-a-particular-project-using-odi-sdk</link>
		<comments>http://odiexperts.com/generate-all-scenario-for-a-particular-project-using-odi-sdk#comments</comments>
		<pubDate>Fri, 06 Jan 2012 00:00:51 +0000</pubDate>
		<dc:creator>Kshitiz Devendra</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[ODI]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[ODI SDK]]></category>
		<category><![CDATA[PROJECT]]></category>
		<category><![CDATA[REGENERATE]]></category>
		<category><![CDATA[scenario]]></category>

		<guid isPermaLink="false">http://odiexperts.com/?p=3250</guid>
		<description><![CDATA[Hi Friends! First of all HAPPY NEW YEAR! We, from ODI Experts, hope that 2012 be a fantastic year for all of you! Continuing our &#8220;Java code series&#8221; take a look on this new one. The below code is used to Generate/Regenerate  All Scenario and depending on the options the appropriate ODI Objects scenario will [...]]]></description>
			<content:encoded><![CDATA[<p>Hi Friends!</p>
<p>First of all HAPPY NEW YEAR!</p>
<p>We, from ODI Experts, hope that 2012 be a fantastic year for all of you!</p>
<p>Continuing our &#8220;Java code series&#8221; take a look on this new one.</p>
<p>The below code is used to Generate/Regenerate  All Scenario and depending on the options the appropriate ODI Objects scenario will be generated/regenerated.</p>
<p>Also make sure you use the appropriate Generating option  i.e INCREMENTAL_MODE (OR)  REGENERATE_MODE (OR)   REPLACE_MODE</p>
<p>GenerationOptions options=new GenerationOptions(<span style="color: #ff0000;"><em><strong>GenerationOptions.INCREMENTAL_MODE</strong></em></span>, GenerateFromPackage, GenerateFromInterface, GenerateFromProcedure, GenerateFromVariable);</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:94ab558f-c3e3-43c1-979c-afef47c91865" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: java;">package odi.sdk;

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.OdiFolder;
import oracle.odi.domain.project.OdiProject;
import oracle.odi.domain.project.finder.IOdiProjectFinder;
import oracle.odi.domain.runtime.scenario.OdiScenario;
import oracle.odi.generation.GenerationOptions;
import oracle.odi.generation.support.OdiScenarioGeneratorImpl;
import oracle.odi.impexp.EncodingOptions;
import oracle.odi.impexp.support.ExportServiceImpl;

public class RegenrateAllScen {

    private static String Project_Code;
    private static OdiProject project;
    private static String   Folder_Name;
    private static OdiFolder folder;

    /**
     * @param args
     */
    public static void main(String[] args) {

         /****** Please change these Parameters *********/

        /** Development Repository ****/    

         String Url = "jdbc:oracle:thin:@localhost:1521:xe";
         String Driver="oracle.jdbc.OracleDriver";
         String Master_User="ODI_MASTER_11G";
         String Master_Pass="ODI_MASTER_11G";
         String WorkRep="WORKREP1";
         String Odi_User="SUPERVISOR";
         String Odi_Pass="SUNOPSIS";

      // Generating ODI Objects options

         Boolean GenerateFromInterface     = true;
         Boolean GenerateFromPackage       = true;
         Boolean GenerateFromProcedure     = true;
         Boolean GenerateFromVariable      = true;

         Project_Code   ="XMT";

         /********************************************/

 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());

//Regenerating All Scenario by Project
// Get Project
project = ((IOdiProjectFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiProject.class)).findByCode(Project_Code);

OdiScenarioGeneratorImpl generatescen=new OdiScenarioGeneratorImpl(odiInstance);
//
// Please change your Generating Option ie INCREMENTAL (or) REGENERATE (or) REPLACE
//
GenerationOptions options=new GenerationOptions(GenerationOptions.INCREMENTAL_MODE, GenerateFromPackage, GenerateFromInterface, GenerateFromProcedure, GenerateFromVariable);
OdiScenario[] scen =generatescen.generateAllScenarios(project, options);
for (OdiScenario odiScenario : scen) {
    System.out.println( options.getMode()+" Generating Scenario  " +odiScenario.getName()+"\t"+odiScenario.getVersion());
}

odiInstance.getTransactionManager().commit(trans);
System.out.println("Commiting Changes \n Process Completed");
odiInstance.close();

    }

}</pre>
<pre class="brush: java;"></pre>
<p>Keeping visinting us!</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://odiexperts.com/generate-all-scenario-for-a-particular-project-using-odi-sdk/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interface with Union, Minus Operator using ODI SDK</title>
		<link>http://odiexperts.com/interface-with-union-minus-operator-using-odi-sdk</link>
		<comments>http://odiexperts.com/interface-with-union-minus-operator-using-odi-sdk#comments</comments>
		<pubDate>Tue, 13 Dec 2011 16:23:11 +0000</pubDate>
		<dc:creator>Kshitiz Devendra</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[Java Codes]]></category>
		<category><![CDATA[ODI]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Interface]]></category>
		<category><![CDATA[MINUS]]></category>
		<category><![CDATA[ODI SDK]]></category>
		<category><![CDATA[Operator]]></category>
		<category><![CDATA[UNION]]></category>

		<guid isPermaLink="false">http://odiexperts.com/?p=3249</guid>
		<description><![CDATA[Howdy guys! Keeping the Java series, here is more one Java Code for ODI. The below codes is used to create an Interface that can create Multiple Dataset depending on the source datastore and Operator provided. For example &#8211; Here String[] source_datastore={&#8220;REGIONS&#8221;,&#8221;REGIONS&#8221;,&#8221;REGIONS&#8221;}; we are using three different source tables ,you can change them and provide [...]]]></description>
			<content:encoded><![CDATA[<p>Howdy guys!</p>
<p>Keeping the Java series, here is more one Java Code for ODI.</p>
<p>The below codes is used to create an Interface that can create Multiple Dataset depending on the source<br />
datastore and Operator provided.<br />
For example &#8211; Here<br />
String[] source_datastore={&#8220;REGIONS&#8221;,&#8221;REGIONS&#8221;,&#8221;REGIONS&#8221;};</p>
<p>we are using three different source tables ,you can change them and provide any number of Source datastore in the array and accordingly n number of the Dataset are created.</p>
<p>String[] operator={&#8220;UNION&#8221;,&#8221;MINUS&#8221;};</p>
<p>For n number of the source database , n-1 number of the Operator needs to be provided.<br />
For example if there are 4 different source datastore , then 3 operator need to provided which can be same or different depending on your requirement.</p>
<pre class="brush: java;">package odi.sdk;

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.exception.OdiRuntimeException;
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.model.OdiDataStore;
import oracle.odi.domain.model.finder.IOdiDataStoreFinder;
import oracle.odi.domain.project.OdiCKM;
import oracle.odi.domain.project.OdiFolder;
import oracle.odi.domain.project.OdiIKM;
import oracle.odi.domain.project.OdiInterface;
import oracle.odi.domain.project.OdiLKM;
import oracle.odi.domain.project.ProcedureOption;
import oracle.odi.domain.project.finder.IOdiCKMFinder;
import oracle.odi.domain.project.finder.IOdiFolderFinder;
import oracle.odi.domain.project.finder.IOdiIKMFinder;
import oracle.odi.domain.project.finder.IOdiLKMFinder;
import oracle.odi.domain.project.interfaces.DataSet;
import oracle.odi.domain.project.interfaces.SourceDataStore;
import oracle.odi.domain.project.interfaces.SourceSet;
import oracle.odi.domain.topology.OdiContext;
import oracle.odi.domain.topology.finder.IOdiContextFinder;
import oracle.odi.interfaces.interactive.support.InteractiveInterfaceHelperWithActions;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionOnTargetDataStoreComputeAutoMapping;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKM;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKM.KMType;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKMOptionValue;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetTargetDataStore;
import oracle.odi.interfaces.interactive.support.km.optionretainer.KMOptionRetainerHomonymy;
import oracle.odi.interfaces.interactive.support.km.optionretainer.KMOptionRetainerLazy;
import oracle.odi.interfaces.interactive.support.mapping.automap.AutoMappingComputerLazy;
import oracle.odi.interfaces.interactive.support.mapping.matchpolicy.MappingMatchPolicyLazy;
import oracle.odi.interfaces.interactive.support.sourceset.creators.InexistentMappingException;
import oracle.odi.interfaces.interactive.support.targetkeychoosers.TargetKeyChooserPrimaryKey;

public class PermanentInterfaceWithUnion {

    private static String Project_Code;
    private static String Folder_Name;
    private static OdiFolder folder;
    private static String Context_Code;
    private static OdiContext context;
    private static OdiDataStore sourceDatastore;
    private static String target_model_name;
    private static String source_model_name;
    private static String LKM;
    private static String IKM;
    private static String CKM;
    private static String target_datastore;
    private static SourceSet srcset;
    private static SourceDataStore sd;
    private static DataSet dataset;

    /**
     * @param args
     */
    public static void main(String[] args) {

              /****** Please change these Parameters *********/

        String Url = "jdbc:oracle:thin:@localhost:1521:xe";
        String Driver="oracle.jdbc.OracleDriver";
        String Master_User="ODI_MASTER_11G";
        String Master_Pass="ODI_MASTER_11G";
        String WorkRep="WORKREP1";
        String Odi_User="SUPERVISOR";
        String Odi_Pass="SUNOPSIS";

        Project_Code="XMT";
        Context_Code="XMT";
        Folder_Name="FOLDER";
        source_model_name = "SRCE_HR";
        String[] source_datastore={"REGIONS","REGIONS","REGIONS"};
        String[] operator={"UNION","MINUS"};
        target_model_name = "TRGT_HR";
        target_datastore="REGIONS";

        LKM ="LKM SQL to Oracle";
        IKM ="IKM SQL Control Append";
        CKM ="CKM Oracle";

                /*****************************/

        // Connection
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());

        // Find the folder

        Collection&lt;OdiFolder&gt; fold = ((IOdiFolderFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiFolder.class)).findByName(Folder_Name);
        for (Iterator&lt;OdiFolder&gt; it = fold.iterator(); it.hasNext();) {
            folder = (OdiFolder) it.next();
        }

        // Find the Context
        context = ((IOdiContextFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class)).findByCode(Context_Code);

        OdiDataStore targetDatastore = ((IOdiDataStoreFinder)odiInstance.getTransactionalEntityManager().
                getFinder(OdiDataStore.class)).findByName(target_datastore, target_model_name);

        System.out.println("Interface Creation Started for ..."+ target_datastore);
        // Creating a New Interface
        OdiInterface intf = new OdiInterface(folder, target_datastore, context);

        // Setting the above Context as the Optimization Context
                intf.setOptimizationContext(context);

        // Reading the Source Data Store
        // Find the Data store using the IOdiDataStoreFinder
        int order=0;
        for (int i=0 ;i&lt;source_datastore.length ;i++) {

            sourceDatastore = ((IOdiDataStoreFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).
                    findByName(source_datastore[i], source_model_name);

            // Creating DataSet to automatically assign different
            // Source Data store
            // DataSet(OdiInterface pInterface, java.lang.String pName)
            if (i == 0) {
                dataset = intf.getDataSets().iterator().next();
                dataset.setName("DATASET"+i);

            } else {
            dataset=new DataSet(intf,"DATASET"+i);
            dataset.setOperator(operator[i-1]);
            dataset.setOrder(order);
            }

            srcset = new SourceSet("SrcSet01",dataset);
            sd=new SourceDataStore(dataset,false,sourceDatastore.getName().toString(),0,sourceDatastore);
            srcset.addSourceDataStore(sd);
            dataset.addSourceSet(srcset);
            order+=10;

        }

        // Helper is to manipulate Odi interfaces in an
        // interactive way

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

        helper.performAction(new InterfaceActionSetTargetDataStore(
                targetDatastore, new MappingMatchPolicyLazy(),
                new AutoMappingComputerLazy(),
                new AutoMappingComputerLazy(),
                new TargetKeyChooserPrimaryKey()));

        helper.performAction(new InterfaceActionOnTargetDataStoreComputeAutoMapping());

        // Add the Filter
        //helper.performAction(new InterfaceActionAddFilter(dataset, sd.getName(),ExecutionLocation.WORK));

        // Start mapping the KM
        // LKM
        Collection&lt;OdiLKM&gt; lkm1 = ((IOdiLKMFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiLKM.class)).findByName(
                        LKM,Project_Code);

        for (Iterator&lt;OdiLKM&gt; iterator = lkm1.iterator(); iterator.hasNext();) {
            OdiLKM odiLKM = (OdiLKM) iterator.next();
            helper.performAction(new InterfaceActionSetKM(odiLKM,srcset, KMType.LKM,new KMOptionRetainerHomonymy()));

            // Fetching each option of the LKM
            for (ProcedureOption c : odiLKM.getOptions()) {
                helper.performAction(new InterfaceActionSetKMOptionValue(srcset, KMType.LKM,"DELETE_TEMPORARY_INDEXES", true));
            }
        }

        // IKM
        // Find the IKM using the IOdiIKMFinder

        Collection&lt;OdiIKM&gt; ikm1 = ((IOdiIKMFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiIKM.class)).findByName(
                        IKM,Project_Code);

        for (Iterator&lt;OdiIKM&gt; iterator = ikm1.iterator(); iterator.hasNext();) {
            OdiIKM odiIKM = (OdiIKM) iterator.next();

            // Setting the IKM in the interface
            helper.performAction(new InterfaceActionSetKM(odiIKM, intf.getTargetDataStore(),KMType.IKM, new KMOptionRetainerLazy()));

            // Fetching each option of the IKM
            for (ProcedureOption c : odiIKM.getOptions()) {

                // Modifying the Options of the IKM in the
                // Interface
                helper.performAction(new InterfaceActionSetKMOptionValue(intf.getTargetDataStore(), KMType.IKM,
                        "FLOW_CONTROL", false));

                helper.performAction(new InterfaceActionSetKMOptionValue(intf.getTargetDataStore(), KMType.IKM,
                        "STATIC_CONTROL", true));

            }
        }

        // CKM
        Collection&lt;OdiCKM&gt; ckm1 = ((IOdiCKMFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiCKM.class)).findByName(
                CKM,Project_Code);

        for (Iterator&lt;OdiCKM&gt; iterator = ckm1.iterator(); iterator.hasNext();) {
            OdiCKM odiCKM = (OdiCKM) iterator.next();
            helper.performAction(new InterfaceActionSetKM(odiCKM, intf.getTargetDataStore(),KMType.CKM, new KMOptionRetainerLazy()));
        }

        // Compute the Interface sourceset

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

        // Persisting the Interface
        // Called to inform the ODI persistence layer that this
        // interface will be persisted
        try {helper.preparePersist();}
        catch (oracle.odi.interfaces.interactive.exceptions.OdiInterfaceNotReadyForPersistException e) {e.printStackTrace();}

        odiInstance.getTransactionalEntityManager().persist(intf);

        /*// Generating Scenarios

        System.out.println("Generating Scenario for .."+ target_datastore );
        IOdiScenarioGenerator gene = new OdiScenarioGeneratorImpl(odiInstance);
        OdiScenario newScen = gene.generateScenario(intf,target_datastore, "001");
        odiInstance.getTransactionalEntityManager().persist(newScen);*/

        // Finally close the Instance
        odiInstance.getTransactionManager().commit(trans);
        odiInstance.close();

        System.out.println("Process Completed");
    }

}</pre>
<p style="text-align: center;"><a href="http://odiexperts.com/wp-content/uploads/2011/11/ScreenClip2.png"><img class="aligncenter" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-style: initial; border-color: initial; border-width: 0px;" title="ScreenClip(2)" src="http://odiexperts.com/wp-content/uploads/2011/11/ScreenClip2_thumb.png" alt="ScreenClip(2)" width="644" height="216" border="0" /></a></p>
<p style="text-align: center;"><strong><a href="http://odiexperts.com/wp-content/uploads/2011/11/ScreenClip3.png"><img class="aligncenter" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-style: initial; border-color: initial; border-width: 0px;" title="ScreenClip(3)" src="http://odiexperts.com/wp-content/uploads/2011/11/ScreenClip3_thumb.png" alt="ScreenClip(3)" width="608" height="427" border="0" /></a> </strong></p>
<p style="text-align: left;">As you know, comments are always really welcome!</p>
<p style="text-align: left;">Good to see you here.</p>
]]></content:encoded>
			<wfw:commentRss>http://odiexperts.com/interface-with-union-minus-operator-using-odi-sdk/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Export and Importing Scenarios based on Project (or)Folder</title>
		<link>http://odiexperts.com/export-and-importing-scenarios-based-on-project-orfolder</link>
		<comments>http://odiexperts.com/export-and-importing-scenarios-based-on-project-orfolder#comments</comments>
		<pubDate>Mon, 28 Nov 2011 00:32:32 +0000</pubDate>
		<dc:creator>Kshitiz Devendra</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[Logic]]></category>
		<category><![CDATA[ODI]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Export]]></category>
		<category><![CDATA[FOLDER]]></category>
		<category><![CDATA[Import]]></category>
		<category><![CDATA[ODI Scenario]]></category>
		<category><![CDATA[ODI_SDK]]></category>
		<category><![CDATA[PROJECT]]></category>
		<category><![CDATA[scenario]]></category>

		<guid isPermaLink="false">http://odiexperts.com/?p=3251</guid>
		<description><![CDATA[Hi Everyone, Keeping our &#8220;java series&#8221; we have one more piece of code to share. I hope you &#8220;enjoy&#8221; it! The below code is used to Export and Import all the Scenario from Development Work Rep to Execution Work Rep . For Export there are 3 different options either Export all the scenario For a Project [...]]]></description>
			<content:encoded><![CDATA[<p>Hi Everyone,</p>
<p>Keeping our &#8220;java series&#8221; we have one more piece of code to share.</p>
<p>I hope you &#8220;enjoy&#8221; it!</p>
<p>The below code is used to Export and Import all the Scenario from Development Work Rep to Execution Work Rep .</p>
<p>For Export there are 3 different options either Export all the scenario</p>
<ul>
<li>For a Project (or)</li>
<li>For a Folder (or)</li>
<li>Scenarios matching a particular Time period .</li>
</ul>
<p><span style="color: #ff0000;">Note : &#8211; Make sure you either delete the folder or delete all the scenario inside the Export Folder once successful import is done .</span></p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:9d03ceea-3141-4f9a-b6cb-b308a832d135" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: java;">package odi.sdk;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
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.IOdiScenarioSourceContainer;
import oracle.odi.domain.project.OdiFolder;
import oracle.odi.domain.project.OdiProject;
import oracle.odi.domain.project.finder.IOdiFolderFinder;
import oracle.odi.domain.project.finder.IOdiProjectFinder;
import oracle.odi.domain.runtime.scenario.OdiScenario;
import oracle.odi.domain.runtime.scenario.finder.IOdiScenarioFinder;
import oracle.odi.impexp.EncodingOptions;
import oracle.odi.impexp.OdiImportException;
import oracle.odi.impexp.support.ExportServiceImpl;
import oracle.odi.impexp.support.ImportServiceImpl;

public class ExportImport {

     private static String Project_Code;
     private static OdiProject project;
     private static String   Folder_Name;
     private static OdiFolder folder;

     /**
     * @param args
     * @throws IOException
     * @throws OdiImportException
     * @throws ParseException
     */

    public static void main(String[] args) throws IOException, OdiImportException, ParseException {

     /****** Please change these Parameters *********/

    /** Development Repository ****/    

     String Url = "jdbc:oracle:thin:@localhost:1521:xe";
     String Driver="oracle.jdbc.OracleDriver";
     String Master_User="ODI_MASTER_11G";
     String Master_Pass="ODI_MASTER_11G";
     String WorkRep="WORKREP1";
     String Odi_User="SUPERVISOR";
     String Odi_Pass="SUNOPSIS";

     /*** Execution Repository ***/
     // In case if your Execution rep is linked to a different Master repository please appropriately create new variables
     // The present codes assumes that Development and Execution are linked to the same Master Repository.

     String WorkRep_Execution="WORKREP_EXECUTION";

     /***************************************************/

     //Exporting Scenario Options

     String ExportFolderPath="/home/oracle/Documents/ODIExport";

     // While providing path in windows make sure you use \\
     Boolean ExportPackageScen      = true;
     Boolean ExportInterfaceScen    = true;
     Boolean ExportProcedureScen    = true;
     Boolean ExportVariableScen     = false;
     Boolean RecursiveExport        = true;
     Boolean OverWriteFile          = true;

     Project_Code   ="XMT";
     Folder_Name    ="FOLDER2";

     // Date based on which the scenario is compared
     SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy");
     Date date =df.parse("11-23-2011");

     /********************************************/

MasterRepositoryDbInfo masterInfo = new MasterRepositoryDbInfo(Url, Driver, Master_User,Master_Pass.toCharArray(), new PoolingAttributes());

/// Development Repository
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());

//Execution Repository

WorkRepositoryDbInfo workInfo_exec = new WorkRepositoryDbInfo(WorkRep_Execution, new PoolingAttributes());
OdiInstance odiInstance_exec=OdiInstance.createInstance(new OdiInstanceConfig(masterInfo,workInfo_exec));
Authentication auth_exec = odiInstance_exec.getSecurityManager().createAuthentication(Odi_User,Odi_Pass.toCharArray());
odiInstance_exec.getSecurityManager().setCurrentThreadAuthentication(auth_exec);
ITransactionStatus trans_exec = odiInstance_exec.getTransactionManager().getTransaction(new DefaultTransactionDefinition());

        //Export All Scenario by Project
        // Get Project
        project = ((IOdiProjectFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiProject.class)).findByCode(Project_Code);
        ExportServiceImpl export=new ExportServiceImpl(odiInstance);
        EncodingOptions EncdOption = new EncodingOptions();
        System.out.println( " Exporting all Scenario for the Project " +Project_Code);
        export.exportAllScenarii(project, ExportFolderPath, ExportPackageScen, ExportInterfaceScen, ExportProcedureScen, ExportVariableScen, EncdOption, RecursiveExport, OverWriteFile);    

        // ( or )

        // Export All Scenario by Folder
        // Find the folder
        Collection&lt;OdiFolder&gt; fold = ((IOdiFolderFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiFolder.class)).findByName(Folder_Name, Project_Code);
        for (Iterator&lt;OdiFolder&gt; it = fold.iterator(); it.hasNext();) {
             folder = (OdiFolder) it.next();
        }

        ExportServiceImpl export=new ExportServiceImpl(odiInstance);
        EncodingOptions EncdOption = new EncodingOptions();
        System.out.println( " Exporting all Scenario for the Project " +Project_Code+ " and Folder "+Folder_Name);
        export.exportAllScenarii(folder, ExportFolderPath, ExportPackageScen, ExportInterfaceScen, ExportProcedureScen, ExportVariableScen, EncdOption, RecursiveExport, OverWriteFile);    

        // ( or )

        // Export Selected Scenario based on date

        ExportServiceImpl export=new ExportServiceImpl(odiInstance);
        EncodingOptions EncdOption = new EncodingOptions();

        //Reading all scenario

        Collection odiscen= ((IOdiScenarioFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiScenario.class)).findAll();
        for (Object scen : odiscen) {
            OdiScenario odiscenario =(OdiScenario)scen ;
            if (odiscenario.getLastDate().before(date)) {
                System.out.println(" Exporting scenario  "+odiscenario.getName());
                export.exportToXml(odiscenario, ExportFolderPath, OverWriteFile, RecursiveExport, EncdOption);
            }
        }

        //Importing Scenarios in INSERT_UPDATE Mode
        // The below code import all the scenarios present in the Exported Folder path , so make sure older files are deleted
        ImportServiceImpl importsrvc=new ImportServiceImpl(odiInstance_exec);
        String[] XMLFiles=getXMLFiles(ExportFolderPath).split("\n");
        for (String xmlfile : XMLFiles) {
            System.out.println(" Importing scenario  XML "+xmlfile);
            importsrvc.importObjectFromXml(importsrvc.IMPORT_MODE_SYNONYM_INSERT_UPDATE, xmlfile, true);
        }

       // Commit and Close Transaction
       odiInstance.close();
       odiInstance_exec.getTransactionManager().commit(trans_exec);
       odiInstance_exec.close();

    }

    //Reading all the XML Files
    public static String getXMLFiles(String DirectoryName){

        String xmlfiles="";
        String files;
        File folder = new File(DirectoryName);
        File[] listOfFiles = folder.listFiles();
          for (int i = 0; i &lt; listOfFiles.length; i++)
          {
           if (listOfFiles[i].isFile())
           {
           files = listOfFiles[i].getName();
               if (files.endsWith(".xml") || files.endsWith(".XML"))
               {
                   xmlfiles+=DirectoryName+"/"+files+"\n";
                }
           }}
        return xmlfiles;
  }

}</pre>
<p class="brush: java;">Good to see you around and please, keep visiting us!</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://odiexperts.com/export-and-importing-scenarios-based-on-project-orfolder/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Creating Interface for Single Source and Target</title>
		<link>http://odiexperts.com/creating-interface-for-single-source-and-target</link>
		<comments>http://odiexperts.com/creating-interface-for-single-source-and-target#comments</comments>
		<pubDate>Thu, 17 Nov 2011 02:53:43 +0000</pubDate>
		<dc:creator>Kshitiz Devendra</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[ODI]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://odiexperts.com/?p=3158</guid>
		<description><![CDATA[This particular Code generate Interface and Scenario for one single Source and Target. By default the target datastore name is used as the Interface Name package odi_sdk; import java.util.Collection; import java.util.HashSet; 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.exception.OdiRuntimeException; 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.model.OdiDataStore; import oracle.odi.domain.model.finder.IOdiDataStoreFinder; [...]]]></description>
			<content:encoded><![CDATA[<p>This particular Code generate Interface and Scenario for one single Source and Target. By default the target datastore name is used as the Interface Name</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:d044d00a-b63a-489c-bda1-0855a9b7c647" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: java">package odi_sdk;

import java.util.Collection;
import java.util.HashSet;
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.exception.OdiRuntimeException;
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.model.OdiDataStore;
import oracle.odi.domain.model.finder.IOdiDataStoreFinder;
import oracle.odi.domain.project.OdiCKM;
import oracle.odi.domain.project.OdiFolder;
import oracle.odi.domain.project.OdiIKM;
import oracle.odi.domain.project.OdiInterface;
import oracle.odi.domain.project.OdiLKM;
import oracle.odi.domain.project.ProcedureOption;
import oracle.odi.domain.project.finder.IOdiCKMFinder;
import oracle.odi.domain.project.finder.IOdiFolderFinder;
import oracle.odi.domain.project.finder.IOdiIKMFinder;
import oracle.odi.domain.project.finder.IOdiLKMFinder;
import oracle.odi.domain.project.interfaces.DataSet;
import oracle.odi.domain.project.interfaces.SourceDataStore;
import oracle.odi.domain.project.interfaces.SourceSet;
import oracle.odi.domain.runtime.scenario.OdiScenario;
import oracle.odi.domain.topology.OdiContext;
import oracle.odi.domain.topology.finder.IOdiContextFinder;
import oracle.odi.generation.IOdiScenarioGenerator;
import oracle.odi.generation.support.OdiScenarioGeneratorImpl;
import oracle.odi.interfaces.interactive.support.InteractiveInterfaceHelperWithActions;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionOnTargetDataStoreComputeAutoMapping;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKM;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKM.KMType;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKMOptionValue;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetTargetDataStore;
import oracle.odi.interfaces.interactive.support.km.optionretainer.KMOptionRetainerHomonymy;
import oracle.odi.interfaces.interactive.support.km.optionretainer.KMOptionRetainerLazy;
import oracle.odi.interfaces.interactive.support.mapping.automap.AutoMappingComputerLazy;
import oracle.odi.interfaces.interactive.support.mapping.matchpolicy.MappingMatchPolicyLazy;
import oracle.odi.interfaces.interactive.support.sourceset.creators.InexistentMappingException;
import oracle.odi.interfaces.interactive.support.targetkeychoosers.TargetKeyChooserPrimaryKey;

public class PermanentInterface {

	private static String Project_Code;
	private static String Folder_Name;
	private static OdiFolder folder;
	private static String Context_Code;
	private static OdiContext context;
	private static OdiDataStore sourceDatastore;
	private static OdiInterface odiInterface;
	private static String target_model_name;
	private static String source_model_name;
	private static String LKM;
	private static String IKM;
	private static String CKM;
	private static String source_datastore;
	private static String target_datastore;

	/**
	 * @param args
	 */
	public static void main(String[] args) {

              /****** Please change these Parameters *********/

		String Url = "jdbc:oracle:thin:@localhost:1521:orcl";
		String Driver="oracle.jdbc.OracleDriver";
		String Master_User="ODI_MASTER_11G";
		String Master_Pass="ODI_MASTER_11G";
		String WorkRep="WORKREP1";
		String Odi_User="SUPERVISOR";
		String Odi_Pass="SUNOPSIS";

                Project_Code="XMT";
		Context_Code="XMT";
		Folder_Name="FOLDER";
		source_model_name = "SRCE_HR";
		source_datastore="REGIONS";
		target_model_name = "TRGT_HR";
		target_datastore="REGIONS";

		LKM ="LKM SQL to Oracle";
		IKM ="IKM SQL Control Append";
		CKM ="CKM Oracle";

                /*****************************/

		// Connection
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());

		// Find the folder

		Collection fold = ((IOdiFolderFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiFolder.class)).findByName(Folder_Name);
		for (Iterator it = fold.iterator(); it.hasNext();) {
			folder = (OdiFolder) it.next();
		}

		// Find the Context
		context = ((IOdiContextFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class)).findByCode(Context_Code);

		OdiDataStore targetDatastore = ((IOdiDataStoreFinder)odiInstance.getTransactionalEntityManager().
                getFinder(OdiDataStore.class)).findByName(target_datastore, target_model_name);
		// Reading the Source Data Store
		// Find the Data store using the IOdiDataStoreFinder
		sourceDatastore = ((IOdiDataStoreFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).
                findByName(source_datastore, source_model_name);

		System.out.println("Interface Creation Started for ..."+ target_datastore);
		// Creating a New Interface
		OdiInterface intf = new OdiInterface(folder, target_datastore, context);

		// Setting the above Context as the Optimization Context
		intf.setOptimizationContext(context);

		// Creating DataSet to automatically assign different
		// Source Data store
		// DataSet(OdiInterface pInterface, java.lang.String pName)

		DataSet dataset = intf.getDataSets().iterator().next();
		SourceSet srcset = new SourceSet("srcset0",dataset);
		SourceDataStore sd=new SourceDataStore(dataset,false,sourceDatastore.getName().toString(),0,sourceDatastore);
		srcset.addSourceDataStore(sd);

		// Helper is to manipulate Odi interfaces in an
		// interactive way

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

		helper.performAction(new InterfaceActionSetTargetDataStore(
				targetDatastore, new MappingMatchPolicyLazy(),
				new AutoMappingComputerLazy(),
				new AutoMappingComputerLazy(),
				new TargetKeyChooserPrimaryKey()));

		helper.performAction(new InterfaceActionOnTargetDataStoreComputeAutoMapping());

		// Add the Filter
		//helper.performAction(new InterfaceActionAddFilter(dataset, sd.getName(),ExecutionLocation.WORK));

		// Start mapping the KM
		// LKM
		Collection lkm1 = ((IOdiLKMFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiLKM.class)).findByName(
						LKM,Project_Code);

		for (Iterator iterator = lkm1.iterator(); iterator.hasNext();) {
			OdiLKM odiLKM = (OdiLKM) iterator.next();
			helper.performAction(new InterfaceActionSetKM(odiLKM,srcset, KMType.LKM,new KMOptionRetainerHomonymy()));

			// Fetching each option of the LKM
			for (ProcedureOption c : odiLKM.getOptions()) {
				helper.performAction(new InterfaceActionSetKMOptionValue(srcset, KMType.LKM,"DELETE_TEMPORARY_INDEXES", true));
			}
		}

		// IKM
		// Find the IKM using the IOdiIKMFinder

		Collection ikm1 = ((IOdiIKMFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiIKM.class)).findByName(
						IKM,Project_Code);

		for (Iterator iterator = ikm1.iterator(); iterator.hasNext();) {
			OdiIKM odiIKM = (OdiIKM) iterator.next();

			// Setting the IKM in the interface
			helper.performAction(new InterfaceActionSetKM(odiIKM, intf.getTargetDataStore(),KMType.IKM, new KMOptionRetainerLazy()));

			// Fetching each option of the IKM
			for (ProcedureOption c : odiIKM.getOptions()) {

				// Modifying the Options of the IKM in the
				// Interface
				helper.performAction(new InterfaceActionSetKMOptionValue(intf.getTargetDataStore(), KMType.IKM,
						"FLOW_CONTROL", false));

				helper.performAction(new InterfaceActionSetKMOptionValue(intf.getTargetDataStore(), KMType.IKM,
						"STATIC_CONTROL", true));

			}
		}

		// CKM
		Collection ckm1 = ((IOdiCKMFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiCKM.class)).findByName(
				CKM,Project_Code);

		for (Iterator iterator = ckm1.iterator(); iterator.hasNext();) {
			OdiCKM odiCKM = (OdiCKM) iterator.next();
			helper.performAction(new InterfaceActionSetKM(odiCKM, intf.getTargetDataStore(),KMType.CKM, new KMOptionRetainerLazy()));
		}

		// Compute the Interface sourceset

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

		// Persisting the Interface
		// Called to inform the ODI persistence layer that this
		// interface will be persisted
		try {helper.preparePersist();}
		catch (oracle.odi.interfaces.interactive.exceptions.OdiInterfaceNotReadyForPersistException e) {e.printStackTrace();}

		odiInstance.getTransactionalEntityManager().persist(intf);

		// Generating Scenarios 

		System.out.println("Generating Scenario for .."+ target_datastore );
		IOdiScenarioGenerator gene = new OdiScenarioGeneratorImpl(odiInstance);
		OdiScenario newScen = gene.generateScenario(intf,target_datastore, "001");
		odiInstance.getTransactionalEntityManager().persist(newScen);

		// Finally close the Instance
		odiInstance.getTransactionManager().commit(trans);
		odiInstance.close();

		System.out.println("Process Completed");
	}

}</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://odiexperts.com/creating-interface-for-single-source-and-target/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Permanent Interface based on Model Level</title>
		<link>http://odiexperts.com/creating-permanent-interface-based-on-model-level-2</link>
		<comments>http://odiexperts.com/creating-permanent-interface-based-on-model-level-2#comments</comments>
		<pubDate>Thu, 17 Nov 2011 02:46:05 +0000</pubDate>
		<dc:creator>Kshitiz Devendra</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[ODI]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://odiexperts.com/?p=3230</guid>
		<description><![CDATA[This particular ODI SDK codes creates one source to one target   interface and accordingly generate Scenario,  based on condition where the Source table is same as Target Table name , under two different Model. By default the target datastore name is used as the Interface Name. For this example , Source Model is HR [...]]]></description>
			<content:encoded><![CDATA[<p>This particular ODI SDK codes creates one source to one target   interface and accordingly generate Scenario,  based on condition where the Source table is same as Target Table name , under two different Model.</p>
<p>By default the target datastore name is used as the Interface Name.</p>
<p>For this example , Source Model is HR schema and also the Target Model is HR schema.</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:8dd28fa4-a288-40c9-a3a4-3e300f0be962" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: java;">package odi_sdk;

import java.util.Collection;
import java.util.HashSet;
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.exception.OdiRuntimeException;
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.model.OdiDataStore;
import oracle.odi.domain.model.finder.IOdiDataStoreFinder;
import oracle.odi.domain.project.OdiCKM;
import oracle.odi.domain.project.OdiFolder;
import oracle.odi.domain.project.OdiIKM;
import oracle.odi.domain.project.OdiInterface;
import oracle.odi.domain.project.OdiLKM;
import oracle.odi.domain.project.ProcedureOption;
import oracle.odi.domain.project.finder.IOdiCKMFinder;
import oracle.odi.domain.project.finder.IOdiFolderFinder;
import oracle.odi.domain.project.finder.IOdiIKMFinder;
import oracle.odi.domain.project.finder.IOdiLKMFinder;
import oracle.odi.domain.project.interfaces.DataSet;
import oracle.odi.domain.project.interfaces.SourceDataStore;
import oracle.odi.domain.project.interfaces.SourceSet;
import oracle.odi.domain.runtime.scenario.OdiScenario;
import oracle.odi.domain.topology.OdiContext;
import oracle.odi.domain.topology.finder.IOdiContextFinder;
import oracle.odi.generation.IOdiScenarioGenerator;
import oracle.odi.generation.support.OdiScenarioGeneratorImpl;
import oracle.odi.interfaces.interactive.support.InteractiveInterfaceHelperWithActions;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionOnTargetDataStoreComputeAutoMapping;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKM;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKM.KMType;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKMOptionValue;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetTargetDataStore;
import oracle.odi.interfaces.interactive.support.km.optionretainer.KMOptionRetainerHomonymy;
import oracle.odi.interfaces.interactive.support.km.optionretainer.KMOptionRetainerLazy;
import oracle.odi.interfaces.interactive.support.mapping.automap.AutoMappingComputerLazy;
import oracle.odi.interfaces.interactive.support.mapping.matchpolicy.MappingMatchPolicyLazy;
import oracle.odi.interfaces.interactive.support.sourceset.creators.InexistentMappingException;
import oracle.odi.interfaces.interactive.support.targetkeychoosers.TargetKeyChooserPrimaryKey;

public class PermanentInterface {

	private static String Project_Code;
	private static String Folder_Name;
	private static OdiFolder folder;
	private static String Context_Code;
	private static OdiContext context;
	private static OdiDataStore sourceDatastore;
	private static OdiInterface odiInterface;
	private static String target_model_name;
	private static String source_model_name;
	private static String LKM;
	private static String IKM;
	private static String CKM;

	/**
	 * @param args
	 */
	public static void main(String[] args) {

        /****** Please change these Parameters *********/

		String Url = "jdbc:oracle:thin:@localhost:1521:orcl";
		String Driver="oracle.jdbc.OracleDriver";
		String Master_User="ODI_MASTER_11G";
		String Master_Pass="ODI_MASTER_11G";
		String WorkRep="WORKREP1";
		String Odi_User="SUPERVISOR";
		String Odi_Pass="SUNOPSIS";

                Project_Code="XMT";
		Context_Code="XMT";
		Folder_Name="FOLDER";
		source_model_name = "SRCE_HR";
		target_model_name = "TRGT_HR";
		LKM ="LKM SQL to Oracle";
		IKM ="IKM SQL Control Append";
		CKM ="CKM Oracle";

                /*****************************/

		// Connection
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());

		// Find the folder

		Collection fold = ((IOdiFolderFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiFolder.class)).findByName(Folder_Name);
		for (Iterator it = fold.iterator(); it.hasNext();) {
			folder = (OdiFolder) it.next();
		}

		// Find the Context
		context = ((IOdiContextFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class)).findByCode(Context_Code);

		// Target Data Store
		Object[] trgt_ds = ((IOdiDataStoreFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).findAll().toArray();

		// This part of the code is to remove the
		// duplicate datastores present in different Models
		HashSet hs = new HashSet();
		for (Object dt_str : trgt_ds) {
			OdiDataStore ds = (OdiDataStore) dt_str;
			hs.add(ds.getName().toString());
		}

		for (Object ds : hs) {
			// Target Data Store
			OdiDataStore targetDatastore = ((IOdiDataStoreFinder)odiInstance.getTransactionalEntityManager().
                        getFinder(OdiDataStore.class)).
                        findByName(ds.toString(), target_model_name);

			if (targetDatastore != null) {
			// Reading the Source Data Store
			// Find the Data store using the IOdiDataStoreFinder
			sourceDatastore = ((IOdiDataStoreFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).
                        findByName(ds.toString(), source_model_name);

			System.out.println("Interface Creation Started for ..."+ ds.toString());
			// Creating a New Interface
			OdiInterface intf = new OdiInterface(folder, ds.toString(), context);

			// Setting the above Context as the Optimization Context
			intf.setOptimizationContext(context);

			// Creating DataSet to automatically assign different
			// Source Data store
			// DataSet(OdiInterface pInterface, java.lang.String pName)

			DataSet dataset = intf.getDataSets().iterator().next();
			SourceSet srcset = new SourceSet("srcset0",dataset);
			SourceDataStore sd=new SourceDataStore(dataset,false,sourceDatastore.getName().
                        toString(),0,sourceDatastore);
			srcset.addSourceDataStore(sd);

			// Helper is to manipulate Odi interfaces in an
			// interactive way

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

			helper.performAction(new InterfaceActionSetTargetDataStore(
					targetDatastore, new MappingMatchPolicyLazy(),
					new AutoMappingComputerLazy(),
					new AutoMappingComputerLazy(),
					new TargetKeyChooserPrimaryKey()));

			helper.performAction(new InterfaceActionOnTargetDataStoreComputeAutoMapping());

			// Add the Filter
			//helper.performAction(new InterfaceActionAddFilter(dataset, sd.getName(),ExecutionLocation.WORK));

			// Start mapping the KM
			// LKM
			Collection lkm1 = ((IOdiLKMFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiLKM.class)).
                        findByName(LKM,Project_Code);

			for (Iterator iterator = lkm1.iterator(); iterator.hasNext();) {
				OdiLKM odiLKM = (OdiLKM) iterator.next();
				helper.performAction(new InterfaceActionSetKM(odiLKM,srcset, KMType.LKM,new KMOptionRetainerHomonymy()));

				// Fetching each option of the LKM
				for (ProcedureOption c : odiLKM.getOptions()) {
					helper.performAction(new InterfaceActionSetKMOptionValue(srcset, KMType.LKM,"DELETE_TEMPORARY_INDEXES", false));
				}
			}

			// IKM
			// Find the IKM using the IOdiIKMFinder

			Collection ikm1 = ((IOdiIKMFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiIKM.class)).findByName(
							IKM,Project_Code);

			for (Iterator iterator = ikm1.iterator(); iterator.hasNext();) {
				OdiIKM odiIKM = (OdiIKM) iterator.next();

				// Setting the IKM in the interface
				helper.performAction(new InterfaceActionSetKM(odiIKM, intf.getTargetDataStore(),KMType.IKM, new KMOptionRetainerLazy()));

				// Fetching each option of the IKM
				for (ProcedureOption c : odiIKM.getOptions()) {

					// Modifying the Options of the IKM in the
					// Interface
					helper.performAction(new InterfaceActionSetKMOptionValue(intf.getTargetDataStore(), KMType.IKM,
							"FLOW_CONTROL", false));

					helper.performAction(new InterfaceActionSetKMOptionValue(intf.getTargetDataStore(), KMType.IKM,
							"STATIC_CONTROL", true));

				}
			}

			// CKM
			Collection ckm1 = ((IOdiCKMFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiCKM.class)).findByName(
					CKM,Project_Code);

			for (Iterator iterator = ckm1.iterator(); iterator.hasNext();) {
				OdiCKM odiCKM = (OdiCKM) iterator.next();
				helper.performAction(new InterfaceActionSetKM(odiCKM, intf.getTargetDataStore(),KMType.CKM, new KMOptionRetainerLazy()));
			}

			// Compute the Interface sourceset

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

			// Persisting the Interface
			// Called to inform the ODI persistence layer that this
			// interface will be persisted
			try {helper.preparePersist();}
			catch (oracle.odi.interfaces.interactive.exceptions.OdiInterfaceNotReadyForPersistException e) {e.printStackTrace();}

			odiInstance.getTransactionalEntityManager().persist(intf);

			// Generating Scenarios 

			System.out.println("Generating Scenario for .."+ ds.toString() );
			IOdiScenarioGenerator gene = new OdiScenarioGeneratorImpl(odiInstance);
			OdiScenario newScen = gene.generateScenario(intf,ds.toString(), "001");
			odiInstance.getTransactionalEntityManager().persist(newScen);
			} } 

		// Finally close the Instance
		odiInstance.getTransactionManager().commit(trans);
		odiInstance.close();

		System.out.println("Process Completed");
	}

}</pre>
</div>
<h4><span style="text-decoration: underline; color: #ff0000;">Sample Output</span></h4>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/11/Output.jpg"><img class="alignnone size-full wp-image-3222" title="Output" src="http://odiexperts.com/wp-content/uploads/2011/11/Output.jpg" alt="" width="440" height="325" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://odiexperts.com/creating-permanent-interface-based-on-model-level-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically add Interfaces/Scenarios to new ODIPackage using ODI SDK</title>
		<link>http://odiexperts.com/automatically-add-interfacesscenarios-to-new-odipackage-using-odi-sdk</link>
		<comments>http://odiexperts.com/automatically-add-interfacesscenarios-to-new-odipackage-using-odi-sdk#comments</comments>
		<pubDate>Wed, 16 Nov 2011 03:20:43 +0000</pubDate>
		<dc:creator>Kshitiz Devendra</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[ODI]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://odiexperts.com/?p=3183</guid>
		<description><![CDATA[The below codes  automatically adds all the interface/Scenarios of a Folder  into a New Package . The below codes are written in such a way so that minimal changes are required . All you would need to change is the parameters .  Also in the Scenarios we have mentioned only Scenario name and version as -1 [...]]]></description>
			<content:encoded><![CDATA[<p>The below codes  automatically adds all the interface/Scenarios of a Folder  into a New Package .</p>
<p>The below codes are written in such a way so that minimal changes are required .</p>
<p>All you would need to change is the parameters .  Also in the Scenarios we have mentioned only Scenario name and version as -1 so please change accordingly or add more parameters according to your requirement.</p>
<h4><span style="text-decoration: underline;">Add all the interface of the Folder into Package</span></h4>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:b3d9e9ac-f0ee-4fb2-8482-f097e948ef11" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: java;">package odi_sdk;

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.OdiFolder;
import oracle.odi.domain.project.OdiInterface;
import oracle.odi.domain.project.OdiPackage;
import oracle.odi.domain.project.StepInterface;
import oracle.odi.domain.project.finder.IOdiFolderFinder;
import oracle.odi.domain.project.finder.IOdiInterfaceFinder;

public class AddIntfNewPackage {

	private static String Project_Code;
	private static String Folder_Name;
	private static OdiInterface odiInterface;
	private static StepInterface step_prevscen;
	private static OdiPackage pkg;
    private static StepInterface step_intf;
	private static OdiFolder folder;
	private static String Package_Name;
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		/****** Please change these Parameters *********/

		String Url = "jdbc:oracle:thin:@localhost:1521:orcl";
		String Driver="oracle.jdbc.OracleDriver";
		String Master_User="ODI_MASTER_11G";
		String Master_Pass="ODI_MASTER_11G";
		String WorkRep="WORKREP1";
		String Odi_User="SUPERVISOR";
		String Odi_Pass="SUNOPSIS";

		Project_Code="XMT";
		Folder_Name ="FOLDER";
		Package_Name="";  //Provide Package Name

		/********************************************/

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&lt;OdiFolder&gt; fold = ((IOdiFolderFinder) odiInstance
	                 .getTransactionalEntityManager().getFinder(OdiFolder.class)).
                         findByName(Folder_Name,Project_Code);

	 for (Iterator&lt;OdiFolder&gt; it = fold.iterator(); it.hasNext();)
                {
	             folder = (OdiFolder) it.next();
	        }

	     // New Package
	      pkg = new OdiPackage(folder, Package_Name);

	      int i=0;

 Collection&lt;OdiInterface&gt; intf_find = ((IOdiInterfaceFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiInterface.class)).
findByProject(Project_Code, Folder_Name);

	  for (Iterator&lt;OdiInterface&gt; iterator = intf_find.iterator(); iterator.hasNext();)
                   {
		     odiInterface = (OdiInterface) iterator.next();
		     System.out.println("Interface Name is " + odiInterface.getName());

		    step_intf = new StepInterface(pkg,odiInterface,odiInterface.getName());

		     if (i==0) {
		    step_prevscen = new StepInterface(pkg,odiInterface,odiInterface.getName());
		    pkg.setFirstStep(step_prevscen);
		    pkg.removeStep(step_intf);
		   	   i+=1;
		   	   }else{
		   		step_prevscen.setNextStepAfterSuccess(step_intf);
		   		step_prevscen = step_intf;
		   	   }}

               // Persisting the Package
	      odiInstance.getTransactionalEntityManager().persist(pkg);
	      odiInstance.getTransactionManager().commit(trans);
	      odiInstance.close();
	      System.out.println("Process Completed");
	}
}
</pre>
</div>
<h4><span style="text-decoration: underline;">Add all the scenario of the Folder into the Package. </span></h4>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:bb5ea6fe-dd18-4cf4-ae15-c6b4e2cecb48" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: java;">package odi_sdk;

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.OdiFolder;
import oracle.odi.domain.project.OdiInterface;
import oracle.odi.domain.project.OdiPackage;
import oracle.odi.domain.project.StepOdiCommand;
import oracle.odi.domain.project.finder.IOdiFolderFinder;
import oracle.odi.domain.project.finder.IOdiInterfaceFinder;
import oracle.odi.domain.runtime.scenario.OdiScenario;
import oracle.odi.domain.runtime.scenario.finder.IOdiScenarioFinder;
import oracle.odi.domain.xrefs.expression.Expression;

public class AddScenNewPackage {

	private static String Project_Code;
	private static String Folder_Name;
	private static OdiInterface odiInterface;
	private static StepOdiCommand step_prevscen;
	private static OdiPackage pkg;
    private static StepOdiCommand step_scen;
	private static OdiFolder folder;
	private static String Package_Name;
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		/****** Please change these Parameters *********/

		String Url = "jdbc:oracle:thin:@localhost:1521:orcl";
		String Driver="oracle.jdbc.OracleDriver";
		String Master_User="ODI_MASTER_11G";
		String Master_Pass="ODI_MASTER_11G";
		String WorkRep="WORKREP1";
		String Odi_User="SUPERVISOR";
		String Odi_Pass="SUNOPSIS";

		Project_Code="XMT";
		Folder_Name ="FOLDER";
		Package_Name="TESTING";  //Provide Package Name

		/********************************************/

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&lt;OdiFolder&gt; fold = ((IOdiFolderFinder) odiInstance
	                 .getTransactionalEntityManager().getFinder(OdiFolder.class)).
                          findByName(Folder_Name,Project_Code);

			 for (Iterator&lt;OdiFolder&gt; it = fold.iterator(); it.hasNext();) {
	             folder = (OdiFolder) it.next();
	        }

	     // New Package
		 pkg = new OdiPackage(folder, Package_Name);

	      int i=0;

		   Collection&lt;OdiInterface&gt; intf_find = ((IOdiInterfaceFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiInterface.class)).
                   findByProject(Project_Code, Folder_Name);

		   for (Iterator&lt;OdiInterface&gt; iterator = intf_find.iterator(); iterator.hasNext();) {
		     odiInterface = (OdiInterface) iterator.next();

		     Collection&lt;OdiScenario&gt; scen = ((IOdiScenarioFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiScenario.class)).
                     findBySourceInterface(odiInterface.getInterfaceId());

		     for (Iterator&lt;OdiScenario&gt; iterator2 = scen.iterator(); iterator2.hasNext();)
                           {
		   	   OdiScenario odiScenario = (OdiScenario) iterator2.next();
		   	   	System.out.println(odiScenario.getName());
			   	   step_scen = new StepOdiCommand(pkg,odiScenario.getName().toUpperCase());

			   	   step_scen.setCommandExpression(new Expression("OdiStartScen -SCEN_NAME="+odiScenario.getName()+" -SCEN_VERSION=-1",
			   						   null, Expression.SqlGroupType.NONE));
		   	    System.out.println(i);
			   	 if (i==0) {
				   	   step_prevscen = step_scen;
				   	   pkg.setFirstStep(step_prevscen);
				   	   step_prevscen = step_scen;
				   	   i+=1;
				   	   }else{
				   			step_prevscen.setNextStepAfterSuccess(step_scen);
				   			step_prevscen = step_scen;
				   	   }}
		   }

              odiInstance.getTransactionalEntityManager().persist(pkg);
	      odiInstance.getTransactionManager().commit(trans);
	      odiInstance.close();
	      System.out.println("Process Completed");
	}
}</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://odiexperts.com/automatically-add-interfacesscenarios-to-new-odipackage-using-odi-sdk/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Package using SDK</title>
		<link>http://odiexperts.com/creating-package-using-sdk</link>
		<comments>http://odiexperts.com/creating-package-using-sdk#comments</comments>
		<pubDate>Wed, 16 Nov 2011 01:04:57 +0000</pubDate>
		<dc:creator>Kshitiz Devendra</dc:creator>
				<category><![CDATA[Logic]]></category>
		<category><![CDATA[ODI]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://odiexperts.com/?p=3156</guid>
		<description><![CDATA[This post is about on how to Create Package and call Variable in different mode namely Declare, Set, Refresh and Evaluate Mode and Interface and Scenarios inside the Package ,using ODI . As you know that in Package we define each ODI Object as Step. Similarly in SDK codes too we declare Step depending on [...]]]></description>
			<content:encoded><![CDATA[<p>This post is about on how to Create Package and call Variable in different mode namely Declare, Set, Refresh and Evaluate Mode and Interface and Scenarios inside the Package ,using ODI .</p>
<p>As you know that in Package we define each ODI Object as Step. Similarly in SDK codes too we declare Step depending on the type of object and call them in the package . For example StepVariable, StepOdiCommand,StepInterface etc.</p>
<blockquote><p>StepModel<br />
StepOdiCommand<br />
StepOsCommand<br />
StepProcedure<br />
StepSubModel<br />
StepType<br />
StepVariable</p></blockquote>
<p>Lets take a look at an example of Creating an example in Declare Mode</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:3ded0ca4-6a7b-437b-93bb-36da52fb4c18" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: java;">StepVariable stepDecVar = new StepVariable(pkg,var,StepName);
DeclareVariable DecVar  = new StepVariable.DeclareVariable(stepDecVar);
stepDecVar.setAction(DecVar);</pre>
</div>
<p>First step is to define the step of Variable Type .</p>
<p>StepVariable stepDecVar = new StepVariable(PACKAGE ,VARIABLE  ,StepName);</p>
<p>Next step is to have the variable in the mode we want the variable to be such as</p>
<p>( DeclareVariable, SetVariable,RefreshVariable etc ).</p>
<p>DeclareVariable DecVar  = new StepVariable.DeclareVariable(StepVariable  NAME);</p>
<p>Next step is setting the action of the step</p>
<p>stepDecVar.setAction(DecVar);</p>
<p>For other types of the Variable Mode you can look at the below codes.</p>
<p>You can call Scenario using the StepOdiCommand</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:d21cd350-d4e6-4408-83bf-9cdecc7630ff" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: java;">StepOdiCommand odicmnd = new StepOdiCommand(pkg,StepName);
odicmnd.setCommandExpression(new Expression(
"OdiStartScen -SCEN_NAME=SCEN -SCEN_VERSION=001",null, Expression.SqlGroupType.NONE));</pre>
</div>
<p>Just provide the right expression in the set command expression .</p>
<p>The below codes creates the Package as shows in the below image.</p>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/11/image.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/11/image_thumb.png" alt="image" width="633" height="271" border="0" /></a></p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:927fc70e-58fd-424f-85f1-af6f82e2c516" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: java;">package odi_sdk;

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.OdiFolder;
import oracle.odi.domain.project.OdiInterface;
import oracle.odi.domain.project.OdiPackage;
import oracle.odi.domain.project.OdiVariable;
import oracle.odi.domain.project.StepInterface;
import oracle.odi.domain.project.StepOdiCommand;
import oracle.odi.domain.project.StepVariable;
import oracle.odi.domain.project.StepVariable.DeclareVariable;
import oracle.odi.domain.project.StepVariable.EvaluateVariable;
import oracle.odi.domain.project.StepVariable.RefreshVariable;
import oracle.odi.domain.project.StepVariable.SetVariable;
import oracle.odi.domain.project.finder.IOdiFolderFinder;
import oracle.odi.domain.project.finder.IOdiInterfaceFinder;
import oracle.odi.domain.project.finder.IOdiVariableFinder;
import oracle.odi.domain.xrefs.expression.Expression;

public class CreatingPackage {

    private static String Project_Code;
    private static String Folder_Name;
    private static String Package_Name;
    private static OdiFolder folder;
    /**
     * @param args
     */
    public static void main(String[] args) {

               /****** Please change these Parameters *********/

		String Url = "jdbc:oracle:thin:@localhost:1521:orcl";
		String Driver="oracle.jdbc.OracleDriver";
		String Master_User="ODI_MASTER_11G";
		String Master_Pass="ODI_MASTER_11G";
		String WorkRep="WORKREP1";
		String Odi_User="SUPERVISOR";
		String Odi_Pass="SUNOPSIS";

		Project_Code="XMT";
		Folder_Name ="FOLDER";
		Package_Name="PKG_TEST";

// Connection
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&lt;OdiFolder&gt; fold = ((IOdiFolderFinder) odiInstance
                 .getTransactionalEntityManager().getFinder(OdiFolder.class)).
                 findByName(Folder_Name,Project_Code);

         for (Iterator&lt;OdiFolder&gt; it = fold.iterator(); it.hasNext();) {
             folder = (OdiFolder) it.next();
        }

        OdiPackage pkg = new OdiPackage(folder, Package_Name);
        // Here are some of the examples based on variable using the methods defined below
        //Declare Example
        OdiVariable var1=getProjVariable(odiInstance,"TEST_VARIABLE1",Project_Code);
        System.out.println(var1.getName());
        StepVariable step1=getDeclareVariable(pkg, var1, var1.getName());

        //Set Example
        OdiVariable var2=getProjVariable(odiInstance,"TEST_VARIABLE1",Project_Code);
        StepVariable step2=getSetVariable(pkg, var2, var2.getName(), "15");

        //Refresh Example
        OdiVariable var3=getProjVariable(odiInstance,"TEST_VARIABLE1",Project_Code);
        StepVariable step3=getRefreshVariable(pkg, var3, var3.getName());

        //Evaluate Example
        OdiVariable var4=getProjVariable(odiInstance, "TEST_VARIABLE1",Project_Code);
        StepVariable step4=getEvaluateVariable(pkg, var4, var4.getName(), "=", "Y");

        // Refresh Variable Failure
        OdiVariable var5=getProjVariable(odiInstance, "TEST_VARIABLE2",Project_Code);
        StepVariable step5=getRefreshVariable(pkg, var5, var5.getName());

        // Scenario
        StepOdiCommand scen1=getOdiCmnd(pkg, "SCEN",
                 "OdiStartScen -SCEN_NAME=SCEN -SCEN_VERSION=001");

        // Interface
        StepInterface intf = getIntf(odiInstance, pkg, "TEST_INTF", "TEST_INTF");
        // Linking the steps depending on success or Failure .
        // Categorized for easy understanding and link
        //Success
        pkg.setFirstStep(step1);
        step1.setNextStepAfterSuccess(step2);
        step2.setNextStepAfterSuccess(step3);
        step3.setNextStepAfterSuccess(step4);
        step4.setNextStepAfterSuccess(scen1);
        scen1.setNextStepAfterSuccess(intf);

        //Failure
        step1.setNextStepAfterFailure(step5);
        step2.setNextStepAfterFailure(step5);
        step3.setNextStepAfterFailure(step5);
        step4.setNextStepAfterFailure(step5);
        scen1.setNextStepAfterFailure(step5);
        intf.setNextStepAfterFailure(step5);
        // Persisting Package
         odiInstance.getTransactionalEntityManager().persist(pkg);
        /*** Change Ends here **/

        // Finally close the Instance
        odiInstance.getTransactionManager().commit(trans);
        odiInstance.close();

        System.out.println("Completed ");

    }
        /*****************************************************/
        // Please find few methods that can be called any number of times for few types of StepType
        /*****************************************************/
        //Find Global Variable
        public static OdiVariable getGlobalVariable(OdiInstance odiInstance,String GlobalVariable) {
            OdiVariable var=((IOdiVariableFinder) odiInstance.getTransactionalEntityManager().getFinder(
                            OdiVariable.class)).findGlobalByName(GlobalVariable);

            return var;
        }

        //Find Project Variable
        public static OdiVariable getProjVariable(OdiInstance odiInstance,String ProjectVariable,String ProjectCode) {
            OdiVariable var=((IOdiVariableFinder) odiInstance.getTransactionalEntityManager().getFinder(
                            OdiVariable.class)).findByName(ProjectVariable,ProjectCode);

            return var;
        }

        // Declare Variable
        public static StepVariable getDeclareVariable(OdiPackage pkg,OdiVariable var,String StepName) {

            StepVariable stepDecVar = new StepVariable(pkg,var,StepName);
            DeclareVariable DecVar  = new StepVariable.DeclareVariable(stepDecVar);
            stepDecVar.setAction(DecVar);

            return stepDecVar;

        }

        // Refresh Variable
        public static StepVariable getRefreshVariable(OdiPackage pkg,OdiVariable var,String StepName) {

            StepVariable stepRefVar = new StepVariable(pkg,var,StepName);
            RefreshVariable RefVar  = new StepVariable.RefreshVariable(stepRefVar);
            stepRefVar.setAction(RefVar);

            return stepRefVar;
        }

        // Set Variable
        public static StepVariable getSetVariable(OdiPackage pkg,OdiVariable var,String StepName,String Value) {

            StepVariable stepSetVar = new StepVariable(pkg,var,StepName);
            SetVariable SetVar  = new StepVariable.SetVariable(stepSetVar);
            SetVar = new StepVariable.SetVariable(Value);
            stepSetVar.setAction(SetVar);

            return stepSetVar;

        }

        // Evaluate Variable
        public static StepVariable getEvaluateVariable(OdiPackage pkg,OdiVariable var,String StepName,String Operator,String Value) {

            StepVariable stepEvaVar = new StepVariable(pkg,var,StepName);
            EvaluateVariable EvaVar  = new StepVariable.EvaluateVariable(stepEvaVar);
            EvaVar = new  StepVariable.EvaluateVariable(Operator,Value);
            stepEvaVar.setAction(EvaVar);

            return stepEvaVar;

        }

        // ODI Command
        public static StepOdiCommand getOdiCmnd (OdiPackage pkg,String StepName,String Command) {

            StepOdiCommand odicmnd = new StepOdiCommand(pkg,StepName);
            odicmnd.setCommandExpression(new Expression(Command,null, Expression.SqlGroupType.NONE));
            return odicmnd;

        }

        // Interface
        public static StepInterface getIntf (OdiInstance odiinstance,OdiPackage pkg,String Interface,String StepName) {

            StepInterface stepIntf = null;
             Collection&lt;OdiInterface&gt; intf_find = ((IOdiInterfaceFinder) odiinstance.getTransactionalEntityManager().getFinder(OdiInterface.class)).findByName(Interface, Project_Code, Folder_Name);
             for (Iterator&lt;OdiInterface&gt; iterator = intf_find.iterator(); iterator.hasNext();) {
                 OdiInterface    intf = (OdiInterface) iterator.next();
                 stepIntf = new StepInterface(pkg,intf,StepName);

                 }return stepIntf;
        }

}
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://odiexperts.com/creating-package-using-sdk/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling the &#8220;ORDER BY&#8221; clause in an interface</title>
		<link>http://odiexperts.com/order-by</link>
		<comments>http://odiexperts.com/order-by#comments</comments>
		<pubDate>Sun, 13 Nov 2011 15:56:13 +0000</pubDate>
		<dc:creator>Kshitiz Devendra</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[Knowledge Modules]]></category>
		<category><![CDATA[ODI]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[ODI 11g]]></category>
		<category><![CDATA[ODI Experts]]></category>
		<category><![CDATA[Oracle Data Integrator]]></category>
		<category><![CDATA[Oracle Data Integrator 11g]]></category>
		<category><![CDATA[Order By]]></category>

		<guid isPermaLink="false">http://odiexperts.com/?p=3169</guid>
		<description><![CDATA[Hello Everyone&#8230; We always get a lot of emails asking about how to &#8220;Order By&#8221; in ODI because of that, here there is a simple way to do it&#8230; Stays as a suggestion to Oracle implement as default feature in forward versions! A simple example how to handle Order By in ODI. Solution 1 Step [...]]]></description>
			<content:encoded><![CDATA[<p>Hello Everyone&#8230;</p>
<p>We always get a lot of emails asking about how to &#8220;Order By&#8221; in ODI because of that, here there is a simple way to do it&#8230;</p>
<p>Stays as a suggestion to Oracle implement as default feature in forward versions!</p>
<p>A simple example how to handle Order By in ODI.</p>
<h2><span style="text-decoration: underline;">Solution 1</span></h2>
<h4>Step 1.  Create an Option</h4>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/11/image1.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/11/image_thumb1.png" alt="image" width="270" height="202" border="0" /></a></p>
<h4>Step 2. Add the code into KM</h4>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:29a149cb-8608-4668-b9e2-a466c3be933d" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: java;">&lt;% if (odiRef.getOption("ORDER_BY").equals("1")) { %&gt;
ORDER BY
&lt;%=odiRef.getColList("", "[COL_NAME]", ",\n\t", "", "(UD1)")%&gt;
&lt;%=odiRef.getColList(",", "[COL_NAME]", ",\n\t", "", "(UD2)")%&gt;
&lt;%=odiRef.getColList(",", "[COL_NAME]", ",\n\t", "", "(UD3)")%&gt;
&lt;%=odiRef.getColList(",", "[COL_NAME]", ",\n\t", "", "(UD4)")%&gt;
&lt;%=odiRef.getColList(",", "[COL_NAME]", ",\n\t", "", "(UD5)")%&gt;
&lt;%=odiRef.getColList(",", "[COL_NAME]", ",\n\t", "", "(UD6)")%&gt;
&lt;%=odiRef.getColList("", "[COL_NAME]", ",\n\t", "", "(UD7)")%&gt;
&lt;%=odiRef.getColList("", "[COL_NAME]", ",\n\t", "", "(UD8)")%&gt;
&lt;%=odiRef.getColList("", "[COL_NAME]", ",\n\t", "", "(UD9)")%&gt;
&lt;%=odiRef.getColList("", "[COL_NAME]", ",\n\t", "", "(UD10)")%&gt;
&lt;%} %&gt;</pre>
</div>
<p>This way you can have the KM to handle with and without Order By option .</p>
<h4>Step 3.  Mark the Columns accordingly with UD1</h4>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/11/image2.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/11/image_thumb2.png" alt="image" width="306" height="233" border="0" /></a></p>
<h2><span style="text-decoration: underline;">Solution 2</span></h2>
<h4>Step 1.  Create an Option</h4>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/11/image3.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/11/image_thumb3.png" alt="image" width="254" height="167" border="0" /></a></p>
<h4>Step 2 . Add the option into KM</h4>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:afc62768-0a22-4a7b-bcd3-92c9ec11d3be" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">
<pre class="brush: java;">&lt;%=odiRef.getOption("ORDER_BY")%&gt;</pre>
</div>
<h4>Step 3.  Add the Order By Clause accordingly</h4>
<p>Provide the Order By clause accordingly for N number of columns  in the interface</p>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/11/image4.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/11/image_thumb4.png" alt="image" width="669" height="108" border="0" /></a></p>
<p><strong><span style="text-decoration: underline;">Sample Output </span></strong></p>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/11/image5.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/11/image_thumb5.png" alt="image" width="334" height="233" border="0" /></a>.</p>
<p>Good to see you around&#8230;</p>
<p>Keep visiting us at www.odiexperts.com</p>
]]></content:encoded>
			<wfw:commentRss>http://odiexperts.com/order-by/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Temporary Interface using ODI SDK</title>
		<link>http://odiexperts.com/creating-temporary-interface-using-odi-sdk</link>
		<comments>http://odiexperts.com/creating-temporary-interface-using-odi-sdk#comments</comments>
		<pubDate>Tue, 27 Sep 2011 03:46:33 +0000</pubDate>
		<dc:creator>Kshitiz Devendra</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[Logic]]></category>
		<category><![CDATA[ODI]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Interface]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://odiexperts.com/?p=3114</guid>
		<description><![CDATA[In this below example we are creating a temporary interface with HR table REGIONS as the source . Please go through this post ( http://odiexperts.com/odi-sdk-setup-and-config-in-eclipse ) before proceeding and this post is a continuation of the objects created in the old Post. The below codes assumes that we already have the HR model with REGIONS [...]]]></description>
			<content:encoded><![CDATA[<p>In this below example we are creating a temporary interface with HR table REGIONS as the source .</p>
<p>Please go through this post ( <a href="http://odiexperts.com/odi-sdk-setup-and-config-in-eclipse">http://odiexperts.com/odi-sdk-setup-and-config-in-eclipse</a> ) before proceeding and this post is a continuation of the objects created in the old Post.</p>
<p>The below codes assumes that we already have the <span style="color: #ff0000;">HR model with REGIONS datastore.</span></p>
<pre class="brush:java">// Find the Project
// Using IFinder find the project , Folder , Context and Logical Schema ,which
// will be used to create  the Temporary Interface.

 project = ((IOdiProjectFinder)odiInstance.getTransactionalEntityManager().
getFinder(OdiProject.class)).
findByCode("XMT");

// Find the folder
// Here among the collection of Folder we are looking for  (FOLDER)
 Collection fold = ((IOdiFolderFinder)odiInstance.getTransactionalEntityManager().
getFinder(OdiFolder.class)).
findByName("FOLDER");

for (java.util.Iterator it=fold.iterator(); it.hasNext();){
     folder=(OdiFolder)it.next();
}

// Find the Context
   context = ((IOdiContextFinder)odiInstance.getTransactionalEntityManager().
getFinder(OdiContext.class)).
findByCode("XMT");

//Find the Oracle Logical Schema
   oracleLogicalSchema = ((IOdiLogicalSchemaFinder)odiInstance.getTransactionalEntityManager().
getFinder(OdiLogicalSchema.class)).
findByName("HR");

//Importing the KM
// ImportServiceImpl(OdiInstance pOdiInstance) 

IImportService importService = new ImportServiceImpl(odiInstance);

try {

// Specify the path of the XML files ok KM .
String KM_PATH = "C:\\Oracle\\Middleware\\Oracle_ODI1\\oracledi\\xml-reference";

// Import the KMs using duplication mode

// importObjectFromXml(int pImportMode, java.lang.String pFileName,
//    IImportRoot pObjectParent, boolean pDeclareMissingRepository)
// This method imports an object from an OracleDI export file (XML) under a parent object.

importService.importObjectFromXml(IImportService.IMPORT_MODE_DUPLICATION, KM_PATH
+ "\\KM_IKM SQL Control Append.xml",proj, false);
} catch (OdiImportNotSupportedException e) {

throw new OdiRuntimeException(e);
} catch (OdiImportException e) {throw new OdiRuntimeException(e);
} catch (IOException e) {throw new OdiRuntimeException(e);
}

// Eclipse can help to create the Exception automatically if it
// detects an Exception, so Exception handling can be easy task.

// Creating a New Interface
// OdiInterface(OdiFolder pFolder, java.lang.String pName, OdiContext pOptimizationContext) 

OdiInterface intf = new OdiInterface(fold, "INTF_REGIONS",context);

// Setting the above Context as the Optimization Context

intf.setOptimizationContext(context); 

// Creating DataSet to automatically assign different Source Data store
// DataSet(OdiInterface pInterface, java.lang.String pName) 

// A DataSet is a subset of sources that can be combined with other
// DataSets using Set operators (such as UNION, MINUS, etc.). DataSets contain SourceDataStores, Joins, Filters and
// TargetMappings (which are occurrences of mappings executed on Source or Staging Area.

DataSet dataset = intf.getDataSets().iterator().next();

// Reading the Source Data Store
// Find the Data store using the IOdiDataStoreFinder

OdiDataStore sourceDatastore = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class)).findByName("REGIONS",
"HR");

 // Creating the Target Data Store
// Helper is to manipulate Odi interfaces in an interactive way

// InteractiveInterfaceHelperWithActions(OdiInterface pInterface, OdiInstance pOdiInstance,
// IOdiEntityManager pOdiEntityManager) 

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

helper.performAction(new InterfaceActionAddSourceDataStore(sourceDatastore, dataset,
new AliasComputerDoubleChecker(),new ClauseImporterLazy(),new AutoMappingComputerColumnName()));

// Using the above create Logical Schema in place of Set
// Staging area different from Target

helper.performAction(new InterfaceActionOnStagingAreaSetLogicalSchema(oracleLogicalSchema));

// Creating a Temporary Table Name so using the Format
// Source Data Store + " TEMP"

helper.performAction(new InterfaceActionOnTemporaryTargetDataStoreSetName(
sourceDatastore.getName().toString() + "_TEMP"));

// Setting the Schema as Work Schema ( Temporary Schema) where Temporary Table will be created

helper.performAction(new InterfaceActionOnTemporaryTargetDataStoreSetDatabaseSchema(
DatabaseSchema.TEMPORARY_SCHEMA));

// Fetching the Source Columns and adding it to the target
// table and performing the automatic Columns Mapping

Object[] col = sourceDatastore.getColumns().toArray();
for (int i = 0; i &lt; col.length; i++) {
try {
     OdiColumn column = (OdiColumn) col[i];
     helper.performAction(new InterfaceActionOnTemporaryTargetDataStoreAddColumn(
     column, new AutoMappingComputerColumnName()));
// Each Source Column is read and added to target table and
// automatically mapped using AutoMappingComputerColumnName

 } catch (UnknownActionException e1) {e1.printStackTrace();}
     }

// Start mapping the KM
// Since both the source and the Temporary Table is in the
// same Data Server so no LKM only IKM

// IKM
// Find the IKM using the IOdiIKMFinder

Collection&lt;OdiIKM&gt; ikm1 = ((IOdiIKMFinder) odiInstance
.getTransactionalEntityManager().getFinder(
OdiIKM.class)).findByName("IKM SQL Control Append", "XMT");

for (Iterator iterator = ikm1.iterator(); iterator.hasNext();) {
     OdiIKM odiIKM = (OdiIKM) iterator.next();

// Fetching each option of the IKM
for (ProcedureOption c : odiIKM.getOptions()) {
// Setting the IKM in the interface
helper.performAction(new InterfaceActionSetKM(
odiIKM, intf.getTargetDataStore(),
KMType.IKM, new KMOptionRetainerLazy()));

// Modifying the Options of the IKM in the Interface
helper.performAction(new InterfaceActionSetKMOptionValue(
intf.getTargetDataStore(), KMType.IKM,"FLOW_CONTROL", false));

helper.performAction(new InterfaceActionSetKMOptionValue(
intf.getTargetDataStore(), KMType.IKM,"TRUNCATE", true));

helper.performAction(new InterfaceActionSetKMOptionValue(
intf.getTargetDataStore(), KMType.IKM,"CREATE_TARG_TABLE", true));

}

}

// Compute the Interface sourceset

try {
helper.computeSourceSets();
//Should be called at some point after source data stores are added to or
// removed from the interface, or some mappings/joins/filters have been added
// or had their locations changed, to create the correct source sets.
// Typically called before setting the KMs for the interface source set, or before calling <code>preparePersist</code>

 } catch (InexistentMappingException e) {
throw new OdiRuntimeException(e);
}

// Persisting the Interface
// Called to inform the ODI persistence layer that this interface will be persisted
 try {
helper.preparePersist();
} catch (oracle.odi.interfaces.interactive.exceptions.OdiInterfaceNotReadyForPersistException e) {
e.printStackTrace();
}</pre>
<p>After successful execution the interface is created successfully and with the columns added to target and mapped .</p>
<p>Also the IKM is set with the options specified.</p>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/08/image26.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/08/image_thumb26.png" alt="image" width="368" height="209" border="0" /></a></p>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/08/image27.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/08/image_thumb27.png" alt="image" width="592" height="346" border="0" /></a></p>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/08/image28.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/08/image_thumb28.png" alt="image" width="602" height="534" border="0" /></a></p>
<p>The Complete Java Code</p>
<pre class="brush:java">package odi.sdk;

import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

import oracle.odi.core.OdiInstance;
import oracle.odi.core.exception.OdiRuntimeException;
import oracle.odi.core.persistence.transaction.ITransactionStatus;
import oracle.odi.core.persistence.transaction.support.TransactionCallbackWithoutResult;
import oracle.odi.core.persistence.transaction.support.TransactionTemplate;
import oracle.odi.domain.model.OdiColumn;
import oracle.odi.domain.model.OdiDataStore;
import oracle.odi.domain.model.finder.IOdiDataStoreFinder;
import oracle.odi.domain.project.OdiFolder;
import oracle.odi.domain.project.OdiIKM;
import oracle.odi.domain.project.OdiInterface;
import oracle.odi.domain.project.OdiInterface.DatabaseSchema;
import oracle.odi.domain.project.OdiProject;
import oracle.odi.domain.project.ProcedureOption;
import oracle.odi.domain.project.finder.IOdiIKMFinder;
import oracle.odi.domain.project.finder.IOdiProjectFinder;
import oracle.odi.domain.project.finder.*;
import oracle.odi.domain.topology.finder.*;
import oracle.odi.domain.project.interfaces.DataSet;
import oracle.odi.domain.topology.OdiContext;
import oracle.odi.domain.topology.OdiLogicalSchema;
import oracle.odi.domain.topology.finder.IOdiContextFinder;
import oracle.odi.impexp.IImportService;
import oracle.odi.impexp.OdiImportException;
import oracle.odi.impexp.OdiImportNotSupportedException;
import oracle.odi.impexp.support.ImportServiceImpl;
import oracle.odi.interfaces.interactive.exceptions.UnknownActionException;
import oracle.odi.interfaces.interactive.support.InteractiveInterfaceHelperWithActions;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionAddSourceDataStore;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionOnStagingAreaSetLogicalSchema;
import oracle.odi.interfaces.interactive.support.actions.
InterfaceActionOnTemporaryTargetDataStoreAddColumn;
import oracle.odi.interfaces.interactive.support.actions.
InterfaceActionOnTemporaryTargetDataStoreSetDatabaseSchema;
import oracle.odi.interfaces.interactive.support.actions.
InterfaceActionOnTemporaryTargetDataStoreSetName;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKM;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKM.KMType;
import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetKMOptionValue;
import oracle.odi.interfaces.interactive.support.aliascomputers.AliasComputerDoubleChecker;
import oracle.odi.interfaces.interactive.support.clauseimporters.ClauseImporterLazy;
import oracle.odi.interfaces.interactive.support.km.optionretainer.KMOptionRetainerLazy;
import oracle.odi.interfaces.interactive.support.mapping.automap.AutoMappingComputerColumnName;
import oracle.odi.interfaces.interactive.support.sourceset.creators.InexistentMappingException;
import oracle.odi.publicapi.samples.SimpleOdiInstanceHandle;

public class TempIntf {

	private static OdiProject project;
	private static OdiFolder folder;
	private static OdiLogicalSchema oracleLogicalSchema;
	private static OdiContext context;

	public static void main(String[] args) {

	final SimpleOdiInstanceHandle odiInstanceHandle = SimpleOdiInstanceHandle
	.create("jdbc:oracle:thin:@localhost:1521:orcl",
	"oracle.jdbc.OracleDriver",
	"ODI_MASTER_11G",
	"ODI_MASTER_11G",
	"WORKREP1",
	"SUPERVISOR",
	"SUNOPSIS");

	final OdiInstance odiInstance = odiInstanceHandle.getOdiInstance();
	try {
	TransactionTemplate tx = new TransactionTemplate(odiInstance.getTransactionManager());
	tx.execute(new TransactionCallbackWithoutResult()
	{
	   protected void doInTransactionWithoutResult(ITransactionStatus pStatus)
	   {

		 // Find the Project
		 project = ((IOdiProjectFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiProject.class)).
findByCode("XMT");

		 // Find the folder
		 Collection fold = ((IOdiFolderFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiFolder.class)).
findByName("FOLDER");

	        for (java.util.Iterator it=fold.iterator(); it.hasNext();){
	          folder=(OdiFolder)it.next();
	        }
		 // Find the Context
		 context = ((IOdiContextFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class)).
findByCode("XMT");

		 //Find the Oracle Logical Schema
		 oracleLogicalSchema = ((IOdiLogicalSchemaFinder)odiInstance.getTransactionalEntityManager().
getFinder(OdiLogicalSchema.class)).
findByName("HR");

		 //Importing the KM

		// ImportServiceImpl(OdiInstance pOdiInstance) 

		IImportService importService = new ImportServiceImpl(odiInstance);

		try {

		// Specify the path of the XML files ok KM .
		String KM_PATH = "H:\\oracle\\ODI_Middleware\\Oracle_ODI1\\oracledi\\xml-reference";

		// Import the KMs using duplication mode

		// importObjectFromXml(int pImportMode, java.lang.String pFileName,
//		    IImportRoot pObjectParent, boolean pDeclareMissingRepository)
		// This method imports an object from an OracleDI export file (XML) under a parent object.

		importService.importObjectFromXml(IImportService.IMPORT_MODE_DUPLICATION, KM_PATH
		+ "\\KM_IKM SQL Control Append.xml",project, false);
		} catch (OdiImportNotSupportedException e) {

		throw new OdiRuntimeException(e);
		} catch (OdiImportException e) {throw new OdiRuntimeException(e);
		} catch (IOException e) {throw new OdiRuntimeException(e);
		}

		// Eclipse can help to create the Exception automatically if it
		// detects an Exception, so Exception handling can be easy task.

		// Creating a New Interface
		// OdiInterface(OdiFolder pFolder, java.lang.String pName, OdiContext pOptimizationContext) 

		OdiInterface intf = new OdiInterface(folder, "INTF_REGIONS",context);

		// Setting the above Context as the Optimization Context

		intf.setOptimizationContext(context); 

		// Creating DataSet to automatically assign different Source Data store
		// DataSet(OdiInterface pInterface, java.lang.String pName) 

		// A DataSet is a subset of sources that can be combined with other
		// DataSets using Set operators (such as UNION, MINUS, etc.). DataSets contain SourceDataStores, Joins, Filters and
		// TargetMappings (which are occurrences of mappings executed on Source or Staging Area.

		DataSet dataset = intf.getDataSets().iterator().next();

		// Reading the Source Data Store
		// Find the Data store using the IOdiDataStoreFinder

		OdiDataStore sourceDatastore = ((IOdiDataStoreFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).
findByName("REGIONS","HR");

		 // Creating the Target Data Store
		// Helper is to manipulate Odi interfaces in an interactive way

		// InteractiveInterfaceHelperWithActions(OdiInterface pInterface, OdiInstance pOdiInstance,
		// IOdiEntityManager pOdiEntityManager) 

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

		helper.performAction(new InterfaceActionAddSourceDataStore(sourceDatastore, dataset,
		new AliasComputerDoubleChecker(),new ClauseImporterLazy(),new AutoMappingComputerColumnName()));

		// Using the above create Logical Schema in place of Set
		// Staging area different from Target

		helper.performAction(new InterfaceActionOnStagingAreaSetLogicalSchema(oracleLogicalSchema));

		// Creating a Temporary Table Name so using the Format
		// Source Data Store + " TEMP"

		helper.performAction(new InterfaceActionOnTemporaryTargetDataStoreSetName(
		sourceDatastore.getName().toString() + "_TEMP"));

		// Setting the Schema as Work Schema ( Temporary Schema) where Temporary Table will be created

		helper.performAction(new InterfaceActionOnTemporaryTargetDataStoreSetDatabaseSchema(
		DatabaseSchema.TEMPORARY_SCHEMA));

		// Fetching the Source Columns and adding it to the target
		// table and performing the automatic Columns Mapping

		Object[] col = sourceDatastore.getColumns().toArray();
		for (int i = 0; i &lt; col.length; i++) {
		try {
		     OdiColumn column = (OdiColumn) col[i];
		     helper.performAction(new InterfaceActionOnTemporaryTargetDataStoreAddColumn(
		     column, new AutoMappingComputerColumnName()));
		// Each Source Column is read and added to target table and
		// automatically mapped using AutoMappingComputerColumnName

		 } catch (UnknownActionException e1) {e1.printStackTrace();}
		     }

		// Start mapping the KM
		// Since both the source and the Temporary Table is in the
		// same Data Server so no LKM only IKM

		// IKM
		// Find the IKM using the IOdiIKMFinder

		Collection ikm1 = ((IOdiIKMFinder) odiInstance
		.getTransactionalEntityManager().getFinder(
		OdiIKM.class)).findByName("IKM SQL Control Append", "XMT");

		for (Iterator iterator = ikm1.iterator(); iterator.hasNext();) {
		     OdiIKM odiIKM = (OdiIKM) iterator.next();

		// Fetching each option of the IKM
		for (ProcedureOption c : odiIKM.getOptions()) {
		// Setting the IKM in the interface
		helper.performAction(new InterfaceActionSetKM(
		odiIKM, intf.getTargetDataStore(),
		KMType.IKM, new KMOptionRetainerLazy()));

		// Modifying the Options of the IKM in the Interface
		helper.performAction(new InterfaceActionSetKMOptionValue(
		intf.getTargetDataStore(), KMType.IKM,"FLOW_CONTROL", false));

		helper.performAction(new InterfaceActionSetKMOptionValue(
		intf.getTargetDataStore(), KMType.IKM,"TRUNCATE", true));

		helper.performAction(new InterfaceActionSetKMOptionValue(
		intf.getTargetDataStore(), KMType.IKM,"CREATE_TARG_TABLE", true));

		}

		}

		// Compute the Interface sourceset

		try {
		helper.computeSourceSets();
		//Should be called at some point after source data stores are added to or
		// removed from the interface, or some mappings/joins/filters have been added
		// or had their locations changed, to create the correct source sets.
		// Typically called before setting the KMs for the interface source set, or before calling <code>preparePersist</code>

		 } catch (InexistentMappingException e) {
		throw new OdiRuntimeException(e);
		}

		// Persisting the Interface
		// Called to inform the ODI persistence layer that this interface will be persisted
		 try {
		helper.preparePersist();
		} catch (oracle.odi.interfaces.interactive.exceptions.OdiInterfaceNotReadyForPersistException e) {
		e.printStackTrace();
		}

		// Persist the Data Server , Physical and Logical Schema

		   //odiInstance.getTransactionalEntityManager().persist(oracleTechnology);

		   System.out.println("Done");

		   }
		   });
		   }  

		   finally 

		   {
		   odiInstanceHandle.release();
		   }
}

}</pre>
]]></content:encoded>
			<wfw:commentRss>http://odiexperts.com/creating-temporary-interface-using-odi-sdk/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating ODI Procedure using SDK</title>
		<link>http://odiexperts.com/creating-odi-procedure-using-sdk-2</link>
		<comments>http://odiexperts.com/creating-odi-procedure-using-sdk-2#comments</comments>
		<pubDate>Mon, 19 Sep 2011 04:22:17 +0000</pubDate>
		<dc:creator>Kshitiz Devendra</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[ODI]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Procedure]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://odiexperts.com/?p=3139</guid>
		<description><![CDATA[This post is about to create ODI procedure using the SDK codes. The logic is pretty simple Initially find the Project, Folder , Technology and store them into Variable. Declare a new ODI Procedure Add the Line and for each line define the parameters , technology and expression for Target and Source if required Finally [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush:java">This post is about to create ODI procedure using the SDK codes.</pre>
<ul>
<li>The logic is pretty simple Initially find the Project, Folder , Technology and store them into Variable.</li>
<li>Declare a new ODI Procedure</li>
<li>Add the Line and for each line define the parameters , technology and expression for Target and Source if required</li>
<li>Finally persist the Procedure.</li>
</ul>
<pre class="brush:java">// Find the Context
context = ((IOdiContextFinder)odiInstance.getTransactionalEntityManager().
getFinder(OdiContext.class)).
findByCode("XMT");

//Find the Oracle Logical Schema
oracleLogicalSchema = ((IOdiLogicalSchemaFinder)odiInstance.getTransactionalEntityManager().
getFinder(OdiLogicalSchema.class)).
findByName("HR");

//Find the Oracle Technology
oracleTechnology =((IOdiTechnologyFinder)odiInstance.getTransactionalEntityManager().
getFinder(OdiTechnology.class)).
findByCode("ORACLE");

// Creating a New Procedure of the name test_pro under the folder(FOLDER)
OdiUserProcedure pro=new OdiUserProcedure(folder ,"test_pro");
// Creating the first line
 pro.addLine("first_line");

// Declaring the Line Command
OdiProcedureLineCmd cmd =new OdiProcedureLineCmd();
// Add the required properties for the command
cmd.setExecutionContext(context);
cmd.setTechnology(oracleTechnology);
cmd.setLogicalSchema(oracleLogicalSchema);
cmd.setAutoCommitMode();

// defining the experssion and set it to the command
String expr = "Select 1 from dual";
cmd.setExpression(new Expression(expr, null,SqlGroupType.NONE));           

//for each line add the required properties from above.
for (OdiUserProcedureLine line: pro.getLines()) {
     System.out.print(line);
     line.setOnTargetCommand(cmd);
     line.setLogLevel(4);
     line.setLogCounter(LogCounter.INSERT);
           }

// Persist(save) the Procedure 

odiInstance.getTransactionalEntityManager().persist(pro);</pre>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/09/image.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/09/image_thumb.png" alt="image" width="159" height="109" border="0" /></a></p>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/09/image1.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/09/image_thumb1.png" alt="image" width="702" height="55" border="0" /></a></p>
<p><a href="http://odiexperts.com/wp-content/uploads/2011/09/image2.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="image" src="http://odiexperts.com/wp-content/uploads/2011/09/image_thumb2.png" alt="image" width="644" height="198" border="0" /></a></p>
<p><strong>Java Codes</strong></p>
<pre class="brush:java">package odi.sdk;

import java.util.Collection;

import oracle.odi.core.OdiInstance;
import oracle.odi.core.persistence.transaction.ITransactionStatus;
import oracle.odi.core.persistence.transaction.support.TransactionCallbackWithoutResult;
import oracle.odi.core.persistence.transaction.support.TransactionTemplate;
import oracle.odi.domain.project.OdiFolder;
import oracle.odi.domain.project.OdiProcedureLine.LogCounter;
import oracle.odi.domain.project.OdiProcedureLineCmd;
import oracle.odi.domain.project.OdiProject;
import oracle.odi.domain.project.OdiUserProcedure;
import oracle.odi.domain.project.OdiUserProcedureLine;
import oracle.odi.domain.project.finder.IOdiFolderFinder;
import oracle.odi.domain.project.finder.IOdiProjectFinder;
import oracle.odi.domain.topology.OdiContext;
import oracle.odi.domain.topology.OdiLogicalSchema;
import oracle.odi.domain.topology.OdiTechnology;
import oracle.odi.domain.topology.finder.IOdiContextFinder;
import oracle.odi.domain.topology.finder.IOdiLogicalSchemaFinder;
import oracle.odi.domain.topology.finder.IOdiTechnologyFinder;
import oracle.odi.domain.xrefs.expression.Expression;
import oracle.odi.domain.xrefs.expression.Expression.SqlGroupType;
import oracle.odi.publicapi.samples.SimpleOdiInstanceHandle;

public class OdiProc {

	private static OdiProject project;
	private static OdiFolder folder;
	private static OdiLogicalSchema oracleLogicalSchema;
	private static OdiContext context;
	private static OdiTechnology oracleTechnology;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		final SimpleOdiInstanceHandle odiInstanceHandle = SimpleOdiInstanceHandle
		.create("jdbc:oracle:thin:@localhost:1521:orcl",
		"oracle.jdbc.OracleDriver",
		"ODI_MASTER_11G",
		"ODI_MASTER_11G",
		"WORKREP1",
		"SUPERVISOR",
		"SUNOPSIS");

		final OdiInstance odiInstance = odiInstanceHandle.getOdiInstance();
		try {
		TransactionTemplate tx = new TransactionTemplate(odiInstance.getTransactionManager());
		tx.execute(new TransactionCallbackWithoutResult()
		{
		   protected void doInTransactionWithoutResult(ITransactionStatus pStatus)
		   {

			// Find the Project
			project = ((IOdiProjectFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiProject.class)).
findByCode("XMT");

			// Find the folder
			Collection fold = ((IOdiFolderFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiFolder.class)).
findByName("FOLDER");

			for (java.util.Iterator it=fold.iterator(); it.hasNext();){
			     folder=(OdiFolder)it.next();
			     }

			// Find the Context
			context = ((IOdiContextFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class)).
findByCode("XMT");

			//Find the Oracle Logical Schema
			oracleLogicalSchema = ((IOdiLogicalSchemaFinder)odiInstance.getTransactionalEntityManager().
getFinder(OdiLogicalSchema.class)).
findByName("HR");

			//Find the Oracle Technology
			oracleTechnology =((IOdiTechnologyFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiTechnology.class)).
findByCode("ORACLE");

			OdiUserProcedure pro=new OdiUserProcedure(folder ,"test_pro");
            pro.addLine("first_line");

            OdiProcedureLineCmd cmd =new OdiProcedureLineCmd();
            cmd.setExecutionContext(context);
            cmd.setTechnology(oracleTechnology);
            cmd.setLogicalSchema(oracleLogicalSchema);
            cmd.setAutoCommitMode();

           String expr = "Select 1 from dual";
           cmd.setExpression(new Expression(expr, null,SqlGroupType.NONE));           

            for (OdiUserProcedureLine line: pro.getLines()) {
                  System.out.print(line);
                  line.setOnTargetCommand(cmd);
                  line.setLogLevel(4);
                  line.setLogCounter(LogCounter.INSERT);
            }

            odiInstance.getTransactionalEntityManager().persist(pro);

            //Done
			System.out.println("Done");

		   }
		   });
		   }  

		   finally 

		   {
		   odiInstanceHandle.release();
		   }

	}

}</pre>
]]></content:encoded>
			<wfw:commentRss>http://odiexperts.com/creating-odi-procedure-using-sdk-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.662 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-01-27 13:58:32 -->
<!-- Compression = gzip -->
