I'm using groovy to edit an existing mapping in ODI 12.2. In the mapping there is already an source datastore and a target datastore. I want to use it, but I keep duplicating the source and target datastore. Is there way to do this?
I'm new to groovy any help would be extremely helpful.
//mapping
txnDef = new DefaultTransactionDefinition()
tm = odiInstance.getTransactionManager()
tme = odiInstance.getTransactionalEntityManager()
txnStatus = tm.getTransaction(txnDef)
Mapping map = ((IMappingFinder) tme.getFinder(Mapping.class)).findByName(folder, mappingName)
dsf = (IOdiDataStoreFinder)tme.getFinder(OdiDataStore.class)
mapf = (IMappingFinder) tme.getFinder(Mapping.class)
tme.persist(map)
//insert source table
boundTo_emp = dsf.findByName(SRCdatastore, SRCmodel)
comp_emp = new DatastoreComponent(map, boundTo_emp)
//insert target table
boundTo_tgtemp = dsf.findByName(TRGdatastore, TGRmodel)
comp_tgtemp = new DatastoreComponent(map, boundTo_tgtemp)
comp_emp.connectTo(comp_tgtemp)
createExp(comp_tgtemp, boundTo_tgtemp, "LAST_NAME", "SRC_CUSTOMER.LAST_NAME")
deploymentspec = map.getDeploymentSpec(0)
node = deploymentspec.findNode(comp_tgtemp)
println deploymentspec.getExecutionUnits()
aps = deploymentspec.getAllAPNodes()
tgts = deploymentspec.getTargetNodes()
tme.persist(map)
tm.commit(txnStatus)
I want it to edit my existing expression from source to target datastore but instead it creates a duplicate source and target datastore and add the expression there.
You are creating new DatastoreComponents instead of using the existing ones from the mapping. You can find the existing ones by invoking findComponent method on your mapping.
Try replacing
comp_emp = new DatastoreComponent(map, boundTo_emp)
with
comp_emp = map.findComponent(SRCdatastore)
Same goes for the target component.
You can also remove the following line if the source and target are already connected in the mapping :
comp_emp.connectTo(comp_tgtemp)