indexedQuery() public method

Create a query against a table matching one or more indices
public indexedQuery ( IndexedQuery $query, boolean $use_cache = true ) : QueryResult
$query Bravo3\Orm\Query\IndexedQuery
$use_cache boolean
return Bravo3\Orm\Query\QueryResult
Exemplo n.º 1
0
 /**
  * @dataProvider entityManagerDataProvider
  * @param EntityManager $em
  */
 public function testIdQuery(EntityManager $em)
 {
     $a = new IndexedEntity();
     $a->setId1('1');
     $a->setId2('first');
     $a->setAlpha('alpha1');
     $a->setBravo(1);
     $a->setCharlie(true);
     $b = new IndexedEntity();
     $b->setId1('2');
     $b->setId2('second');
     $b->setAlpha('alpha2');
     $b->setBravo(2);
     $b->setCharlie(false);
     $em->persist($a)->persist($b)->flush();
     $result = $em->indexedQuery(new IndexedQuery(IndexedEntity::class, ['@id' => '1.fir*']));
     $this->assertCount(1, $result);
     /** @var IndexedEntity $entity */
     $entity = $result->current();
     $this->assertEquals('1', $entity->getId1());
     $this->assertEquals('first', $entity->getId2());
     $this->assertEquals('alpha1', $entity->getAlpha());
     $result = $em->indexedQuery(new IndexedQuery(IndexedEntity::class, ['@id' => '*']));
     $this->assertGreaterThanOrEqual(2, count($result));
     $result = $em->indexedQuery(new IndexedQuery(IndexedEntity::class, ['@id' => '*', 'ab' => 'alpha1*']));
     $this->assertCount(1, $result);
     /** @var IndexedEntity $entity */
     $entity = $result->current();
     $this->assertEquals('1', $entity->getId1());
     $this->assertEquals('first', $entity->getId2());
     $this->assertEquals('alpha1', $entity->getAlpha());
 }
Exemplo n.º 2
0
 /**
  * Will rebuild a table, repairing indices and re-serialising content
  *
  * The end result will be:
  * - new inverse indices will be created
  * - changes to serialisation will be updated on all entities
  * - added/removed fields will be updated on all entities
  *
  * @param string $class_name
  * @param int    $batch_size
  */
 public function rebuild($class_name, $batch_size = 100)
 {
     $this->maintenanceOperation(function () use($class_name, $batch_size) {
         $metadata = $this->entity_manager->getMapper()->getEntityMetadata($class_name);
         $this->logger->info("Rebuilding `" . $metadata->getTableName() . "`..");
         $records = $this->entity_manager->indexedQuery(new IndexedQuery($class_name, ['@id' => '*']), false);
         $this->logger->info(number_format($records->count()) . ' records to rebuild, ' . number_format($batch_size) . ' at a time');
         $ts = microtime(true);
         $this->rebuildRecords($records, $metadata, $batch_size);
         $delta = microtime(true) - $ts;
         $this->logger->info("Rebuild of `" . $metadata->getTableName() . "` completed in " . number_format($delta, 2) . " seconds");
     });
 }