/* * Use this groovy script from the ODI Groovy panel to quickly configure * datastores with SCD metadata processed from a file. * * The file (defined in variable inputFile below) has 4 comma separated fields * model_code,datastore_name,{column_name|*}[,scd_type_string] * The scd_type_string is a value from OdiColumn.ScdType in the ODI SDK * The column_name can be replaced with asterisk, so you can set all columns * * For example you can set the metadata as such; WAREHOUSE_MODEL,DIM_CUSTOMER,*,OVERWRITE_ON_CHANGE WAREHOUSE_MODEL,DIM_CUSTOMER,KEY,SURROGATE_KEY WAREHOUSE_MODEL,DIM_CUSTOMER,C_BID,NATURAL_KEY WAREHOUSE_MODEL,DIM_CUSTOMER,CURRENT_IND,CURRENT_RECORD_FLAG WAREHOUSE_MODEL,DIM_CUSTOMER,C_EFF,START_TIMESTAMP WAREHOUSE_MODEL,DIM_CUSTOMER,C_EXP,END_TIMESTAMP WAREHOUSE_MODEL,DIM_CUSTOMER,C_MSTAT,ADD_ROW_ON_CHANGE * * If you want to reset all the SCD descriptors you can omit the scd_type_string * WAREHOUSE_MODEL,DIM_CUSTOMER,*,OVERWRITE_ON_CHANGE */ import oracle.odi.core.OdiInstance import oracle.odi.domain.model.finder.IOdiDataStoreFinder import oracle.odi.domain.model.finder.IOdiColumnFinder import oracle.odi.domain.model.OdiDataStore import oracle.odi.domain.model.OdiColumn import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition import java.io.* def inputFile = "c:\\temp\\in.csv" def trans = odiInstance.getTransactionManager().getTransaction(new DefaultTransactionDefinition()) def df = (IOdiDataStoreFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class) def cf = (IOdiColumnFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiColumn.class) def inp = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile))) def inpStr = "" def srcmodel = "" def srctab = "" while ((inpStr = inp.readLine()) != null && inpStr.length() != 0) { def toks = inpStr.split(",") if (toks.length < 3) {System.err.println("Error in input, line: "+inpStr) continue } if (toks[0] != null && toks[0].size() > 0) srcmodel = toks[0] if (toks[1] != null && toks[1].size() > 0) srctab = toks[1] def srccol = toks[2] def typ = null if (toks.length > 3) { typ = toks[3]; } if (typ != null) typ = OdiColumn.ScdType.valueOf(typ); def odiDatastore = df.findByName(srctab, srcmodel) if (srccol == "*") { def cols = odiDatastore.getColumns(); for (int i = 0; i < cols.size(); i++) { def odiColumn = cols.get(i); odiColumn.setScdType( typ ); odiInstance.getTransactionalEntityManager().persist(odiColumn) } } else { def odiColumn = cf.findByName(srccol, odiDatastore.getDataStoreId()) odiColumn.setScdType( typ ); odiInstance.getTransactionalEntityManager().persist(odiColumn) } } odiInstance.getTransactionManager().commit(trans)