@param AttributeQueryBuilderInterface $attributeQb
@param mixed                          $data

@return AttributeQueryBuilderInterface
322102
protected function applyAttributeQueryBuilder(
        AttributeQueryBuilderInterface $attributeQb,
        $data
    ): AttributeQueryBuilderInterface {
        $input = $data['input'];
        switch ($data['option']) {
            case 'exact':
                return $attributeQb->equals($input);
            case 'like_':
                return $attributeQb->like(trim($input, '%').'%');
            case '_like':
                return $attributeQb->like('%'.trim($input, '%'));
            case '_like_':
                return $attributeQb->like('%'.trim($input, '%').'%');
            case 'notlike_':
                return $attributeQb->notLike(trim($input, '%').'%');
            case '_notlike':
                return $attributeQb->notLike('%'.trim($input, '%'));
            case '_notlike_':
                return $attributeQb->notLike('%'.trim($input, '%').'%');
            case 'empty':
                return $attributeQb->equals('');
            case 'notempty':
                return $attributeQb->notEquals('');
            case 'null':
                return $attributeQb->isNull();
            case 'notnull':
                return $attributeQb->isNotNull();
        }
        throw new \UnexpectedValueException("Unknown option '{$data['option']}'");
    }
1342777
public static function _parseManyToOne($query, $relationship, $attribute = null, $name = null)
    {
        $columns = $relationship->getColumns();

        if (!$name) {
            $name = $relationship->getName();
        }

        if (!$relationship->getParent()) {
            throw new AnDomainQueryException('Query Building Failed. Unkown Parent');
        } elseif ($relationship->isPolymorphic()) {
            reset($columns);
            $columns = array(key($columns) => current($columns));
        }

        $parent = $relationship->getParentRepository();
        $parent_query = $parent->getQuery();
        $condition = array();

        foreach ($columns as $parent_property => $child_column) {
            $result = self::parseColumn($parent_query, $parent_property);
            $condition[(string) $child_column] = $result['columns'];
        }

        $query->link($parent_query, $condition, array('as' => $name));

        if ($attribute) {
            $result = self::parseColumn($parent_query, $attribute);

            return $result;
        }
    }
623635
public function simpleQueryString($query, array $attributes = [])
    {
        $query = new SimpleQueryStringQuery($query, $attributes);

        $this->append($query);

        return $this;
    }
410440
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        /** @var AttributeInterface $attribute */
        $attribute = $options['attribute'];

        $builder
            ->add(
                'enabled',
                CheckboxType::class,
                [
                    'widget_checkbox_label' => 'label',
                ]
            )
            ->add(
                'column',
                TextType::class,
                [
                    'data' => $attribute->getCode(),
                ]
            );

        if ($attribute->getType()->isRelation()) {
            $builder->add(
                'serializedColumn',
                ChoiceType::class,
                [
                    'choices' => [
                        'EAV Identifier' => 'identifier',
                        'Doctrine Id' => 'id',
                        'Label (WARNING: not re-importable)' => 'label',
                    ],
                ]
            );
        }
    }
155163
public function addOrderBy(AttributeQueryBuilderInterface $attributeQueryBuilder, $direction = null)
    {
        $this->queryBuilder->addOrderBy($attributeQueryBuilder->applyJoin()->getColumn(), $direction);

        return $this;
    }
1080233
public static function query($poolName = null, $modelClass = null, $queryType = null): IQuery
    {
        return BeanFactory::newInstance(Query::class, null, $modelClass, $poolName, $queryType);
    }
1352132
protected function saveQuery(array $attributes = null): Query
    {
        return Query::update(static::$tableName)
            ->set($attributes ?? $this->getFieldsValues())
            ->where($this->getPKValue())
        ;
    }
178496
protected function insertAndSetId(Builder $query, $attributes)
    {
        $id = $query->insertGetId($attributes, $keyName = $this->getKeyName());

        $this->setAttribute($keyName, $id);
    }
