package oisoft.togetherx.scripts.SQL.impl;
import java.util.Enumeration;
import oisoft.togetherx.scriptapi.UML.UMLClass;
//import oisoft.togetherx.scriptapi.UML.UMLAttribute;
//import oisoft.togetherx.scriptapi.UML.UMLAssociation;
import oisoft.togetherx.scriptapi.UML.enums.UMLAttributeEnumeration;
//import oisoft.togetherx.scriptapi.UML.enums.UMLAssociationEnumeration;
//import oisoft.togetherx.scripts.SQL.SQLTable;
import oisoft.togetherx.scripts.SQL.SQLForeignKey;
class ColumnEnumeration implements Enumeration{
private UMLAttributeEnumeration myAttributes;
// private ForeignKeyEnumeration myForeignKeys;
private Enumeration myForeignKeys;
private TableImpl myTable;
private Enumeration myForeignColumns = new EmptyEnumeration();
private boolean myPrimaryKeyOnly;
private Object myCurrent;
// private QryAttribute myLastAttribute;
// private Table myForeignTable = null;
/**@associates <b>ColumnEnumeration</b>*/
// private Enumeration myForeignKeys = new EmptyEnumeration();
ColumnEnumeration(TableImpl table, SQLModelImpl model){
this(table,model,true);
}
ColumnEnumeration(TableImpl table, SQLModelImpl model, boolean showForeignKeys){
this(table,model,showForeignKeys,false);
}
ColumnEnumeration(TableImpl table, SQLModelImpl model, boolean showForeignKeys, boolean primaryKeyOnly){
myAttributes = table.getUMLClass().getAttributes();
myPrimaryKeyOnly = primaryKeyOnly;
myTable = table;
if( showForeignKeys ){
myForeignKeys = new ForeignKeyEnumeration(table,model,primaryKeyOnly);
}
else{
myForeignKeys = new EmptyEnumeration();
}
advance();
}
public Object nextElement(){
Object result = myCurrent;
advance();
return result;
}
public boolean hasMoreElements(){
return myCurrent != null;
}
private void advance(){
myCurrent = null;
while( myAttributes.hasMoreElements() ){
ColumnImpl tmp = (ColumnImpl)myTable.getColumn(myAttributes.getNextUMLAttribute());
if(!myPrimaryKeyOnly || tmp.isPrimaryKey()){
myCurrent = tmp;
break;
}
}
if(myCurrent == null){
while(!myForeignColumns.hasMoreElements() && myForeignKeys.hasMoreElements() ){
myForeignColumns = ((SQLForeignKey)myForeignKeys.nextElement()).getColumns();
}
if( myForeignColumns.hasMoreElements() ){
myCurrent = myForeignColumns.nextElement();
}
}
}
}
|