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/10 16:59:32
6    */
7   package org.asyrinx.joey.gen.model.rdb;
8   
9   import java.util.Iterator;
10  
11  import org.asyrinx.brownie.core.lang.StringUtils;
12  import org.asyrinx.joey.gen.model.Element;
13  
14  import test.org.asyrinx.joey.gen.model.rdb.Constants;
15  
16  /***
17   * @author akima
18   */
19  public class Database extends Element {
20  
21      public Database() {
22          super();
23      }
24  
25      /***
26       *  
27       */
28      public Database(Databases parent, String name) {
29          super(parent, name);
30      }
31  
32      /*
33       * (non-Javadoc)
34       * 
35       * @see org.asyrinx.joey.gen.model.Element#getParentElement()
36       */
37      public Databases getParent() {
38          return (Databases) super.getParentElement();
39      }
40  
41      /*
42       * (non-Javadoc)
43       * 
44       * @see org.asyrinx.joey.gen.model.Element#add(org.asyrinx.joey.gen.model.Element)
45       */
46      public void add(Element element) {
47          if (element instanceof Table)
48              tables.add((Table) element);
49          else if (element instanceof RdbEnumeration)
50              enumerations.add((RdbEnumeration) element);
51          else
52              super.add(element);
53      }
54  
55      private final TableSet tables = new TableSet(this);
56  
57      /***
58       * @return Returns the tables.
59       */
60      public TableSet getTables() {
61          return tables;
62      }
63  
64      private final RdbEnumerationSet enumerations = new RdbEnumerationSet(this);
65  
66      /***
67       * @return Returns the enumerations.
68       */
69      public RdbEnumerationSet getEnumerations() {
70          return enumerations;
71      }
72  
73      /***
74       * @param committed
75       */
76      public void moveTables(Database dest) {
77          for (final Iterator i = tables.iterator(); i.hasNext();) {
78              final Table table = (Table) i.next();
79              dest.getTables().add(table);
80          }
81      }
82  
83      /***
84       * @param committed
85       */
86      public void moveEnumerations(Database dest) {
87          for (final Iterator i = enumerations.iterator(); i.hasNext();) {
88              final RdbEnumeration enumeration = (RdbEnumeration) i.next();
89              dest.getEnumerations().add(enumeration);
90          }
91      }
92  
93      /***
94       * @param string
95       * @return
96       */
97      public Column getColumn(String columnName) {
98          final String[] nameParts = StringUtils.tokenizeToArray(columnName, Constants.ELEMENTS_DELIMITER);
99          if (nameParts.length == 2) {
100             return getColumn(nameParts[0], nameParts[1]);
101         } else if (nameParts.length == 3) {
102             if (getParent() != null)
103                 return getParent().getColumn(columnName);
104         }
105         return null;
106     }
107 
108     public Column getColumn(String tableName, String columnName) {
109         final Table table = getTables().getTable(tableName);
110         return (table == null) ? null : table.getColumns().getColumn(columnName);
111 
112     }
113 }