@param PropertyMetadata               $mapping
@param Identifier|CompositeIdentifier $identifier

@return array Marshalled reference value
543460
private function prepareReferencedDocumentValue(PropertyMetadata $mapping, Identifier $identifier)
    {
        $hashKey            = $identifier->getHashKey();
        $hashType           = $hashKey->getType();
        $hashIndex          = $mapping->isStoreAsMap() ? $hashKey->getPropertyMetadata()->attributeName : 0;
        $return[$hashIndex] = $hashType->convertToDatabaseValue($identifier->getHashValue(), false);

        if ($identifier->isComposite()) {
            $rangeKey            = $identifier->getRangeKey();
            $rangeType           = $rangeKey->getType();
            $rangeIndex          = $mapping->isStoreAsMap() ? $rangeKey->getPropertyMetadata()->attributeName : 1;
            $return[$rangeIndex] = $rangeType->convertToDatabaseValue($identifier->getRangeValue(), false);
        }

        if ($mapping->targetDocument === null) {
            //add the discriminator value (if necessary)
            $discriminatorIndex = $mapping->isStoreAsMap() ? $mapping->discriminatorAttribute : count($return) + 1;
            $className          = $identifier->class->getName();

            //use discriminator map value if one exists
            if ($mapping->discriminatorMap !== null) {
                $discriminator = array_search($className, $mapping->discriminatorMap);

                if ($discriminator === false) {
                    unset($discriminator);
                }
            }

            //otherwise the FQCN is the discriminator
            if (!isset($discriminator)) {
                $discriminator = $className;
            }

            //only store if its not the same as the default
            if ($discriminator !== $mapping->discriminatorDefaultValue) {
                $return[$discriminatorIndex] = $discriminator;
            }
        }

        if ($mapping->isStoreAsJson()) {
            $return = json_encode($return);
        }

        return $mapping->getSerializationType()->convertToDatabaseValue($return);
    }
654698
public function prepareAssociatedDocumentValue(PropertyMetadata $mapping, $document, $includeNestedCollections = false)
    {
        if ($document === null) {
            return Type::getNull();
        }

        if ($mapping->embedded) {
            return $this->prepareEmbeddedDocumentValue($mapping, $document, $includeNestedCollections);
        }

        if ($mapping->reference) {
            $class      = $this->dm->getClassMetadata(get_class($document));
            $identifier = $class->createIdentifier($document);

            return $this->prepareReferencedDocumentValue($mapping, $identifier);
        }

        throw new \InvalidArgumentException('Mapping is neither embedded nor reference.');
    }
626938
protected function findByMetaSetAndTarget(MetaSetInterface $metaSet, $target = null)
    {
        $metaDatas = array();

        foreach ($this->findMetaDataValues($metaSet, $target) as $metaDataValue) {
            $identifier = $metaDataValue->getSetId();

            if (!isset($metaDatas[$identifier])) {
                $metaData = new MetaData($metaSet);
                $metaDatas[$identifier] = $metaData;
            } else {
                $metaData = $metaDatas[$identifier];
            }

            $field = $metaSet->getFieldById($metaDataValue->getFieldId());

            if (!$field) {
                $this->logger->error(sprintf("MetaSet with id %s doesn't exist", $metaDataValue->getFieldId()));
                continue;
            }

            $metaData->set($field->getName(), $metaDataValue->getValue(), $metaDataValue->getLanguage());
        }

        return $metaDatas;
    }
1200199
private function formatPropertyMappings(iterable $propertyMappings)
    {
        $output = [];

        foreach ($propertyMappings as $propertyName => $property) {
            $output[] = $this->formatField(sprintf('  %s', $propertyName), '');

            if ($property instanceof FieldMetadata) {
                $output = array_merge($output, $this->formatColumn($property));
            } elseif ($property instanceof AssociationMetadata) {
                // @todo guilhermeblanco Fix me! We are trying to iterate through an AssociationMetadata instance
                foreach ($property as $field => $value) {
                    $output[] = $this->formatField(sprintf('    %s', $field), $this->formatValue($value));
                }
            }
        }

        return $output;
    }
