본문 바로가기

ETL Tools/Oracle Data Integrator

[ODI 11g SDK] Data Lineage

/************************* TIP ************************/
using recursive function

//*** Get table lineage from interface
//***** pseudo code
//***** find interface using both findByTargetDataStore and findBySourceDataStore in the IOdiInterfaceFinder class
//***** made by Cheon Jeonghyeon on 2012.01.10
//***** 

function(tableName, modelName, OdiInstance)
{
   Get Table ID from 'tableName, modelName';
   Get Interfaces from TableID;
   if not exists
      end;
   else
   for(interfaces) 
      Get datasets from interface;
      Get mapping statement of column from 'columnName';
      for(datasets)
         Get sources from dataset;
         for(sources)
               call function(source table, source model, OdiInstance);
 }


//*** Get table column lineage from interface
//***** pseudo code
//***** find interface using both findByTargetDataStore and findBySourceDataStore in the IOdiInterfaceFinder class
//***** made by Cheon Jeonghyeon on 2012.01.10
//***** 

function(tableName, modelName, OdiInstance, columnName)
{
   Get Table ID from 'tableName, modelName';
   Get Interfaces from TableID;
   if not exists
      end;
   else 
   for(interfaces) 
      Get datasets from interface;
      Get mapping statement of column from 'columnName';
      for(datasets)
         Get sources from dataset;
         for(sources)
             Get alias from source;
             Get columns from source;
                for(columns)
                Compare string 'alias.column' with mapping;
                if exists
                   call function(source table, source model, OdiInstance, the column);
                else 
                   end; 
 }


package odi.widetns;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import odi.lineage.vo.LineageVO;
import oracle.odi.domain.model.OdiColumn;
import oracle.odi.domain.model.OdiDataStore;
import oracle.odi.domain.model.finder.IOdiDataStoreFinder;
import oracle.odi.domain.project.OdiInterface;
import oracle.odi.domain.project.finder.IOdiInterfaceFinder;
import oracle.odi.domain.project.interfaces.DataSet;
import oracle.odi.domain.project.interfaces.SourceDataStore;
import oracle.odi.domain.project.interfaces.TargetMapping;
import oracle.odi.domain.xrefs.CrossRef;

