Beispiel #1
0
 public function __construct(FileInterface $file, TableSchemaInterface $tableSchema, IndexSchema $indexPage = null, $forkRate = 33)
 {
     $keyLength = 0;
     foreach ($indexPage->getColumns() as $columnId) {
         /* @var $columnPage ColumnSchema */
         $columnPage = $tableSchema->getColumn($columnId);
         assert(!is_null($columnPage));
         $keyLength += $columnPage->getCellSize();
     }
     if ($keyLength < 4) {
         $keyLength = 4;
     }
     if (!is_numeric($forkRate)) {
         throw new \ErrorException("Forkrate has to specified as integer!");
     }
     $forkRate = (int) $forkRate;
     $this->file = $file;
     $this->setKeyLength($keyLength);
     $this->forkRate = $forkRate;
     $this->tableSchema = $tableSchema;
     $this->indexPage = $indexPage;
     // if file is empty, initialize it
     if ($file->getLength() <= 1) {
         $file->setData(str_pad("", $keyLength * 8, ""));
         $rootNode = new BTreeNodePage();
         $rootNode->setKeyLength($keyLength);
         $rootNode->setForkRate($this->forkRate);
         // make sure root-reference is in index 1, not 0.
         // that way we can use reference 0 as 'not defined'/'not used'
         $this->setRootReference(1);
         $this->writeNode($rootNode, 1);
     }
 }
Beispiel #2
0
 public function createTable($schemaId, $tableId, TableSchemaInterface $tableSchema, IndexFactoryInterface $indexFactory)
 {
     $autoincrementFilePath = sprintf(FilePathes::FILEPATH_AUTOINCREMENT, $schemaId, $tableId);
     $deletedRowsFilepath = sprintf(FilePathes::FILEPATH_DELETED_ROWS, $schemaId, $tableId);
     /* @var $autoincrementFile FileInterface */
     $autoincrementFile = $this->filesystem->getFile($autoincrementFilePath);
     /* @var $deletedRowsFile FileInterface */
     $deletedRowsFile = $this->filesystem->getFile($deletedRowsFilepath);
     $columnDatas = array();
     foreach ($tableSchema->getColumnIterator() as $columnId => $columnSchema) {
         /* @var $columnSchema ColumnSchema */
         $columnDatas[$columnId] = $this->columnDataFactory->createColumnData($schemaId, $tableId, $columnId, $columnSchema);
     }
     $indexes = array();
     foreach ($tableSchema->getIndexIterator() as $indexId => $indexSchema) {
         /* @var $indexSchema IndexSchema */
         $indexes[$indexId] = $indexFactory->createIndex($schemaId, $tableId, $indexId, $tableSchema, $indexSchema);
     }
     $table = new Table($tableSchema, $columnDatas, $indexes, $autoincrementFile, $deletedRowsFile, $valueResolver = null, $dataConverter = null);
     return $table;
 }