[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/propel-generator/classes/propel/engine/database/model/ -> Index.php (source)

   1  <?php
   2  
   3  /*
   4   *  $Id: Index.php 351 2006-03-15 18:42:34Z hans $
   5   *
   6   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   7   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   8   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   9   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  10   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17   *
  18   * This software consists of voluntary contributions made by many individuals
  19   * and is licensed under the LGPL. For more information please see
  20   * <http://propel.phpdb.org>.
  21   */
  22  
  23  require_once 'propel/engine/database/model/XMLElement.php';
  24  include_once 'propel/engine/EngineException.php';
  25  
  26  /**
  27   * Information about indices of a table.
  28   *
  29   * @author Jason van Zyl <vanzyl@apache.org>
  30   * @author Daniel Rall <dlr@finemaltcoding.com>
  31   * @version $Revision: 351 $
  32   * @package propel.engine.database.model
  33   */
  34  class Index extends XMLElement {
  35  
  36      /** enables debug output */
  37      const DEBUG = false;
  38  
  39      private $indexName;
  40      private $parentTable;
  41  
  42      /** @var array string[] */
  43      private $indexColumns;
  44  
  45      /** @var array  */
  46      private $indexColumnSizes = array();
  47  
  48      /**
  49       * Creates a new instance with default characteristics (no name or
  50       * parent table, small column list size allocation, non-unique).
  51       *
  52       * @param Table $table
  53       * @param array $indexColumns
  54       */
  55      public function __construct(Table $table, $indexColumns = array())
  56      {
  57          $this->indexColumns = $indexColumns;
  58          $this->setTable($table);
  59          if (!empty($indexColumns)) {
  60  
  61              $this->createName();
  62  
  63              if (self::DEBUG) {
  64                  print("Created Index named " . $this->getName()
  65                          . " with " . count($indexColumns) . " columns\n");
  66              }
  67          }
  68      }
  69  
  70      private function createName()
  71      {
  72          $table = $this->getTable();
  73          $inputs = array();
  74          $inputs[] = $table->getDatabase();
  75          $inputs[] = $table->getName();
  76          if ($this->isUnique()) {
  77              $inputs[] = "U";
  78          } else {
  79              $inputs[] = "I";
  80          }
  81          // ASSUMPTION: This Index not yet added to the list.
  82          if ($this->isUnique()) {
  83              $inputs[] = count($table->getUnices()) + 1;
  84          } else {
  85              $inputs[] = count($table->getIndices()) + 1;
  86          }
  87  
  88          $this->indexName = NameFactory::generateName(
  89                  NameFactory::CONSTRAINT_GENERATOR, $inputs);
  90      }
  91  
  92      /**
  93       * Sets up the Index object based on the attributes that were passed to loadFromXML().
  94       * @see parent::loadFromXML()
  95       */
  96      protected function setupObject()
  97      {
  98          $this->indexName = $this->getAttribute("name");
  99      }
 100  
 101      /**
 102       * @see #isUnique()
 103       * @deprecated Use isUnique() instead.
 104       */
 105      public function getIsUnique()
 106      {
 107          return $this->isUnique();
 108      }
 109  
 110      /**
 111       * Returns the uniqueness of this index.
 112       */
 113      public function isUnique()
 114      {
 115          return false;
 116      }
 117  
 118      /**
 119       * @see #getName()
 120       * @deprecated Use getName() instead.
 121       */
 122      public function getIndexName()
 123      {
 124          return $this->getName();
 125      }
 126  
 127      /**
 128       * Gets the name of this index.
 129       */
 130      public function getName()
 131      {
 132          if ($this->indexName === null) {
 133              try {
 134                  // generate an index name if we don't have a supplied one
 135                  $this->createName();
 136              } catch (EngineException $e) {
 137                  // still no name
 138              }
 139          }
 140          return $this->indexName;
 141      }
 142  
 143      /**
 144       * @see #setName(String name)
 145       * @deprecated Use setName(String name) instead.
 146       */
 147      public function setIndexName($name)
 148      {
 149          $this->setName($name);
 150      }
 151  
 152      /**
 153       * Set the name of this index.
 154       */
 155      public function setName($name)
 156      {
 157          $this->indexName = $name;
 158      }
 159  
 160      /**
 161       * Set the parent Table of the index
 162       */
 163      public function setTable(Table $parent)
 164      {
 165          $this->parentTable = $parent;
 166      }
 167  
 168      /**
 169       * Get the parent Table of the index
 170       */
 171      public function getTable()
 172      {
 173          return $this->parentTable;
 174      }
 175  
 176      /**
 177       * Returns the Name of the table the index is in
 178       */
 179      public function getTableName()
 180      {
 181          return $this->parentTable->getName();
 182      }
 183  
 184      /**
 185       * Adds a new column to an index.
 186       * @param array $attrib The attribute array from XML parser.
 187       */
 188      public function addColumn($attrib)
 189      {
 190          $name = $attrib["name"];
 191          $this->indexColumns[] = $name;
 192          if (isset($attrib["size"])) {
 193              $this->indexColumnSizes[$name] = $attrib["size"];
 194          }
 195      }
 196  
 197      /**
 198       * Whether there is a size for the specified column.
 199       * @param string $name
 200       * @return boolean
 201       */
 202  	public function hasColumnSize($name)
 203      {
 204          return isset($this->indexColumnSizes[$name]);
 205      }
 206  
 207      /**
 208       * Returns the size for the specified column, if given.
 209       * @param string $name
 210       * @return numeric The size or NULL
 211       */
 212  	public function getColumnSize($name)
 213      {
 214          if (isset($this->indexColumnSizes[$name])) {
 215              return $this->indexColumnSizes[$name];
 216          }
 217          return null; // just to be explicit
 218      }
 219  
 220      /**
 221       * @see #getColumnList()
 222       * @deprecated Use getColumnList() instead (which is not deprecated too!)
 223       */
 224      public function getIndexColumnList()
 225      {
 226          return $this->getColumnList();
 227      }
 228  
 229      /**
 230       * Return a comma delimited string of the columns which compose this index.
 231       * @deprecated because Column::makeList() is deprecated; use the array-returning getColumns() and DDLBuilder->getColumnList() instead instead.
 232       */
 233      public function getColumnList()
 234      {
 235          return Column::makeList($this->getColumns(), $this->getTable()->getDatabase()->getPlatform());
 236      }
 237  
 238      /**
 239       * @see #getColumns()
 240       * @deprecated Use getColumns() instead.
 241       */
 242      public function getIndexColumns()
 243      {
 244          return $this->getColumns();
 245      }
 246  
 247      /**
 248       * Return the list of local columns. You should not edit this list.
 249       * @return array string[]
 250       */
 251      public function getColumns()
 252      {
 253          return $this->indexColumns;
 254      }
 255  
 256      /**
 257       * String representation of the index. This is an xml representation.
 258       */
 259      public function toString()
 260      {
 261  
 262          $result = " <index name=\""
 263                . $this->getName()
 264                .'"';
 265  
 266          $result .= ">\n";
 267  
 268          for ($i=0, $size=count($this->indexColumns); $i < $size; $i++) {
 269              $result .= "  <index-column name=\""
 270                  . $this->indexColumns[$i]
 271                  . "\"/>\n";
 272          }
 273          $result .= " </index>\n";
 274          return $result;
 275      }
 276  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7