コード例 #1
0
ファイル: FullTextUtils.php プロジェクト: justthefish/hesper
 /**
  * @throws WrongArgumentException
  * @return SelectQuery
  **/
 public static function makeFullTextQuery(FullTextDAO $dao, Criteria $criteria, $string)
 {
     Assert::isString($string, 'only strings accepted today');
     $array = self::prepareSearchString($string);
     if (!$array) {
         throw new ObjectNotFoundException();
     }
     if (!($field = $dao->getIndexField()) instanceof DBField) {
         $field = new DBField($dao->getIndexField(), $dao->getTable());
     }
     return $criteria->toSelectQuery()->andWhere(Expression::fullTextOr($field, $array))->prependOrderBy(Expression::fullTextRankAnd($field, $array))->desc();
 }
コード例 #2
0
 /**
  * @return SelectQuery
  **/
 protected function makeSelectQuery()
 {
     if ($this->criteria) {
         return $this->criteria->toSelectQuery();
     }
     return $this->container->getDao()->makeSelectHead();
 }
コード例 #3
0
ファイル: DaoMoveHelper.php プロジェクト: justthefish/hesper
 public static function down(DAOConnected $object, LogicalObject $exp = null)
 {
     $getMethod = 'get' . ucfirst(self::$property);
     Assert::isTrue(method_exists($object, $getMethod));
     $oldPosition = $object->{$getMethod}();
     $criteria = Criteria::create($object->dao())->add(Expression::gt(self::$property, $oldPosition))->addOrder(OrderBy::create(self::$property)->asc())->setLimit(1);
     if ($exp) {
         $criteria->add($exp);
     }
     if ($lowerObject = $criteria->get()) {
         DaoUtils::setNullValue(self::$nullValue);
         DaoUtils::swap($lowerObject, $object, self::$property);
     }
 }
コード例 #4
0
 /**
  * @return SQLFunction
  **/
 protected function getFunction(Criteria $criteria, JoinCapableQuery $query)
 {
     Assert::isNotNull($this->property);
     return SQLFunction::create('count', $this->property ? $criteria->getDao()->guessAtom($this->property, $query) : $criteria->getDao()->getIdName());
 }
コード例 #5
0
 /**
  * @throws WrongArgumentException
  * @return UnifiedContainer
  **/
 public function setCriteria(Criteria $criteria)
 {
     Assert::isTrue($criteria->getDao() === null || $criteria->getDao() === $this->dao, "criteria's dao doesn't match container's one");
     if (!$criteria->getDao()) {
         $criteria->setDao($this->dao);
     }
     $this->worker->setCriteria($criteria);
     return $this;
 }
コード例 #6
0
 /**
  * @return JoinCapableQuery
  **/
 public function process(Criteria $criteria, JoinCapableQuery $query)
 {
     Assert::isNotNull($this->property);
     return $query->get($criteria->getDao()->guessAtom($this->property, $query), $this->alias);
 }
コード例 #7
0
 /**
  * @return JoinCapableQuery
  **/
 public function process(Criteria $criteria, JoinCapableQuery $query)
 {
     Assert::isNotNull($this->property);
     return $query->get(SQLFunction::create($this->getFunctionName(), $criteria->getDao()->guessAtom($this->property, $query))->setAlias($this->alias));
 }
コード例 #8
0
ファイル: DaoIterator.php プロジェクト: justthefish/hesper
 private function loadNextChunk($id)
 {
     Assert::isNotNull($this->dao);
     $this->offset = 0;
     $criteria = Criteria::create($this->dao);
     if ($this->projection) {
         $criteria->setProjection($this->projection);
     }
     $criteria->addOrder($this->keyProperty)->setLimit($this->chunkSize);
     if ($id !== null) {
         $criteria->add(Expression::gt($this->keyProperty, $id));
     }
     // preserving memory bloat
     $this->dao->dropIdentityMap();
     $this->chunk = $criteria->getList();
     return $this->chunk;
 }
