Criar interface permanente com base no nível Model
Este ODI códigos SDK particular cria uma fonte para uma interface de destino e, portanto, gerar Scenario, com base na condição em que a tabela Fonte é o mesmo que Target Table nome , sob dois diferentes Model.
Por padrão, o nome alvo datastore é usado como o Nome da Interface.
Para este exemplo, o Model Fonte é esquema de HR e também o Model Alvo é esquema de HR.
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");
}
}

dezembro 25, 2013 at 8:29 AM
Hi Cezar
can You help me?
I created a very simple interface, basically an
INSERT INTO TRG_EMP SELECT from 2 tables
But when I execute the interface I got
“org.apache.bsf.BSFException: exception from Groovy: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Insert_flow_into_I$_table: 6: unexpected char: ‘\’ @ line 6, column 18.
logFileName = ‘C:\Users\lczinkoc\ikm_rowbyrow.log’ ”
(The C$_TRG_EMP created and poputalet the I$_TRG_EMP created anf NOT populated”
What should I do the execute successfuly this very simple interface?
Many thanks in advance!
Laszlo