示例#1
0
 public function createIndex($schemaId, $tableId, $indexId, TableSchemaInterface $tableSchema, IndexSchema $indexSchema)
 {
     $indexDataFilepath = sprintf(FilePathes::FILEPATH_INDEX_DATA, $schemaId, $tableId, $indexId);
     $indexDataFile = $this->filesystem->getFile($indexDataFilepath);
     $filePath = sprintf(FilePathes::FILEPATH_TABLE_COLUMN_INDEX, $schemaId, $tableId, $indexId);
     $indexDoublesFilepath = "";
     $indexDoublesFile = null;
     if (!$indexSchema->isUnique()) {
         $indexDoublesFilepath = sprintf(FilePathes::FILEPATH_INDEX_DOUBLES, $schemaId, $tableId, $indexId);
         $indexDoublesFile = $this->filesystem->getFile($indexDoublesFilepath);
     }
     $engine = $indexSchema->getEngine();
     /* @var $index IndexInterface */
     $index = null;
     if ($this->hasIndexFactory($engine)) {
         /* @var $indexFactory IndexFactoryInterface */
         $indexFactory = $this->getIndexFactory($engine);
         $index = $indexFactory->createIndex($schemaId, $tableId, $indexId, $tableSchema, $indexSchema);
     } else {
         switch ($engine) {
             default:
             case IndexEngine::RTREE():
                 $engineName = "UNKNOWN";
                 if (is_object($indexSchema->getEngine())) {
                     $engineName = $indexSchema->getEngine()->getName();
                 }
                 trigger_error("Requested unimplemented INDEX-ENGINE {$engineName}, using B-TREE instead!", E_USER_NOTICE);
                 # Use B-TREE instead of unimplemented index-engine
             # Use B-TREE instead of unimplemented index-engine
             case IndexEngine::BTREE():
                 $index = new BTree($indexDataFile, $tableSchema, $indexSchema);
                 if (!$indexSchema->isUnique()) {
                     $index->setDoublesFile($indexDoublesFile);
                 }
                 break;
             case IndexEngine::HASH():
                 $index = new HashTable($indexDataFile, $indexSchema->getKeyLength());
                 if (!$indexSchema->isUnique()) {
                     $index->setDoublesFile($indexDoublesFile);
                 }
                 break;
         }
     }
     return $index;
 }