标签:des style http io ar os 使用 sp for
本文主要介绍在ODI中使用groovy创建工程,并添加一个表转换的映射。要创建groovy脚本,可以从ODI Studio的菜单:工具->Groovy->新脚本 打开一个编辑窗口。在执行下面的脚本之前,确认在模型中已经有EMP表。
USERSRC
USERDEST
import oracle.odi.domain.project.OdiProject
import oracle.odi.domain.project.finder.IOdiProjectFinder
import oracle.odi.domain.model.finder.IOdiDataStoreFinder
import oracle.odi.domain.project.finder.IOdiFolderFinder
import oracle.odi.domain.project.finder.IOdiKMFinder
import oracle.odi.domain.mapping.finder.IMappingFinder
import oracle.odi.domain.adapter.project.IKnowledgeModule.ProcessingType
import oracle.odi.domain.model.OdiDataStore
import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition
def setExpr(comp, tgtTable, propertyName, expressionText) {
DatastoreComponent.findAttributeForColumn(comp,tgtTable.getColumn(propertyName)).setExpressionText(expressionText)
}
// 工程创建函数
def createProject(project_name, project_folder_name){
project_code = project_name
txnDef = new DefaultTransactionDefinition();
tm = odiInstance.getTransactionManager()
tme = odiInstance.getTransactionalEntityManager()
txnStatus = tm.getTransaction(txnDef)
pf = (IOdiProjectFinder)tme.getFinder(OdiProject.class)
ff = (IOdiFolderFinder)tme.getFinder(OdiFolder.class)
project = pf.findByCode(project_name)
if (project != null) {
println "Project Already Exists. Project Creation Skipped"
}
else{
project = new OdiProject(project_name, project_name)
tme.persist(project)
folder = new OdiFolder(project, project_folder_name)
tme.persist(folder)
tm.commit(txnStatus)
println "Project Created Successfully"
}
}
//映射创建函数
def createMapping(project_name,project_folder_name,myMap) {
txnDef = new DefaultTransactionDefinition()
tm = odiInstance.getTransactionManager()
tme = odiInstance.getTransactionalEntityManager()
txnStatus = tm.getTransaction(txnDef)
pf = (IOdiProjectFinder)tme.getFinder(OdiProject.class)
ff = (IOdiFolderFinder)tme.getFinder(OdiFolder.class)
project = pf.findByCode(project_name)
folderColl = ff.findByName(project_folder_name, project_name)
OdiFolder folder = null
if (folderColl.size() == 1)
folder = folderColl.iterator().next()
dsf = (IOdiDataStoreFinder)tme.getFinder(OdiDataStore.class)
mapf = (IMappingFinder) tme.getFinder(Mapping.class)
Mapping map = (mapf).findByName(folder, myMap)
if ( map!=null) {
println "Map Already Exists. Map Creation Skipped"
}
else{
map = new Mapping(myMap, folder)
tme.persist(map)
ds_source = dsf.findByName("EMP", "USERSRC")
ds_src_comp = new DatastoreComponent(map, ds_source)
ds_target = dsf.findByName("EMP", "USERDEST")
ds_tgt_comp = new DatastoreComponent(map, ds_target)
ds_src_comp.connectTo(ds_tgt_comp)
setExpr(ds_tgt_comp, ds_target, "EMPNO", "EMP.EMPNO")
setExpr(ds_tgt_comp, ds_target, "ENAME", "EMP.ENAME")
setExpr(ds_tgt_comp, ds_target, "JOB", "EMP.JOB")
setExpr(ds_tgt_comp, ds_target, "MGR", "EMP.MGR")
setExpr(ds_tgt_comp, ds_target, "HIREDATE", "EMP.HIREDATE")
setExpr(ds_tgt_comp, ds_target, "SAL", "EMP.SAL")
setExpr(ds_tgt_comp, ds_target, "COMM", "EMP.COMM")
setExpr(ds_tgt_comp, ds_target, "DEPTNO", "EMP.DEPTNO")
deploymentspec = map.getDeploymentSpec(0)
node = deploymentspec.findNode(ds_tgt_comp)
println deploymentspec.getExecutionUnits()
aps = deploymentspec.getAllAPNodes()
tgts = deploymentspec.getTargetNodes()
ikmf = (IOdiKMFinder)tme.getFinder(OdiIKM.class)
ins_ikm = ikmf.findByName("IKM Oracle Insert");
lkmf = (IOdiKMFinder)tme.getFinder(OdiLKM.class)
sql_lkm = lkmf.findByName("LKM Oracle to Oracle Pull (DB Link)");
api = aps.iterator()
ap_node = api.next()
ap_node.setLKM(sql_lkm)
ap_node.getOptionValue(ProcessingType.TARGET,"ADD_DRIVING_SITE_HINT").setValue("true")
tme.persist(map)
tm.commit(txnStatus)
println "Mapping Created SUccessfully"
}
}
//创建映射结束
//执行
createProject("PRO_SCOTT","First Folder")
createMapping("PRO_SCOTT", "First Folder", "New_Mapping")
点击执行脚本,即可看到生成的工程名(PRO_SCOTT)及映射名称(New_Mapping)
标签:des style http io ar os 使用 sp for
原文地址:http://www.cnblogs.com/margiex/p/4153637.html