468840
protected function serializeResource(ResourceInterface $resource, bool $identifierOnly = true): array
    {
        $data = [
            'type' => $resource->type(),
            'id' => $resource->id(),
        ];

        if (!$resource->metaInformation()->isEmpty()) {
            $data['meta'] = $resource->metaInformation()->all();
        }

        if ($identifierOnly) {
            if ($resource instanceof RelatedMetaInformationInterface && !$resource->relatedMetaInformation()->isEmpty()) {
                foreach ($resource->relatedMetaInformation()->all() as $key => $value) {
                    $data['meta'][$key] = $value;
                }
            }

            return $data;
        }

        if (!$resource->attributes()->isEmpty()) {
            $data['attributes'] = $resource->attributes()->all();
        }

        foreach ($resource->relationships()->all() as $relationship) {
            $data['relationships'][$relationship->name()] = $this->serializeRelationship($relationship);
        }

        foreach ($resource->links()->all() as $link) {
            $data['links'][$link->name()] = $this->serializeLink($link);
        }

        return $data;
    }
258668
private List<Object> populateEmbeddedIdUsingLucene(EntityMetadata m, Client client, List<Object> result,
            Map<String, Object> searchFilter, MetamodelImpl metaModel)
    {
        List<Object> compositeIds = new ArrayList<Object>();

        for (String compositeIdName : searchFilter.keySet())
        {
            Object compositeId = null;
            Map<String, String> uniquePKs = (Map<String, String>) searchFilter.get(compositeIdName);
            compositeId = KunderaCoreUtils.initialize(m.getIdAttribute().getBindableJavaType(), compositeId);

            prepareCompositeIdObject(m.getIdAttribute(), compositeId, uniquePKs, metaModel);
            compositeIds.add(compositeId);
        }
        return findUsingLucene(m, client, compositeIds.toArray());
    }
1144308
protected static function removeTypeAndId(array &$mappings, array $copy)
    {
        if (!empty($copy[Serializer::CLASS_IDENTIFIER_KEY])) {
            $type = $copy[Serializer::CLASS_IDENTIFIER_KEY];

            if (\is_scalar($type) && !empty($mappings[$type])) {
                foreach ($mappings[$type]->getIdProperties() as $propertyName) {
                    unset($copy[$propertyName]);
                }
                unset($copy[Serializer::CLASS_IDENTIFIER_KEY]);
            }
        }

        return $copy;
    }
635382
public static function getWhere(DataTablesMappingInterface $mapping) {

        $where = [
            static::getAlias($mapping),
            static::getComparator($mapping),
            static::getParam($mapping),
        ];

        return implode(" ", $where);
    }
130011
protected function getIdentifierRepresentation(IdentifierInterface $identifier): array
    {
        // it's odd not to have actual ID for identifier (which is OK for newly created resource).
        \assert($identifier->getId() !== null);

        return $identifier->hasIdentifierMeta() === false ? [
            DocumentInterface::KEYWORD_TYPE => $identifier->getType(),
            DocumentInterface::KEYWORD_ID   => $identifier->getId(),
        ] : [
            DocumentInterface::KEYWORD_TYPE => $identifier->getType(),
            DocumentInterface::KEYWORD_ID   => $identifier->getId(),
            DocumentInterface::KEYWORD_META => $identifier->getIdentifierMeta(),
        ];
    }
418660
public function loadReference(PropertyMetadata $mapping, $value)
    {
        $value = $mapping->getSerializationType()->convertToPHPValue($value);

        if ($mapping->isStoreAsJson()) {
            $value = json_decode($value);
        }

        $discriminator = null;
        if ($mapping->targetDocument === null) {
            if ($mapping->isStoreAsMap()) {
                //check for a discriminator value
                $attribute     = $mapping->discriminatorAttribute;
                $discriminator = isset($value[$attribute]) ? $value[$attribute] : null;
            } else {
                //mixed reference list types must always provide a discriminator
                $discriminator = end($value);
            }
        }

        $class      = $this->getDiscriminatedClass($mapping, $discriminator);
        $index      = $class->getIndex();
        $hashKey    = $index->getHashKey();
        $hashType   = $hashKey->getType();
        $hashIndex  = $mapping->isStoreAsMap() ? $hashKey->getPropertyMetadata()->attributeName : 0;
        $hashValue  = $hashType->convertToPHPValue($value[$hashIndex], false);
        $rangeValue = null;

        if ($index->isComposite()) {
            $rangeKey   = $index->getRangeKey();
            $rangeType  = $rangeKey->getType();
            $rangeIndex = $mapping->isStoreAsMap() ? $rangeKey->getPropertyMetadata()->attributeName : 1;
            $rangeValue = $rangeType->convertToPHPValue($value[$rangeIndex], false);
        }

        return $class->createIdentifierFromValues($hashValue, $rangeValue);
    }
