Example #1
0
 protected function createName()
 {
     $inputs[] = $this->table->getDatabase();
     $inputs[] = $this->table->getCommonName();
     $inputs[] = 'I';
     $inputs[] = count($this->table->getIndices()) + 1;
     // @TODO replace the factory by a real object
     $this->name = NameFactory::generateName(NameFactory::CONSTRAINT_GENERATOR, $inputs);
 }
 public function testAddArrayIndex()
 {
     $table = new Table();
     $table->addIndex(array('name' => 'author_idx', 'columns' => [['name' => 'bla']]));
     $this->assertCount(1, $table->getIndices());
 }
 /**
  * Normalizes a table for the current platform. Very important for the TableComparator to not
  * generate useless diffs.
  * Useful for checking needed definitions/structures. E.g. Unique Indexes for ForeignKey columns,
  * which the most Platforms requires but which is not always explicitly defined in the table model.
  *
  * @param Table $table The table object which gets modified.
  */
 public function normalizeTable(Table $table)
 {
     if ($table->hasForeignKeys()) {
         foreach ($table->getForeignKeys() as $fk) {
             if ($fk->getForeignTable() && !$fk->getForeignTable()->isUnique($fk->getForeignColumnObjects())) {
                 $unique = new Unique();
                 $unique->setColumns($fk->getForeignColumnObjects());
                 $fk->getForeignTable()->addUnique($unique);
             }
         }
     }
     if (!$this->supportsIndexSize() && $table->getIndices()) {
         // when the plafform does not support index sizes we reset it
         foreach ($table->getIndices() as $index) {
             $index->resetColumnsSize();
         }
     }
     foreach ($table->getColumns() as $column) {
         if ($column->getSize() && ($defaultSize = $this->getDefaultTypeSize($column->getType()))) {
             if (null === $column->getScale() && intval($column->getSize()) === $defaultSize) {
                 $column->setSize(null);
             }
         }
     }
 }
Example #4
0
 /**
  * Builds the DDL SQL to add the indices of a table.
  *
  * @param      Table $table
  * @return     string
  */
 public function getAddIndicesDDL(Table $table)
 {
     $ret = '';
     foreach ($table->getIndices() as $fk) {
         $ret .= $this->getAddIndexDDL($fk);
     }
     return $ret;
 }
Example #5
0
 /**
  * Appends the generated <table> XML node to its parent node.
  *
  * @param Table    $table      The Table model instance
  * @param \DOMNode $parentNode The parent DOMNode object
  */
 private function appendTableNode(Table $table, \DOMNode $parentNode)
 {
     $tableNode = $parentNode->appendChild($this->document->createElement('table'));
     $tableNode->setAttribute('name', $table->getCommonName());
     $database = $table->getDatabase();
     $schema = $table->getSchema();
     if ($schema && $schema !== $database->getSchema()) {
         $tableNode->setAttribute('schema', $schema);
     }
     if (IdMethod::NO_ID_METHOD !== ($idMethod = $table->getIdMethod())) {
         $tableNode->setAttribute('idMethod', $idMethod);
     }
     if ($phpName = $table->getPhpName()) {
         $tableNode->setAttribute('phpName', $phpName);
     }
     $package = $table->getPackage();
     if ($package && !$table->isPackageOverriden()) {
         $tableNode->setAttribute('package', $package);
     }
     if ($namespace = $table->getNamespace()) {
         $tableNode->setAttribute('namespace', $namespace);
     }
     if ($table->isSkipSql()) {
         $tableNode->setAttribute('skipSql', 'true');
     }
     if ($table->isAbstract()) {
         $tableNode->setAttribute('abstract', 'true');
     }
     if ($interface = $table->getInterface()) {
         $tableNode->setAttribute('interface', $interface);
     }
     if ($table->isCrossRef()) {
         $tableNode->setAttribute('isCrossRef', 'true');
     }
     $phpNamingMethod = $table->getPhpNamingMethod();
     if ($phpNamingMethod && $phpNamingMethod !== $database->getDefaultPhpNamingMethod()) {
         $tableNode->setAttribute('phpNamingMethod', $phpNamingMethod);
     }
     if ($baseClass = $table->getBaseClass()) {
         $tableNode->setAttribute('baseClass', $baseClass);
     }
     if ($baseQueryClass = $table->getBaseQueryClass()) {
         $tableNode->setAttribute('baseQueryClass', $baseQueryClass);
     }
     if ($table->isReadOnly()) {
         $tableNode->setAttribute('readOnly', 'true');
     }
     if ($table->isReloadOnInsert()) {
         $tableNode->setAttribute('reloadOnInsert', 'true');
     }
     if ($table->isReloadOnUpdate()) {
         $tableNode->setAttribute('reloadOnUpdate', 'true');
     }
     if (null !== ($referenceOnly = $table->isForReferenceOnly())) {
         $tableNode->setAttribute('forReferenceOnly', $referenceOnly ? 'true' : 'false');
     }
     if ($alias = $table->getAlias()) {
         $tableNode->setAttribute('alias', $alias);
     }
     if ($description = $table->getDescription()) {
         $tableNode->setAttribute('description', $description);
     }
     $defaultStringFormat = $table->getDefaultStringFormat();
     if (Table::DEFAULT_STRING_FORMAT !== $defaultStringFormat) {
         $tableNode->setAttribute('defaultStringFormat', $defaultStringFormat);
     }
     $defaultAccessorVisibility = $table->getDefaultAccessorVisibility();
     if ($defaultAccessorVisibility !== Table::VISIBILITY_PUBLIC) {
         $tableNode->setAttribute('defaultAccessorVisibility', $defaultAccessorVisibility);
     }
     $defaultMutatorVisibility = $table->getDefaultMutatorVisibility();
     if ($defaultMutatorVisibility !== Table::VISIBILITY_PUBLIC) {
         $tableNode->setAttribute('defaultMutatorVisibility', $defaultMutatorVisibility);
     }
     foreach ($table->getColumns() as $column) {
         $this->appendColumnNode($column, $tableNode);
     }
     foreach ($table->getForeignKeys() as $foreignKey) {
         $this->appendForeignKeyNode($foreignKey, $tableNode);
     }
     foreach ($table->getIdMethodParameters() as $parameter) {
         $this->appendIdMethodParameterNode($parameter, $tableNode);
     }
     foreach ($table->getIndices() as $index) {
         $this->appendIndexNode($index, $tableNode);
     }
     foreach ($table->getUnices() as $index) {
         $this->appendUniqueIndexNode($index, $tableNode);
     }
     foreach ($table->getVendorInformation() as $vendorInformation) {
         $this->appendVendorInformationNode($vendorInformation, $tableNode);
     }
     foreach ($table->getBehaviors() as $behavior) {
         $this->appendBehaviorNode($behavior, $tableNode);
     }
 }