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/10/26 15:58:51
6    */
7   package org.asyrinx.joey.gen.command.rdb;
8   
9   import org.asyrinx.brownie.core.lang.StringUtils;
10  import org.asyrinx.joey.gen.model.rdb.Column;
11  import org.asyrinx.joey.gen.model.rdb.Database;
12  import org.asyrinx.joey.gen.model.rdb.ForeignKey;
13  import org.asyrinx.joey.gen.model.rdb.ForeignKeyEntry;
14  import org.asyrinx.joey.gen.model.rdb.ForeignKeyType;
15  import org.asyrinx.joey.gen.model.rdb.Table;
16  
17  /***
18   * @author takeshi
19   */
20  public class PrepareColumnFk extends RdbCommand {
21  
22      /***
23       *  
24       */
25      public PrepareColumnFk() {
26          super();
27      }
28  
29      /*
30       * (non-Javadoc)
31       * 
32       * @see org.asyrinx.joey.gen.model.rdb.visitor.RdbVisitorMock#visit(org.asyrinx.joey.gen.model.rdb.Column)
33       */
34      public void visit(Column column) {
35          if (StringUtils.isEmpty(column.getFk()))
36              return;
37          final Table localTable = column.getParent();
38          final Database db = localTable.getParent();
39          final Column fkCol = db.getColumn(column.getFk());
40          if (fkCol == null) {
41              addError(column, "cannot find:" + column.getFk());
42              return;
43          }
44          final ForeignKey foreignKey = new ForeignKey(localTable, fkCol.getParent().getName());
45          foreignKey.setLabel(column.getLabel());
46          foreignKey.setType(ForeignKeyType.NORMAL);
47          foreignKey.setCascade(column.getFkCascade());
48          new ForeignKeyEntry(foreignKey, column.getName(), fkCol.getName());
49      }
50  
51  }