1344328
protected function loadPropertiesForSubclass(IObjectMapping $mapping, array $rows, array $objectProperties): array
    {
        $objectsPropertiesOfSubClass = [];
        $rowsForSubClass             = [];

        foreach ($rows as $key => $row) {
            if ($mapping->rowMatchesType($row)) {
                $objectsPropertiesOfSubClass[$key] = $objectProperties[$key];
                $rowsForSubClass[$key]             = $row;
            }
        }

        return [$objectsPropertiesOfSubClass, $rowsForSubClass];
    }
662810
public function flattenIdentifier(ClassMetadata $class, array $id)
    {
        $flatId = [];

        foreach ($class->identifier as $field) {
            $property = $class->getProperty($field);

            if ($property instanceof FieldMetadata) {
                $flatId[$field] = $id[$field];

                continue;
            }

            if (isset($id[$field]) && is_object($id[$field])) {
                /** @var ClassMetadata $targetClassMetadata */
                $targetClassMetadata  = $this->metadataFactory->getMetadataFor($property->getTargetEntity());
                $targetClassPersister = $this->unitOfWork->getEntityPersister($property->getTargetEntity());
                // @todo guilhermeblanco Bring this back:
                // $identifiers         = $this->unitOfWork->isInIdentityMap($id[$field])
                //     ? $this->unitOfWork->getEntityIdentifier($id[$field])
                //     : $targetClassPersister->getIdentifier($id[$field])
                // ;
                $identifiers = $targetClassPersister->getIdentifier($id[$field]);

                $associatedId = $this->flattenIdentifier($targetClassMetadata, $identifiers);

                $flatId[$field] = implode(' ', $associatedId);

                continue;
            }

            $associatedId = [];

            foreach ($property->getJoinColumns() as $joinColumn) {
                $associatedId[] = $id[$joinColumn->getColumnName()];
            }

            $flatId[$field] = implode(' ', $associatedId);
        }

        return $flatId;
    }
604568
public function setVersionMapping(PropertyMetadata $mapping)
    {
        if ($mapping->type !== Type::INT && $mapping->type !== Type::DATE) {
            throw LockException::invalidVersionAttributeType($mapping->type);
        }

        $this->isVersioned      = true;
        $this->versionAttribute = $mapping->name;
    }
1080718
public static function getIdValues(array $mappings, array $value, $type)
    {
        $ids = [];
        foreach (\array_keys($value) as $propertyName) {
            if (\in_array($propertyName, RecursiveFormatterHelper::getIdProperties($mappings, $type), true)) {
                $id = RecursiveFormatterHelper::getIdValue($value[$propertyName]);
                $ids[] = (\is_array($id)) ? \implode(JsonApiTransformer::ID_SEPARATOR, $id) : $id;
            }
        }

        return $ids;
    }
436988
private function mapTranslatable(ClassMetadata $mapping)
    {
        $metadata = $this->getTranslatableMetadata($mapping->name);

        if ($metadata->targetEntity
            && $metadata->translations
            && !$mapping->hasAssociation($metadata->translations->name)
        ) {
            $targetMetadata = $this->getTranslatableMetadata($metadata->targetEntity);

            $mapping->mapOneToMany(array(
                'fieldName'     => $metadata->translations->name,
                'targetEntity'  => $metadata->targetEntity,
                'mappedBy'      => $targetMetadata->translatable->name,
                'fetch'         => ClassMetadataInfo::FETCH_EXTRA_LAZY,
                'indexBy'       => $targetMetadata->locale->name,
                'cascade'       => array('persist', 'merge', 'remove'),
                'orphanRemoval' => true,
            ));
        }
    }
81611
function mappingTable( $identifier )
    {
        if ( isset( $this->TransformationTables[$identifier] ) )
            return $this->TransformationTables[$identifier];
        return false;
    }
757998
public function setIdentifier($identifier)
    {
        if ($this->identifier && $this->identifier !== $identifier) {
            throw new MappingException('Cannot map the identifier to more than one property');
        }

        $this->identifier = $identifier;
    }