Esempio n. 1
0
 /**
  * Get table
  *
  * @param  string $tableName
  * @param  string $schema
  * @return Object\TableObject
  */
 public function getTable($tableName, $schema = null)
 {
     if ($schema === null) {
         $schema = $this->defaultSchema;
     }
     $this->loadTableNameData($schema);
     if (!isset($this->data['table_names'][$schema][$tableName])) {
         throw new \Exception('Table "' . $tableName . '" does not exist');
     }
     $data = $this->data['table_names'][$schema][$tableName];
     switch ($data['table_type']) {
         case 'BASE TABLE':
             $table = new Object\TableObject($tableName);
             break;
         case 'VIEW':
             $table = new Object\ViewObject($tableName);
             $table->setViewDefinition($data['view_definition']);
             $table->setCheckOption($data['check_option']);
             $table->setIsUpdatable($data['is_updatable']);
             break;
         default:
             throw new \Exception('Table "' . $tableName . '" is of an unsupported type "' . $data['table_type'] . '"');
     }
     $table->setColumns($this->getColumns($tableName, $schema));
     $table->setConstraints($this->getConstraints($tableName, $schema));
     return $table;
 }
Esempio n. 2
0
 /**
  * $tableName is used by constraint keys.
  */
 protected function loadFromCache($schema, $itemType, $itemName, $tableName = null)
 {
     if ($tableName) {
         if (isset($this->constraintKeys[$schema][$tableName][$itemName])) {
             return;
         }
     } else {
         $prop = $this->keyToProperty($itemType);
         if (isset($this->{$prop}[$schema][$itemName])) {
             return;
         }
     }
     $key = $this->cacheKey($schema . '.' . $itemType . '.' . $itemName);
     $data = $this->cache()->read($key);
     if (!$data) {
         $this->loadAndCache($schema, $itemType, $itemName, $key, $tableName);
     } else {
         switch ($itemType) {
             case 'tb':
                 $object = new ZfObject\TableObject($data['name']);
                 $this->setTableData($object, $data);
                 break;
             case 'vw':
                 $object = new ZfObject\ViewObject($data['name']);
                 $object->setViewDefinition($data['viewDefinition']);
                 $object->setCheckOption($data['checkPption']);
                 $object->setIsUpdatable($data['isUpdatable']);
                 $this->setTableData($object, $data);
                 break;
             case 'ck':
                 $object = new ZfObject\TriggerObject();
                 $object->setOrdinalPosition($data['ordinalPosition']);
                 $object->setReferencedTableSchema($data['referencedTableSchema']);
                 $object->setForeignKeyUpdateRule($data['updateRule']);
                 $object->setForeignKeyDeleteRule($data['deleteRule']);
                 $object->setReferencedTableName($data['referencedTableName']);
                 $object->setReferencedColumnName($data['referencedColumnName']);
                 break;
             case 'tr':
                 $object = new ZfObject\ConstraintKeyObject();
                 $object->setName($data['name']);
                 $object->setEventManipulation($data['eventManipulation']);
                 $object->setEventObjectCatalog($data['eventObjectCatalog']);
                 $object->setEventObjectSchema($data['eventObjectSchema']);
                 $object->setEventObjectTable($data['eventObjectTable']);
                 $object->setActionOrder($data['actionOrder']);
                 $object->setActionCondition($data['actionCondition']);
                 $object->setActionStatement($data['actionStatement']);
                 $object->setActionOrientation($data['actionOrientation']);
                 $object->setActionTiming($data['actionTiming']);
                 $object->setActionReferenceOldTable($data['actionReferenceOldTable']);
                 $object->setActionReferenceNewTable($data['actionReferenceNewTable']);
                 $object->setActionReferenceOldRow($data['actionReferenceOldRow']);
                 $object->setActionReferenceNewRow($data['actionReferenceNewRow']);
                 $object->setCreated($data['created']);
                 break;
         }
         $this->setItem($object, $schema, $itemType, $itemName, $tableName);
     }
 }