Example #1
0
 /**
  * Returns the auto-increment string.
  *
  * @return string
  */
 public function getAutoIncrementString()
 {
     if ($this->isAutoIncrement() && IdMethod::NATIVE === $this->parentTable->getIdMethod()) {
         return $this->getPlatform()->getAutoIncrement();
     }
     if ($this->isAutoIncrement()) {
         throw new EngineException(sprintf('You have specified autoIncrement for column "%s", but you have not specified idMethod="native" for table "%s".', $this->name, $this->parentTable->getName()));
     }
     return '';
 }
Example #2
0
 public function getAddSequencesDDL(Table $table)
 {
     if ('native' === $table->getIdMethod()) {
         $pattern = "\nCREATE SEQUENCE %s\n    INCREMENT BY 1 START WITH 1 NOMAXVALUE NOCYCLE NOCACHE ORDER;\n";
         return sprintf($pattern, $this->quoteIdentifier($this->getSequenceName($table)));
     }
 }
Example #3
0
 public function getDropTableDDL(Table $table)
 {
     $ret = "\nDROP TABLE " . $this->quoteIdentifier($table->getName()) . " CASCADE CONSTRAINTS;\n";
     if ($table->getIdMethod() == IdMethod::NATIVE) {
         $ret .= "\nDROP SEQUENCE " . $this->quoteIdentifier($this->getSequenceName($table)) . ";\n";
     }
     return $ret;
 }
Example #4
0
 protected function getDropSequenceDDL(Table $table)
 {
     if ($table->getIdMethod() == IDMethod::NATIVE && $table->getIdMethodParameters() != null) {
         $pattern = "\nDROP SEQUENCE %s;\n";
         return sprintf($pattern, $this->quoteIdentifier(strtolower($this->getSequenceName($table))));
     }
 }
 /**
  * Returns the name to use for creating a table sequence.
  *
  * This will create a new name or use one specified in an
  * id-method-parameter tag, if specified.
  *
  * @param Table $table
  *
  * @return string
  */
 public function getSequenceName(Table $table)
 {
     static $longNamesMap = array();
     $result = null;
     if (IdMethod::NATIVE === $table->getIdMethod()) {
         $idMethodParams = $table->getIdMethodParameters();
         $maxIdentifierLength = $this->getMaxColumnNameLength();
         if (empty($idMethodParams)) {
             if (strlen($table->getName() . '_SEQ') > $maxIdentifierLength) {
                 if (!isset($longNamesMap[$table->getName()])) {
                     $longNamesMap[$table->getName()] = strval(count($longNamesMap) + 1);
                 }
                 $result = substr($table->getName(), 0, $maxIdentifierLength - strlen('_SEQ_' . $longNamesMap[$table->getName()])) . '_SEQ_' . $longNamesMap[$table->getName()];
             } else {
                 $result = substr($table->getName(), 0, $maxIdentifierLength - 4) . '_SEQ';
             }
         } else {
             $result = substr($idMethodParams[0]->getValue(), 0, $maxIdentifierLength);
         }
     }
     return $result;
 }
Example #6
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);
     }
 }