1
2
3
4
5
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
31
32
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 }