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/11/07 21:25:09
    6    */
    7   package org.asyrinx.joey.gen.model.java;
    8
    9   import java.util.ArrayList;
    10  import java.util.Iterator;
    11  import java.util.List;
    12
    13  import org.asyrinx.joey.gen.model.Element;
    14  import org.asyrinx.joey.gen.model.ElementSet;
    15
    16  /***
    17   * @author takeshi
    18   */
    19  public class EntityKeySet extends ElementSet {
    20
    21      /***
    22       * @param parent
    23       */
    24      public EntityKeySet(Element parent) {
    25          super(parent);
    26      }
    27
    28      /*
    29       * (non-Javadoc)
    30       *
    31       * @see org.asyrinx.joey.gen.model.Element#isEntity()
    32       */
    33      public boolean isEntity() {
    34          return false;
    35      }
    36
    37      public void add(EntityKey key) {
    38          super.add(key);
    39      }
    40
    41      /*
    42       * (non-Javadoc)
    43       *
    44       * @see org.asyrinx.joey.gen.model.ElementSet#contains(org.asyrinx.joey.gen.model.Element)
    45       */
    46      public boolean contains(EntityKey key) {
    47          return super.contains(key);
    48      }
    49
    50      /*
    51       * (non-Javadoc)
    52       *
    53       * @see org.asyrinx.joey.gen.model.ElementSet#getElement(int)
    54       */
    55      public EntityKey getKey(int index) {
    56          return (EntityKey) super.getElement(index);
    57      }
    58
    59      /*
    60       * (non-Javadoc)
    61       *
    62       * @see org.asyrinx.joey.gen.model.ElementSet#get(java.lang.String)
    63       */
    64      public EntityKey getKey(String name) {
    65          return (EntityKey) super.getElement(name);
    66      }
    67
    68      /*
    69       * (non-Javadoc)
    70       *
    71       * @see org.asyrinx.joey.gen.model.ElementSet#remove(java.lang.String)
    72       */
    73      public EntityKey removeKey(String name) {
    74          return (EntityKey) super.removeElement(name);
    75      }
    76
    77      /***
    78       * @return
    79       */
    80      public EntityKey getPrimaryKey() {
    81          for (Iterator i = this.iterator(); i.hasNext();) {
    82              final EntityKey key = (EntityKey) i.next();
    83              if (key.isPrimaryKey())
    84                  return key;
    85          }
    86          return null;
    87      }
    88
    89      public List getIndexes() {
    90          return getKeys(EntityKeyType.INDEX);
    91      }
    92
    93      public List getUniques() {
    94          return getKeys(EntityKeyType.UNIQUE);
    95      }
    96
    97      /***
    98       * @param type
    99       * @return
    100      */
    101     private List getKeys(final EntityKeyType type) {
    102         final List result = new ArrayList();
    103         for (Iterator i = this.iterator(); i.hasNext();) {
    104             final EntityKey key = (EntityKey) i.next();
    105             if (key.getKeyType() == type)
    106                 result.add(key);
    107         }
    108         return result;
    109     }
    110 }