FileDocCategorySizeDatePackage
SQLModelImpl.javaAPI DocExample4779Tue Dec 08 01:21:00 GMT 1998oisoft.togetherx.scripts.SQL.impl

SQLModelImpl

public class SQLModelImpl extends Object implements oisoft.togetherx.scripts.SQL.SQLModel

Fields Summary
private COM.objectspace.jgl.HashMap
myTables
private COM.objectspace.jgl.HashSet
myNameRegistry
private oisoft.togetherx.scriptapi.UML.UMLPackage
myPackage
private SQLDiagramTags
myTags
private SQLNameConstraints
myNameConstraints
Constructors Summary
public SQLModelImpl(oisoft.togetherx.scriptapi.UML.UMLPackage pkg)

    this(pkg,new DefaultDiagramTags());
  
public SQLModelImpl(oisoft.togetherx.scriptapi.UML.UMLPackage pkg, SQLDiagramTags tags)

    this(pkg,tags,new DefaultNameConstraints());
  
public SQLModelImpl(oisoft.togetherx.scriptapi.UML.UMLPackage pkg, SQLDiagramTags tags, SQLNameConstraints nameConstraints)

    myPackage = pkg;
    myTags = tags;
    myNameConstraints = nameConstraints;
  
Methods Summary
public booleancheckConsistency()

    HashSet checked = new HashSet();
    HashSet current = new HashSet();

    for( Enumeration tables = getTables(); tables.hasMoreElements(); ){
      TableImpl currTable = (TableImpl)tables.nextElement();
      if( !checkConsistencyStep(currTable,checked,current) ){
        return false;
      }
      for(Enumeration enum = current.elements(); enum.hasMoreElements(); ){
        checked.add(enum.nextElement());
      }
      current.clear();
    }
    return true;
  
private booleancheckConsistencyStep(TableImpl table, COM.objectspace.jgl.HashSet checked, COM.objectspace.jgl.HashSet current)

    if( checked.get(table) != null ){
      // already checked
      return true;
    }
    if( current.get(table) != null ){
      // cycle in identifying links
      return false;
    }
    try{
      current.add(table);
      for( UMLAssociationEnumeration links = table.getUMLClass().getAssociations(); links.hasMoreElements(); ){
        UMLAssociation link = links.getNextUMLAssociation();
        // only identifying links can cause problems
        if( !link.hasProperty(getTags().linkIdentifying()) ){
          continue;
        }
        if( link.getDest() instanceof UMLClass ){
          TableImpl destTable = (TableImpl)getTable((UMLClass)link.getDest());
          if( !checkConsistencyStep(destTable,checked,current) ){
            return false;
          }
        }
      }
      // no problems found
      checked.add(table);
      return true;
    }
    finally{
      current.remove(table);
    }
  
java.lang.StringcreateTableName(java.lang.String className)

    String result = getNameConstraints().shorten(className,getNameConstraints().getMaxTableNameLength());
    result = dereserve(result);
    result = getUniqueName(result,getNameConstraints().getMaxTableNameLength());
    return result;
  
java.lang.Stringdereserve(java.lang.String name)

    String result = name;
    while( getNameConstraints().isReservedWord(result) && result.length() > 1 ){
      System.out.println("dereserve: "+result);
      result = getNameConstraints().shorten(result,result.length()-1);
    }
    if( getNameConstraints().isReservedWord(result) ){
      result = getNameConstraints().shorten(name+"_",getNameConstraints().getMaxTableNameLength());
    }
    return result;
  
public java.util.EnumerationgetCatalogs()

return
Enumeration of Strings -- catalog names

    return new EmptyEnumeration();
  
SQLNameConstraintsgetNameConstraints()

    return myNameConstraints;
  
public java.util.EnumerationgetSchemas()

return
Enumeration of Strings -- schema names

    return new EmptyEnumeration();
  
oisoft.togetherx.scripts.SQL.SQLTablegetTable(oisoft.togetherx.scriptapi.UML.UMLClass clazz)

    SQLTable result = (SQLTable)myTables.get(clazz);
    if( result == null ){
      result = new TableImpl(clazz,this);
      myTables.put(clazz,result);
      String name = result.getName();
    }
    return result;
  
public java.util.EnumerationgetTables()

    return new TableEnumeration(myPackage.getClasses(),this);
  
SQLDiagramTagsgetTags()

    return myTags;
  
java.lang.StringgetUniqueName(java.lang.String base, int length)

    int i = 2;
    String result = base;
    while( isNameRegistered(result) ){
      result = base+i;
      result = getNameConstraints().shorten(result,length);
      result = dereserve(result);
      ++i;
    }
    registerName(result);
    return result;
  
booleanisNameRegistered(java.lang.String name)

    return myNameRegistry.get(name.toLowerCase()) != null;
  
voidregisterName(java.lang.String name)

    myNameRegistry.add(name.toLowerCase());