de.oc.dbdoc.graphdata.GraphForSingleTableAncestors Maven / Gradle / Ivy
package de.oc.dbdoc.graphdata;
import java.util.ArrayList;
import java.util.List;
import de.oc.dbdoc.ant.Styles;
import de.oc.dbdoc.ant.Tableregistry;
import de.oc.dbdoc.schemadata.Association;
import de.oc.dbdoc.schemadata.Schema;
import de.oc.dbdoc.schemadata.Table;
public class GraphForSingleTableAncestors extends GraphForSingleTable
{
private List _allAncestorTablesForSingleTableReturn;
public GraphForSingleTableAncestors( Table pSingleTable, List pParentGraphs, Styles pStyles, Tableregistry pTableregistry )
{
super( pSingleTable, pParentGraphs, pStyles, pTableregistry );
}
@Override
public String getLabel()
{
return super.getLabel() + "-Ancestors";
}
@Override
public boolean allAssociations()
{
return false;
}
@Override
public boolean isAllAncestors()
{
return true;
}
@Override
public List getVisibleAssociation( Table pTable, Schema pSchema, boolean pOutRefsOnly )
{
List lAllAncestorTablesForSingleTable = getAllAncestorTablesForSingleTable( pSchema );
List lReturn = new ArrayList();
if( lAllAncestorTablesForSingleTable.contains( pTable ) )
{
for( Association lAssociation : pSchema.getAssociations() )
{
if( (lAssociation.getTableTo().equals( pTable ) && lAllAncestorTablesForSingleTable.contains( lAssociation.getTableFrom() )) || (lAssociation.getTableFrom().equals( pTable ) && lAllAncestorTablesForSingleTable.contains( lAssociation.getTableTo() )) )
{
lReturn.add( lAssociation );
}
}
}
return lReturn;
}
private List getAllAncestorTablesForSingleTable( Schema pSchema )
{
if( _allAncestorTablesForSingleTableReturn == null )
{
List lReturn = new ArrayList();
boolean lOneNewFound;
do
{
lOneNewFound = false;
for( Table lTable : pSchema.getTables() )
{
if( !lReturn.contains( lTable ) )
{
if( containsTableRecursive( lTable ) )
{
lReturn.add( lTable );
lOneNewFound = true;
}
else
{
for( Association lAssociation : pSchema.getAssociations() )
{
if( lAssociation.getTableTo().equals( lTable ) && lReturn.contains( lAssociation.getTableFrom() ) )
{
lReturn.add( lTable );
lOneNewFound = true;
break;
}
}
}
}
}
} while( lOneNewFound );
_allAncestorTablesForSingleTableReturn = lReturn;
}
return _allAncestorTablesForSingleTableReturn;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy