View Javadoc

    1   /*
    2    * joey-gen and its relative products are published under the terms
    3    * of the Apache Software License.
    4    *
    5    * Created on 2004/08/15 18:00:19
    6    */
    7   package org.asyrinx.joey.gen.command.rdb;
    8
    9   import java.util.Iterator;
    10
    11  import org.asyrinx.joey.gen.model.rdb.ForeignKey;
    12  import org.asyrinx.joey.gen.model.rdb.ForeignKeyEntry;
    13  import org.asyrinx.joey.gen.model.rdb.Index;
    14  import org.asyrinx.joey.gen.model.rdb.IndexEntry;
    15  import org.asyrinx.joey.gen.model.rdb.Table;
    16
    17  /***
    18   * @author akima
    19   */
    20  public class FkToIndex extends RdbCommand {
    21
    22      public void visit(ForeignKey foreignKey) {
    23          if (!foreignKey.isIndexed())
    24              return;
    25          if (foreignKey.getIndex() != null)
    26              return;
    27          final Table table = foreignKey.getParent();
    28          final Index index = new Index(table, null);
    29          for (final Iterator iterator = foreignKey.iterator(); iterator.hasNext();) {
    30              final ForeignKeyEntry entry = (ForeignKeyEntry) iterator.next();
    31              index.add(new IndexEntry(entry.getLocal()));
    32          }
    33          foreignKey.setIndex(index);
    34      }
    35  }