ODI:如何使用groovy sdk将变量添加到装载计划中

时间:2017-10-31 23:35:30

标签: groovy oracle-data-integrator

我是groovy脚本语言的新手。我正在使用它在ODI中创建加载计划。我写了一个接受两个参数的方法    - loadPlanName    - varName 这些参数是存储库中预先存在的对象的名称。

import oracle.odi.core.persistence.transaction.ITransactionDefinition;
import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition;
import oracle.odi.core.persistence.transaction.ITransactionManager;
import oracle.odi.core.persistence.transaction.ITransactionStatus;
import oracle.odi.core.persistence.IOdiEntityManager;
import oracle.odi.domain.project.OdiProject;
import oracle.odi.domain.project.OdiVariable;
import oracle.odi.domain.project.finder.IOdiProjectFinder;
import oracle.odi.domain.project.finder.IOdiVariableFinder;
import oracle.odi.domain.topology.finder.IOdiLogicalSchemaFinder;
import org.codehaus.groovy.runtime.*;
import oracle.odi.domain.topology.OdiLogicalSchema;
import oracle.odi.domain.xrefs.expression.ExpressionStringBuilder;
import oracle.odi.languages.ILanguageProvider;
import oracle.odi.languages.support.LanguageProviderImpl;
import oracle.odi.domain.runtime.loadplan.OdiLoadPlan;
import oracle.odi.domain.runtime.loadplan.finder.IOdiLoadPlanFinder;
import oracle.odi.domain.runtime.scenario.OdiScenarioFolder;
import oracle.odi.domain.runtime.scenario.finder.IOdiScenarioFolderFinder;
import oracle.odi.generation.*;

def addVariable(loadPlanName, varName) {
  loadPlan = ((IOdiLoadPlanFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiLoadPlan.class)).findByName(loadPlanName);
  var = ((IOdiVariableFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiVariable.class)).findByQualifiedName(varName);

  varTextGenerator = (IOdiVariableTextGenerator).generateLoadPlanVarText(var.getVariableId());
  loadPlan.addVariable(var, varTextGenerator);
}

addVariable('myOdiLoadPlan', 'myOdiVariableName')

然而,行

varTextGenerator = (IOdiVariableTextGenerator).generateLoadPlanVarText(var.getVariableId());

无法执行以下错误..

No signature of method: static oracle.odi.generation.IOdiVariableTextGenerator.generateLoadPlanVarText() is applicable for argument types: (java.math.BigDecimal) values: [59]
(Subtract 18 from the error line number to account for the standard imports)
groovy.lang.MissingMethodException: No signature of method: static oracle.odi.generation.IOdiVariableTextGenerator.generateLoadPlanVarText() is applicable for argument types: (java.math.BigDecimal) values: [59]
    at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1500)
    at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1486)
    at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:53)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at ADW_30_Create_Load_Plans.addVariable(ADW_30_Create_Load_Plans.groovy:124)
    at ADW_30_Create_Load_Plans$addVariable$2.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:190)
    at ADW_30_Create_Load_Plans.run(ADW_30_Create_Load_Plans.groovy:147)
    at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
    at groovy.lang.GroovyShell.run(GroovyShell.java:518)
    at groovy.lang.GroovyShell.run(GroovyShell.java:497)
    at groovy.lang.GroovyShell.run(GroovyShell.java:170)
    at oracle.di.studio.groovy.GroovyScriptRunInstance.run(GroovyScriptRunInstance.java:222)

我尝试过使用

  varTextGenerator = (IOdiVariableTextGenerator).generateLoadPlanVarText(var.getNumericId());

但这也不起作用。 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我解决了。

我用来向Load计划添加变量的groovy代码是

def addVariable(loadPlanName, varName) {
  txnDef = new DefaultTransactionDefinition();
  tm = odiInstance.getTransactionManager()
  txnStatus = tm.getTransaction(txnDef)

  varTextGen = new OdiVariableTextGeneratorDwgImpl(odiInstance)

  lPlan = ((IOdiLoadPlanFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiLoadPlan.class)).findByName(loadPlanName);
  var = ((IOdiVariableFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiVariable.class)).findByQualifiedName(varName);

  lPlanVariable = lPlan.addVariable(var, varTextGen);
  odiInstance.getTransactionalEntityManager().persist(lPlan);
  tm.commit(txnStatus);
}