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/12 18:37:54
    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 Databases extends Element {
    20
    21      /***
    22       *
    23       */
    24      public Databases() {
    25          super();
    26      }
    27
    28      /***
    29       *
    30       */
    31      public Databases(String name) {
    32          super(name);
    33      }
    34
    35      /*
    36       * (non-Javadoc)
    37       *
    38       * @see org.asyrinx.joey.gen.model.Element#add(org.asyrinx.joey.gen.model.Element)
    39       */
    40      public void add(Element element) {
    41          if (element instanceof Database)
    42              databases.add((Database) element);
    43          else
    44              super.add(element);
    45      }
    46
    47      private final DatabaseSet databases = new DatabaseSet(this);
    48
    49      /***
    50       * @return Returns the databases.
    51       */
    52      public DatabaseSet getDatabases() {
    53          return databases;
    54      }
    55
    56      public void appendDatabases(Databases dbs) {
    57          for (Iterator i = dbs.getDatabases().iterator(); i.hasNext();) {
    58              final Database db = (Database) i.next();
    59              this.add(db);
    60          }
    61      }
    62
    63      /***
    64       * @param columnName
    65       * @return
    66       */
    67      public Column getColumn(String columnName) {
    68          final String[] nameParts = StringUtils.tokenizeToArray(columnName, Constants.ELEMENTS_DELIMITER);
    69          if (nameParts.length == 3) {
    70              final Database db = getDatabases().getDatabase(nameParts[0]);
    71              return (db == null) ? null : db.getColumn(nameParts[1], nameParts[2]);
    72          }
    73          return null;
    74      }
    75  }