1060055
protected function checkUnique(
        ExecutionContextInterface $context,
        AttributeInterface $attribute,
        DataInterface $data
    ) {
        $family = $data->getFamily();
        $valueData = $data->get($attribute->getCode());

        if (null === $valueData) { // Do not check uniqueness for null values
            return;
        }

        $query = [
            'attributeCode' => $attribute->getCode(),
            'familyCode' => $family->getCode(),
            $attribute->getType()->getDatabaseType() => $valueData,
        ];
        if ($attribute->getOption('global_unique')) {
            unset($query['familyCode']);
        }
        if ($attribute->getOption('unique_families')) {
            $query['familyCode'] = $attribute->getOption('unique_families');
        }

        /** @var ValueRepository $repo */
        $repo = $this->entityManager->getRepository($family->getValueClass());
        $values = $repo->findBy($query);

        /** @var ValueInterface $value */
        foreach ($values as $value) {
            if (!$value->getData()) {
                $this->logger->critical(
                    "Very weird Doctrine behavior: missing data for value #{$value->getIdentifier()}"
                );

                continue;
            }
            if ($value->getData()->getId() !== $data->getId()) {
                $this->buildAttributeViolation($data, $context, $attribute, 'unique', $valueData);

                return;
            }
        }
    }
537516
protected function hydrateAll(array $data, QueryBuilder $qb)
    {
        $rows = [];
        foreach ($data as $row) {
            $rows[] = $this->hydrate($row, $qb);
        }

        return $rows;
    }
1070294
public function execute(array $data) : QueryInterface
    {
        $data = Validator::validateData($this->table, $data, $this->user);

        // initialize query
        $query = $this->table->find('all');

        $where = $this->getWhereClause($data);
        $group = $this->getGroupByClause($data);
        $select = $this->getSelectClause($data);
        $order = [$this->table->aliasField($data['sort_by_field']) => $data['sort_by_order']];

        $joins = $this->byAssociations($data);
        // set joins and append to where and select parameters
        foreach ($joins as $name => $params) {
            $query->leftJoinWith($name);

            if (!empty($params['where'])) {
                $where = array_merge($where, $params['where']);
            }

            if (!empty($params['select'])) {
                $select = array_merge($select, $params['select']);
            }
        }

        $select = !empty($group) ? $group : $select;
        if (!empty($group)) {
            $select = $group;
            $select[static::GROUP_BY_FIELD] = $query->func()->count($group[0]);
        }

        // add query clauses
        $query->select($select)->where([$data['aggregator'] => $where])->order($order)->group($group);

        return $query;
    }
451901
protected function parseResult(DataInterface $data, AttributeInterface $attribute = null)
    {
        $m = __METHOD__.' is deprecated, use the '.ResponseRendererInterface::class.' service instead';

        throw new \BadMethodCallException($m);
    }
426856
public function searchKeywords($keywords, $queryBuilder)
    {
        if ($this->attributeKey) {
            $result = $queryBuilder->expr()->like('ak_' . $this->attributeKey->getAttributeKeyHandle(), ':keywords');
        } else {
            $result = null;
        }

        return $result;
    }
189341
protected function getQueryBuilderByAttribute(Request $request, AttributeInterface $attribute)
    {
        $term = '%'.trim($request->get('term'), '%').'%';

        if (!$attribute->getType()->isRelation() && !$attribute->getType()->isEmbedded()) {
            $family = $attribute->getFamily();
            $repository = $this->entityManager->getRepository($family->getDataClass());
            if (!$repository instanceof DataRepository) {
                throw new \UnexpectedValueException(
                    "Repository for class {$family->getDataClass()} must be a DataRepository"
                );
            }
            $eavQb = $repository->createFamilyQueryBuilder($family);
            $attributeQb = $eavQb->attribute($attribute);
            $qb = $eavQb->apply($attributeQb->like($term));
            $qb
                ->select($attributeQb->getColumn())
                ->groupBy($attributeQb->getColumn())
                ->orderBy($attributeQb->getColumn());

            return $qb;
        }

        /** @var array $familyCodes */
        $familyCodes = $attribute->getOption('allowed_families', []);
        $families = [];
        foreach ($familyCodes as $familyCode) {
            $families[] = $this->familyRegistry->getFamily($familyCode);
        }

        return $this->dataManager->getQbForFamiliesAndLabel($families, $term);
    }
294002
public function queryString($query, array $attributes = [])
    {
        $query = new QueryStringQuery($query, $attributes);

        $this->append($query);

        return $this;
    }
170985
private function getQueryAttrConverter(Store $store, AttributeMetadata $attrMeta)
    {
        return function ($value) use ($store, $attrMeta) {
            if (in_array($attrMeta->dataType, ['object', 'array'])) {
                // Leave the value as is.
                return $value;
            }
            $value = $store->convertAttributeValue($attrMeta->dataType, $value);
            return $this->getAttributeDbValue($attrMeta, $value);
        };

    }
242003
public function update($q, $data)
    {
        $q['table'] = $this->table;
        return $this->db->update($q, $data);
    }