コード例 #9
0
 /**
  * @return MetaConfiguration
  **/
 public function checkIntegrity()
 {
     $out = $this->getOutput()->newLine()->infoLine('Checking sanity of generated files: ')->newLine();
     $out->info("\t");
     $formErrors = [];
     foreach ($this->classes as $name => $class) {
         if (!($class->getPattern() instanceof SpookedClassPattern || $class->getPattern() instanceof SpookedEnumerationPattern || $class->getPattern() instanceof SpookedEnumPattern || $class->getPattern() instanceof SpookedRegistryPattern || $class->getPattern() instanceof InternalClassPattern) && class_exists(MetaClassNameBuilder::getClassOfMetaClass($class, true))) {
             $out->info($name, true);
             $className = MetaClassNameBuilder::getClassOfMetaClass($class);
             $info = new \ReflectionClass($className);
             $this->checkClassSanity($class, $info);
             if ($info->implementsInterface(Prototyped::class)) {
                 $this->checkClassSanity($class, new \ReflectionClass($class->getProtoClass()));
             }
             if ($info->implementsInterface(DAOConnected::class)) {
                 $this->checkClassSanity($class, new \ReflectionClass($class->getDaoClass()));
             }
             foreach ($class->getInterfaces() as $interface) {
                 Assert::isTrue($info->implementsInterface($interface), 'class ' . $class->getName() . ' expected to implement interface ' . $interface);
             }
             // special handling for Enumeration instances
             if ($class->getPattern() instanceof EnumerationClassPattern || $class->getPattern() instanceof EnumClassPattern || $class->getPattern() instanceof RegistryClassPattern) {
                 $object = new $className(call_user_func([$className, 'getAnyId']));
                 Assert::isTrue(unserialize(serialize($object)) == $object);
                 $out->info(', ');
                 if ($this->checkEnumerationRefIntegrity) {
                     if ($object instanceof Enumeration || $object instanceof Enum || $object instanceof Registry) {
                         $this->checkEnumerationReferentialIntegrity($object, $class->getTableName());
                     }
                 }
                 continue;
             }
             if ($class->getPattern() instanceof AbstractClassPattern) {
                 $out->info(', ');
                 continue;
             }
             /** @var Prototyped $object */
             $object = new $className();
             $proto = $object->proto();
             $form = $proto->makeForm();
             foreach ($class->getProperties() as $name => $property) {
                 Assert::isTrue($property->toLightProperty($class) == $proto->getPropertyByName($name), 'defined property does not match autogenerated one - ' . $class->getName() . '::' . $property->getName());
             }
             if (!$object instanceof DAOConnected) {
                 $out->info(', ');
                 continue;
             }
             $dao = $object->dao();
             Assert::isEqual($dao->getIdName(), $class->getIdentifier()->getColumnName(), 'identifier name mismatch in ' . $class->getName() . ' class');
             try {
                 DBPool::getByDao($dao);
             } catch (MissingElementException $e) {
                 // skipping
                 $out->info(', ');
                 continue;
             }
             $query = Criteria::create($dao)->setLimit(1)->add(Expression::notNull($class->getIdentifier()->getName()))->addOrder($class->getIdentifier()->getName())->toSelectQuery();
             $out->warning(' (' . $query->getFieldsCount() . '/' . $query->getTablesCount() . '/');
             $clone = clone $object;
             if (serialize($clone) == serialize($object)) {
                 $out->info('C', true);
             } else {
                 $out->error('C', true);
             }
             $out->warning('/');
             try {
                 $object = $dao->getByQuery($query);
                 $form = $object->proto()->makeForm();
                 FormUtils::object2form($object, $form);
                 if ($errors = $form->getErrors()) {
                     $formErrors[$class->getName()] = $errors;
                     $out->error('F', true);
                 } else {
                     $out->info('F', true);
                 }
             } catch (ObjectNotFoundException $e) {
                 $out->warning('F');
             }
             $out->warning('/');
             if (Criteria::create($dao)->setFetchStrategy(FetchStrategy::cascade())->toSelectQuery() == $dao->makeSelectHead()) {
                 $out->info('H', true);
             } else {
                 $out->error('H', true);
             }
             $out->warning('/');
             // cloning once again
             $clone = clone $object;
             FormUtils::object2form($object, $form);
             FormUtils::form2object($form, $object);
             if ($object != $clone) {
                 $out->error('T', true);
             } else {
                 $out->info('T', true);
             }
             $out->warning(')')->info(', ');
         }
     }
     $out->infoLine('done.');
     if ($formErrors) {
         $out->newLine()->errorLine('Errors found:')->newLine();
         foreach ($formErrors as $class => $errors) {
             $out->errorLine("\t" . $class . ':', true);
             foreach ($errors as $name => $error) {
                 $out->errorLine("\t\t" . $name . ' - ' . ($error == Form::WRONG ? ' wrong' : ' missing'));
             }
             $out->newLine();
         }
     }
     return $this;
 }
コード例 #10
0
 /**
  * @return JoinCapableQuery
  **/
 public function process(Criteria $criteria, JoinCapableQuery $query)
 {
     return $query->get($this->mappable->toMapped($criteria->getDao(), $query), $this->alias);
 }
コード例 #11
0
ファイル: Cursor.php プロジェクト: avid/hesper
 public static function utilizeCriteria(Criteria $criteria)
 {
     return new self($criteria->getDao(), $criteria->toSelectQuery());
 }
コード例 #12
0
 /**
  * @return JoinCapableQuery
  **/
 public function process(Criteria $criteria, JoinCapableQuery $query)
 {
     return $query->having($this->logic->toMapped($criteria->getDao(), $query));
 }