public class OdiWideTNSLineage extends OdiWideTNSRepository {

/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/
/**************** 01. Calling Data Lineage Constructor ******************/
/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/

public OdiWideTNSLineage(String jdbcUrl, String driver, String mstRepId,
String mstRepPwd, String workrepName, String odiUser,
String odiPassword) {
super(jdbcUrl, driver, mstRepId, mstRepPwd, workrepName, odiUser,
odiPassword);
}

public OdiWideTNSLineage(String[] params) throws Exception {
this(params[0], params[1], params[2], params[3], params[4], params[5],
params[6]);
}

/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/
/**************** 02. Calling Function Data Lineage ******************/
/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/

public void dataLineageCheck(String strTable, String strModel) {
if (odiInstance == null)
return;
recurSourceTable(strTable, strModel);
recurTargetTable(strTable, strModel);
}

public LineageVO dataLineage(String strTable, String strModel) {
if (odiInstance == null)
return null;
LineageVO l = new LineageVO(strTable, strModel);
recurSourceTable(strTable, strModel, 0, l);
recurTargetTable(strTable, strModel, 0, l);
return l;
}

public List<LineageVO> dataLineageList(String strTable, String strModel) {
ArrayList<LineageVO> lst = new ArrayList<LineageVO>();
if (odiInstance == null)
return null;
LineageVO l = new LineageVO(strTable, strModel);
lst.add(l);
recurSourceTable(strTable, strModel, 0, l, lst);
recurTargetTable(strTable, strModel, 0, l, lst);
return lst;
}

/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/
/**************** 03. Calling Function Data Mapping Lineage ******************/
/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/

public void dataLineageCheck(String strTable, String strModel,
String strColumn) {
if (odiInstance == null)
return;
recurSourceTable(strTable, strModel, strColumn);
recurTargetTable(strTable, strModel, strColumn);
}

public LineageVO dataLineage(String strTable, String strModel,
String strColumn) {
if (odiInstance == null)
return null;
LineageVO l = new LineageVO(strTable, strColumn, strModel);
recurSourceTable(strTable, strModel, strColumn, 0, l);
recurTargetTable(strTable, strModel, strColumn, 0, l);
return l;
}

public List<LineageVO> dataLineageList(String strTable, String strModel,
String strColumn) {
if (odiInstance == null)
return null;
LineageVO l = new LineageVO(strTable, strColumn, strModel);
ArrayList<LineageVO> lst = new ArrayList<LineageVO>();
lst.add(l);
recurSourceTable(strTable, strModel, strColumn, 0, l, lst);
recurTargetTable(strTable, strModel, strColumn, 0, l, lst);
return lst;
}

/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/
/**************** 04. Data Lineage using Table ******************/
/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/

// private function for Data lineage
private void recurSourceTable(String srcTable, String srcModel, int nLevel,
LineageVO lineage) {

Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;
DataSet dataset;
SourceDataStore sds;
LineageVO newLineage;

/** process procedure **/

// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(srcTable, srcModel).getDataStoreId();

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findByTargetDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;

nLevel--;
for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {

// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();
for (Iterator<DataSet> dataset_iter = inf.getDataSets().iterator(); dataset_iter
.hasNext();) {
// 5. for statement for looking through data sets
dataset = (DataSet) dataset_iter.next();
for (Iterator<SourceDataStore> src_iter = dataset
.getSourceDataStores().iterator(); src_iter.hasNext();) {
// 6. for statement for looking through source tables
sds = (SourceDataStore) src_iter.next();

// 7. Call myself with source table and model names
newLineage = new LineageVO(null, lineage, nLevel,
sds.getName(), sds.getUnderlyingOdiDataStore()
.getModel().getCode(), inf.getName());
lineage.addSrcTable(newLineage);
recurSourceTable(sds.getName(), sds
.getUnderlyingOdiDataStore().getModel().getCode(),
nLevel, newLineage);
}
}
}
}

private void recurTargetTable(String trgTable, String trgModel, int nLevel,
LineageVO lineage) {
Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;
LineageVO newLineage;

/** process procedure **/

// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(trgTable, trgModel).getDataStoreId();

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findBySourceDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;
nLevel++;
for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {

// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();
newLineage = new LineageVO(lineage, null, nLevel, inf
.getTargetDataStore().getName(), inf.getTargetDataStore()
.getUnderlyingOdiDataStore().getModel().getCode(),
inf.getName());
lineage.addTrgTable(newLineage);

// 5. Call myself with
recurTargetTable(inf.getTargetDataStore().getName(), inf
.getTargetDataStore().getUnderlyingOdiDataStore()
.getModel().getCode(), nLevel, newLineage);
}
}

/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/
/**************** 05. Data Lineage List using Table ******************/
/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/

private void recurSourceTable(String srcTable, String srcModel, int nLevel,
LineageVO lineage, List<LineageVO> lst) {

Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;
DataSet dataset;
SourceDataStore sds;
LineageVO newLineage;

/** process procedure **/

// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(srcTable, srcModel).getDataStoreId();

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findByTargetDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;

nLevel--;
for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {

// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();
for (Iterator<DataSet> dataset_iter = inf.getDataSets().iterator(); dataset_iter
.hasNext();) {
// 5. for statement for looking through data sets
dataset = (DataSet) dataset_iter.next();
for (Iterator<SourceDataStore> src_iter = dataset
.getSourceDataStores().iterator(); src_iter.hasNext();) {
// 6. for statement for looking through source tables
sds = (SourceDataStore) src_iter.next();

// 7. Call myself with source table and model names
newLineage = new LineageVO(null, lineage, nLevel,
sds.getName(), sds.getUnderlyingOdiDataStore()
.getModel().getCode(), inf.getName());
lineage.addSrcTable(newLineage);
lst.add(newLineage);
recurSourceTable(sds.getName(), sds
.getUnderlyingOdiDataStore().getModel().getCode(),
nLevel, newLineage, lst);
}
}
}
}

private void recurTargetTable(String trgTable, String trgModel, int nLevel,
LineageVO lineage, List<LineageVO> lst) {
Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;
LineageVO newLineage;

/** process procedure **/

// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(trgTable, trgModel).getDataStoreId();

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findBySourceDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;
nLevel++;
for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {

// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();
newLineage = new LineageVO(lineage, null, nLevel, inf
.getTargetDataStore().getName(), inf.getTargetDataStore()
.getUnderlyingOdiDataStore().getModel().getCode(),
inf.getName());
lineage.addTrgTable(newLineage);
lst.add(newLineage);
// 5. Call myself with
recurTargetTable(inf.getTargetDataStore().getName(), inf
.getTargetDataStore().getUnderlyingOdiDataStore()
.getModel().getCode(), nLevel, newLineage, lst);
}
}

/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/
/**************** 06. Data Mapping Lineage using Table and Column ******************/
/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/

private void recurSourceTable(String srcTable, String srcModel,
String strColumn, int nLevel, LineageVO lineage) {
Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;
DataSet dataset;
LineageVO newLineage;
// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(srcTable, srcModel).getDataStoreId();

// System.out.println("Table : "+srcTable);
// System.out.println("Data Store ID : "+tableId);

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findByTargetDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;

nLevel--;
for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {
// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();

// System.out.println(" Interface : "+ inf.getName());

for (Iterator<DataSet> dataset_iter = inf.getDataSets().iterator(); dataset_iter
.hasNext();) {
// 5. for statement for looking through datasets
dataset = (DataSet) dataset_iter.next();
lineage.addMapping(dataset.getMapping(strColumn).getSql());

// System.out.println("  Data Set : "+
// dataset.getName()+" Mapping : "+
// dataset.getMapping(strColumn).getSqlExpression());

for (CrossRef<?> odiColumn : dataset.getMapping(strColumn)
.getSqlExpression().getCrossRefs()) {
// 6. Get source column and table names related with Mapping
// Information

// System.out.println("  Source Table : "+
// ((OdiColumn)odiColumn.getReferencedObject()).getTable().getName()
// + " Column : "
// +((OdiColumn)odiColumn.getReferencedObject()).getName());

newLineage = new LineageVO(null, lineage, nLevel,
((OdiColumn) odiColumn.getReferencedObject())
.getTable().getName(),
((OdiColumn) odiColumn.getReferencedObject())
.getName(),
((OdiColumn) odiColumn.getReferencedObject())
.getTable().getModel().getCode(),
inf.getName());
lineage.addSrcTable(newLineage);
// 7. Call myself with those
recurSourceTable(
((OdiColumn) odiColumn.getReferencedObject())
.getTable().getName(),
((OdiColumn) odiColumn.getReferencedObject())
.getTable().getModel().getCode(),
((OdiColumn) odiColumn.getReferencedObject())
.getName(), nLevel, newLineage);
}
}
}
}

private void recurTargetTable(String trgTable, String trgModel,
String strColumn, int nLevel, LineageVO lineage) {
Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;
DataSet dataset;
TargetMapping targetMapping;
LineageVO newLineage;

// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(trgTable, trgModel).getDataStoreId();

System.out.println("Table : " + trgTable);
System.out.println("Data Store ID : " + tableId);

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findBySourceDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;
nLevel++;
for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {
// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();

// System.out.println(" Interface : "+ inf.getName());

for (Iterator<DataSet> dataset_iter = inf.getDataSets().iterator(); dataset_iter
.hasNext();) {
// 5. for statement for looking through datasets
dataset = (DataSet) dataset_iter.next();

// System.out.println("  Data Set : " + dataset.getName());

for (Iterator<TargetMapping> col_iter = dataset.getMappings()
.iterator(); col_iter.hasNext();) {
// 6. for statement for looking through columns
targetMapping = col_iter.next();

// System.out.println("  Table : "+ trgTable + " Column : "
// + strColumn);

for (CrossRef<?> odiColumn : targetMapping
.getSqlExpression().getCrossRefs()) {
// 7. for statement for getting source columns related
// with a target column

// System.out.println("  Source Table : "+
// ((OdiColumn)odiColumn.getReferencedObject()).getTable().getName()
// + " Column : "
// +((OdiColumn)odiColumn.getReferencedObject()).getName());

if (trgTable.equals(((OdiColumn) odiColumn
.getReferencedObject()).getTable().getName()
.toString())
&& strColumn.equals(((OdiColumn) odiColumn
.getReferencedObject()).getName())) {
// 8. if there exist any relationship with the
// column, call myself with those infos

// System.out.println("  equals "+inf.getTargetDataStore().getUnderlyingOdiDataStore().getName()
// +"."+targetMapping.getTargetColumn().getName());

newLineage = new LineageVO(lineage, null, nLevel,
inf.getTargetDataStore()
.getUnderlyingOdiDataStore()
.getName(), targetMapping
.getTargetColumn().getName(), inf
.getTargetDataStore()
.getUnderlyingOdiDataStore()
.getModel().getCode(),
targetMapping.getSql(), inf.getName());
lineage.addTrgTable(newLineage);

recurTargetTable(inf.getTargetDataStore()
.getUnderlyingOdiDataStore().getName(), inf
.getTargetDataStore()
.getUnderlyingOdiDataStore().getModel()
.getCode(), targetMapping.getTargetColumn()
.getName(), nLevel, newLineage);
}
}
}
}
}
}

/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/
/************* 07. Data Mapping Lineage List using Table and Column ****************/
/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/

private void recurSourceTable(String srcTable, String srcModel,
String strColumn, int nLevel, LineageVO lineage, List<LineageVO> lst) {
Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;
DataSet dataset;
LineageVO newLineage;
// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(srcTable, srcModel).getDataStoreId();

// System.out.println("Table : "+srcTable);
// System.out.println("Data Store ID : "+tableId);

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findByTargetDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;

nLevel--;
for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {
// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();

// System.out.println(" Interface : "+ inf.getName());

for (Iterator<DataSet> dataset_iter = inf.getDataSets().iterator(); dataset_iter
.hasNext();) {
// 5. for statement for looking through datasets
dataset = (DataSet) dataset_iter.next();
lineage.addMapping(dataset.getMapping(strColumn).getSql());

// System.out.println("  Data Set : "+
// dataset.getName()+" Mapping : "+
// dataset.getMapping(strColumn).getSqlExpression());

for (CrossRef<?> odiColumn : dataset.getMapping(strColumn)
.getSqlExpression().getCrossRefs()) {
// 6. Get source column and table names related with Mapping
// Information

// System.out.println("  Source Table : "+
// ((OdiColumn)odiColumn.getReferencedObject()).getTable().getName()
// + " Column : "
// +((OdiColumn)odiColumn.getReferencedObject()).getName());

newLineage = new LineageVO(null, lineage, nLevel,
((OdiColumn) odiColumn.getReferencedObject())
.getTable().getName(),
((OdiColumn) odiColumn.getReferencedObject())
.getName(),
((OdiColumn) odiColumn.getReferencedObject())
.getTable().getModel().getCode(),
inf.getName());
lineage.addSrcTable(newLineage);
lst.add(newLineage);
// 7. Call myself with those
recurSourceTable(
((OdiColumn) odiColumn.getReferencedObject())
.getTable().getName(),
((OdiColumn) odiColumn.getReferencedObject())
.getTable().getModel().getCode(),
((OdiColumn) odiColumn.getReferencedObject())
.getName(), nLevel, newLineage, lst);
}
}
}
}

private void recurTargetTable(String trgTable, String trgModel,
String strColumn, int nLevel, LineageVO lineage, List<LineageVO> lst) {
Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;
DataSet dataset;
TargetMapping targetMapping;
LineageVO newLineage;

// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(trgTable, trgModel).getDataStoreId();

// System.out.println("Table : "+trgTable);
// System.out.println("Data Store ID : "+tableId);

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findBySourceDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;
nLevel++;
for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {
// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();

// System.out.println(" Interface : "+ inf.getName());

for (Iterator<DataSet> dataset_iter = inf.getDataSets().iterator(); dataset_iter
.hasNext();) {
// 5. for statement for looking through datasets
dataset = (DataSet) dataset_iter.next();

// System.out.println("  Data Set : " + dataset.getName());

for (Iterator<TargetMapping> col_iter = dataset.getMappings()
.iterator(); col_iter.hasNext();) {
// 6. for statement for looking through columns
targetMapping = col_iter.next();

// System.out.println("  Table : "+ trgTable + " Column : "
// + strColumn);

for (CrossRef<?> odiColumn : targetMapping
.getSqlExpression().getCrossRefs()) {
// 7. for statement for getting source columns related
// with a target column

// System.out.println("  Source Table : "+
// ((OdiColumn)odiColumn.getReferencedObject()).getTable().getName()
// + " Column : "
// +((OdiColumn)odiColumn.getReferencedObject()).getName());

if (trgTable.equals(((OdiColumn) odiColumn
.getReferencedObject()).getTable().getName()
.toString())
&& strColumn.equals(((OdiColumn) odiColumn
.getReferencedObject()).getName())) {
// 8. if there exist any relationship with the
// column, call myself with those information

// System.out.println("  equals "+inf.getTargetDataStore().getUnderlyingOdiDataStore().getName()
// +"."+targetMapping.getTargetColumn().getName());

newLineage = new LineageVO(lineage, null, nLevel,
inf.getTargetDataStore()
.getUnderlyingOdiDataStore()
.getName(), targetMapping
.getTargetColumn().getName(), inf
.getTargetDataStore()
.getUnderlyingOdiDataStore()
.getModel().getCode(),
targetMapping.getSql(), inf.getName());
lineage.addTrgTable(newLineage);
lst.add(newLineage);
recurTargetTable(inf.getTargetDataStore()
.getUnderlyingOdiDataStore().getName(), inf
.getTargetDataStore()
.getUnderlyingOdiDataStore().getModel()
.getCode(), targetMapping.getTargetColumn()
.getName(), nLevel, newLineage, lst);
}
}
}
}
}
}

/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/
/**************** 08. private function for Data Lineage back-up ******************/
/*********************************************************************************************/
/*********************************************************************************************/
/*********************************************************************************************/

private void recurSourceTable(String srcTable, String srcModel) {

Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;
DataSet dataset;
SourceDataStore sds;

/** process procedure **/

// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(srcTable, srcModel).getDataStoreId();

System.out.println("Table : " + srcTable + " Data Store ID : "
+ tableId);

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findByTargetDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;

for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {
// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();
System.out.println(" Interface : " + inf.getName());
for (Iterator<DataSet> dataset_iter = inf.getDataSets().iterator(); dataset_iter
.hasNext();) {
// 5. for statement for looking through data sets
dataset = (DataSet) dataset_iter.next();
System.out.println("  Data Set : " + dataset.getName());
for (Iterator<SourceDataStore> src_iter = dataset
.getSourceDataStores().iterator(); src_iter.hasNext();) {
// 6. for statement for looking through source tables
sds = (SourceDataStore) src_iter.next();
System.out.println("   Source Table : "
+ sds.getName()
+ "   Source Model : "
+ sds.getUnderlyingOdiDataStore().getModel()
.getCode());

// 7. Call myself with source table and model names
recurSourceTable(sds.getName(), sds
.getUnderlyingOdiDataStore().getModel().getCode());
}
}
}
}

private void recurTargetTable(String trgTable, String trgModel) {
Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;

/** process procedure **/

// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(trgTable, trgModel).getDataStoreId();

System.out.println("Table : " + trgTable);
System.out.println("Data Store ID : " + tableId);

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findBySourceDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;
for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {
// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();

System.out.println(" Interface : " + inf.getName());
System.out.println("  Target Table : "
+ inf.getTargetDataStore().getName()
+ "   Target Model : "
+ inf.getTargetDataStore().getUnderlyingOdiDataStore()
.getModel().getCode());

// 5. Call myself with
recurTargetTable(inf.getTargetDataStore().getName(), inf
.getTargetDataStore().getUnderlyingOdiDataStore()
.getModel().getCode());

}
}

private void recurSourceTable(String srcTable, String srcModel,
String strColumn) {
Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;
DataSet dataset;

// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(srcTable, srcModel).getDataStoreId();

System.out.println("Table : " + srcTable);
System.out.println("Data Store ID : " + tableId);

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findByTargetDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;

for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {
// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();
System.out.println(" Interface : " + inf.getName());
for (Iterator<DataSet> dataset_iter = inf.getDataSets().iterator(); dataset_iter
.hasNext();) {
// 5. for statement for looking through datasets
dataset = (DataSet) dataset_iter.next();
System.out.println("  Data Set : " + dataset.getName()
+ " Mapping : "
+ dataset.getMapping(strColumn).getSqlExpression());
for (CrossRef<?> odiColumn : dataset.getMapping(strColumn)
.getSqlExpression().getCrossRefs()) {
// 6. Get source column and table names related with Mapping
// Information
System.out.println("  Source Table : "
+ ((OdiColumn) odiColumn.getReferencedObject())
.getTable().getName()
+ " Column : "
+ ((OdiColumn) odiColumn.getReferencedObject())
.getName());

// 7. Call myself with those
recurSourceTable(
((OdiColumn) odiColumn.getReferencedObject())
.getTable().getName(),
((OdiColumn) odiColumn.getReferencedObject())
.getTable().getModel().getCode(),
((OdiColumn) odiColumn.getReferencedObject())
.getName());
}

}
}
}

private void recurTargetTable(String trgTable, String trgModel,
String strColumn) {
Number tableId;
Collection<OdiInterface> infs;
OdiInterface inf;
DataSet dataset;
TargetMapping targetMapping;

// 1. Get Table ID
tableId = ((IOdiDataStoreFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiDataStore.class))
.findByName(trgTable, trgModel).getDataStoreId();

System.out.println("Table : " + trgTable);
System.out.println("Data Store ID : " + tableId);

// 2. Get Interface Name
infs = ((IOdiInterfaceFinder) odiInstance
.getTransactionalEntityManager().getFinder(OdiInterface.class))
.findBySourceDataStore(tableId);

// 3. When no Interface related with the table as the target, end
if (infs == null)
return;
for (Iterator<OdiInterface> inf_iter = infs.iterator(); inf_iter
.hasNext();) {
// 4. for statement for looking through interfaces
inf = (OdiInterface) inf_iter.next();

System.out.println(" Interface : " + inf.getName());

for (Iterator<DataSet> dataset_iter = inf.getDataSets().iterator(); dataset_iter
.hasNext();) {
// 5. for statement for looking through datasets
dataset = (DataSet) dataset_iter.next();

System.out.println("  Data Set : " + dataset.getName());

for (Iterator<TargetMapping> col_iter = dataset.getMappings()
.iterator(); col_iter.hasNext();) {
// 6. for statement for looking through columns
targetMapping = col_iter.next();

System.out.println("  Table : " + trgTable + " Column : "
+ strColumn);

for (CrossRef<?> odiColumn : targetMapping
.getSqlExpression().getCrossRefs()) {
// 7. for statement for getting source columns related
// with a target column

System.out.println("  Source Table : "
+ ((OdiColumn) odiColumn.getReferencedObject())
.getTable().getName()
+ " Column : "
+ ((OdiColumn) odiColumn.getReferencedObject())
.getName());

if (trgTable.equals(((OdiColumn) odiColumn
.getReferencedObject()).getTable().getName()
.toString())
&& strColumn.equals(((OdiColumn) odiColumn
.getReferencedObject()).getName())) {
// 8. if there exist any relationship with the
// column, call myself with those infos

System.out
.println("  equals "
+ inf.getTargetDataStore()
.getUnderlyingOdiDataStore()
.getName()
+ "."
+ targetMapping.getTargetColumn()
.getName());

recurTargetTable(inf.getTargetDataStore()
.getUnderlyingOdiDataStore().getName(), inf
.getTargetDataStore()
.getUnderlyingOdiDataStore().getModel()
.getCode(), targetMapping.getTargetColumn()
.getName());
}
}
}
}
}
}
}