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      /***
    23       *
    24       */
    25      public FkToIndex() {
    26          super();
    27      }
    28
    29      /*
    30       * (non-Javadoc)
    31       *
    32       * @see org.asyrinx.joey.gen.model.rdb.RdbVisitor#visit(org.asyrinx.joey.gen.model.rdb.ForeignKey)
    33       */
    34      public void visit(ForeignKey foreignKey) {
    35          if (!foreignKey.isIndexed())
    36              return;
    37          if (foreignKey.getIndex() != null)
    38              return;
    39          final Table table = foreignKey.getParent();
    40          final Index index = new Index(table, null);
    41          for (final Iterator iterator = foreignKey.iterator(); iterator.hasNext();) {
    42              final ForeignKeyEntry entry = (ForeignKeyEntry) iterator.next();
    43              index.add(new IndexEntry(entry.getLocal()));
    44          }
    45          foreignKey.setIndex(index);
    46      }
    47  }