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 persist the Procedure.
// 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);
Java Codes
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(); } } }