de.oc.dbdoc.schemadata.Schema Maven / Gradle / Ivy
// Copyright (c) 2004 OPITZ CONSULTING GmbH
package de.oc.dbdoc.schemadata;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
/**
* DOCUMENT ME!
*
* @author FSA
*/
public class Schema
{
private List _tables = new ArrayList();
private Collection _associations = new ArrayList();
public Schema()
{
}
public void addTable( Table pTable )
{
_tables.add( pTable );
Collections.sort( _tables, new Comparator()
{
public int compare( Table pTable1, Table pTable2 )
{
return pTable1.getName().compareTo( pTable2.getName() );
}
} );
}
public void addAssociation( Association pAssociation )
{
_associations.add( pAssociation );
}
public Table findTable( String pTableName )
{
Iterator lTableIterator = _tables.iterator();
while( lTableIterator.hasNext() )
{
Table lTable = lTableIterator.next();
if( lTable.getName().equalsIgnoreCase( pTableName ) )
{
return lTable;
}
}
return null;
}
public void mergeAssociations()
{
while( _mergeFirstAssociations() )
;
}
private boolean _mergeFirstAssociations()
{
for( Association lOuterAssociation : _associations )
{
for( Association lInnerAssociation : _associations )
{
if( lOuterAssociation != lInnerAssociation && lOuterAssociation.isMergeable( lInnerAssociation ) )
{
Association lMergeAssociation = lOuterAssociation.merge( lInnerAssociation );
_associations.remove( lOuterAssociation );
_associations.remove( lInnerAssociation );
_associations.add( lMergeAssociation );
return true;
}
}
}
return false;
}
public Collection getTables()
{
return _tables;
}
public Collection getAssociations()
{
return _associations;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy