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.apache.commons.lang.builder.EqualsBuilder;
    12  import org.asyrinx.brownie.core.lang.StringUtils;
    13  import org.asyrinx.joey.gen.model.Element;
    14
    15  import test.org.asyrinx.joey.gen.model.rdb.Constants;
    16
    17  /***
    18   * @author akima
    19   */
    20  public class Databases extends Element {
    21
    22      /***
    23       *
    24       */
    25      public Databases() {
    26          super();
    27      }
    28
    29      /***
    30       *
    31       */
    32      public Databases(String name) {
    33          super(name);
    34      }
    35
    36      /*
    37       * (non-Javadoc)
    38       *
    39       * @see org.asyrinx.joey.gen.model.Element#add(org.asyrinx.joey.gen.model.Element)
    40       */
    41      public void add(Element element) {
    42          if (element instanceof Database)
    43              databases.add((Database) element);
    44          else
    45              super.add(element);
    46      }
    47
    48      private final DatabaseSet databases = new DatabaseSet(this);
    49
    50      /***
    51       * @return Returns the databases.
    52       */
    53      public DatabaseSet getDatabases() {
    54          return databases;
    55      }
    56
    57      public void appendDatabases(Databases dbs) {
    58          for (Iterator i = dbs.getDatabases().iterator(); i.hasNext();) {
    59              final Database db = (Database) i.next();
    60              this.add(db);
    61          }
    62      }
    63
    64      /***
    65       * @param columnName
    66       * @return
    67       */
    68      public Column getColumn(String columnName) {
    69          final String[] nameParts = StringUtils.tokenizeToArray(columnName, Constants.ELEMENTS_DELIMITER);
    70          if (nameParts.length == 3) {
    71              final Database db = getDatabases().getDatabase(nameParts[0]);
    72              return (db == null) ? null : db.getColumn(nameParts[1], nameParts[2]);
    73          }
    74          return null;
    75      }
    76
    77      /*
    78       * (non-Javadoc)
    79       *
    80       * @see java.lang.Object#equals(java.lang.Object)
    81       */
    82      public boolean equals(Object obj) {
    83          if (!super.equals(obj))
    84              return false;
    85          if (!(obj instanceof Databases))
    86              return false;
    87          final Databases other = (Databases) obj;
    88          return new EqualsBuilder() //
    89                  .append(this.getDatabases(), other.getDatabases()) //
    90                  .isEquals();
    91      }
    92  }