Marshals an embedded field represented by the given metadata.

@param embeddedMetadata
the metadata of the embedded field
@param target
the target object to which the embedded object belongs
764514
private void marshalWithExplodedStrategy(EmbeddedMetadata embeddedMetadata, Object target) {
    try {
      Object embeddedObject = initializeEmbedded(embeddedMetadata, target);
      for (PropertyMetadata propertyMetadata : embeddedMetadata.getPropertyMetadataCollection()) {
        marshalField(propertyMetadata, embeddedObject);
      }
      for (EmbeddedMetadata embeddedMetadata2 : embeddedMetadata.getEmbeddedMetadataCollection()) {
        marshalWithExplodedStrategy(embeddedMetadata2, embeddedObject);
      }
    } catch (Throwable t) {
      throw new EntityManagerException(t);
    }
  }
975616
@VisibleForTesting
  protected void initMetadata(
      @Nullable String encoding, long sizeFromMetadata, @Nullable String generation)
      throws IOException {
    checkState(
        !metadataInitialized,
        "can not initialize metadata, it already initialized for '%s'", resourceIdString);
    gzipEncoded = nullToEmpty(encoding).contains(GZIP_ENCODING);
    if (gzipEncoded) {
      size = Long.MAX_VALUE;
    } else {
      size = sizeFromMetadata;
    }
    randomAccess = !gzipEncoded && readOptions.getFadvise() == Fadvise.RANDOM;
    checkEncodingAndAccess();

    initGeneration(generation);

    metadataInitialized = true;

    logger.atFine().log(
        "Initialized metadata (gzipEncoded=%s, size=%s, randomAccess=%s, generation=%s) for '%s'",
        gzipEncoded, size, randomAccess, generation, resourceIdString);
  }
502124
public function processClassMetadata(ClassMetadata $metadata, $property, $prefix)
    {
        if (in_array($metadata->getName(), $this->processedClasses)) {
            return;
        }

        $metadata->mapEmbedded([
            'fieldName'    => $property,
            'class'        => $this->embeddableMetadata->getName(),
            'columnPrefix' => empty($prefix) ? false : $prefix,
        ]);

        $metadata->inlineEmbeddable($property, $this->embeddableMetadata);

        $this->processedClasses[] = $metadata->getName();
    }
376967
@Override
    public final void setMetadataProperty(final String key, final String value) {
        _metadataProperties.put(key, value);
    }
75655
public void clearMetaData(Object key) {        if (key == this.key) {
            key = null;
            wmmd = null;
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "MetaData was removed.");
            }
        } else {
        }
    }
740628
protected void addEntityFieldsToDocument(EntityMetadata metadata, Object entity, Document document,
        MetamodelImpl metaModel) {
        String indexName = metadata.getIndexName();
        Map<String, PropertyIndex> indexProperties = metadata.getIndexProperties();
        for (String columnName : indexProperties.keySet()) {
            PropertyIndex index = indexProperties.get(columnName);
            java.lang.reflect.Field property = index.getProperty();
            String propertyName = index.getName();
            addFieldToDocument(entity, document, property, propertyName, indexName);
        }

        if (metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType())) {
            Object id = PropertyAccessorHelper.getId(entity, metadata);
            EmbeddableType embeddableId = metaModel.embeddable(metadata.getIdAttribute().getBindableJavaType());
            Set<Attribute> embeddedAttributes = embeddableId.getAttributes();
            indexCompositeKey(embeddedAttributes, metadata, id, document, metaModel);
        }
    }
194369
private static Object deepCopyUsingMetadata(Object source, Map<Object, Object> copiedObjectMap,
            final KunderaMetadata kunderaMetadata)
    {
        Object target = null;
        try
        {
            if (source == null)
            {
                return null;
            }
            Class<?> sourceObjectClass = source.getClass();
            EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, sourceObjectClass);
            if (metadata == null)
            {
                return source;
            }

            MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                    metadata.getPersistenceUnit());

            EntityType entityType = metaModel.entity(sourceObjectClass);

            // May break for mapped super class.

            Object id = null;
            if (metadata.getRelations() != null && !metadata.getRelations().isEmpty())
            {

                id = PropertyAccessorHelper.getId(source, metadata);

                StringBuilder keyBuilder = new StringBuilder(sourceObjectClass.getName());
                keyBuilder.append("#");
                keyBuilder.append(id);
                Object copiedObjectInMap = copiedObjectMap.get(keyBuilder.toString());
                if (copiedObjectInMap != null)
                {
                    return copiedObjectInMap;
                }
            }
            // Copy Columns (in a table that doesn't have any embedded objects

            target = KunderaCoreUtils.createNewInstance(sourceObjectClass);

            Iterator<Attribute> iter = entityType.getAttributes().iterator();
            while (iter.hasNext())
            {
                Attribute attrib = iter.next();

                Field columnField = (Field) attrib.getJavaMember();
                if (attrib.getPersistentAttributeType().equals(PersistentAttributeType.EMBEDDED)
                        || attrib.getPersistentAttributeType().equals(PersistentAttributeType.ELEMENT_COLLECTION))
                {
                    EmbeddableType embeddedColumn = metaModel.embeddable(((AbstractAttribute) attrib)
                            .getBindableJavaType());

                    Object sourceEmbeddedObj = PropertyAccessorHelper.getObject(source, columnField);
                    if (sourceEmbeddedObj != null)
                    {
                        if (metaModel.isEmbeddable(((AbstractAttribute) attrib).getBindableJavaType()))
                        {
                            if (attrib.isCollection())
                            {
                                Class<?> ecDeclaredClass = columnField.getType();
                                Class<?> actualEcObjectClass = sourceEmbeddedObj.getClass();

                                Object targetCollectionObject = actualEcObjectClass.newInstance();

                                // Copy element collections for List and Set
                                if (sourceEmbeddedObj instanceof Collection)
                                {
                                    Class<?> genericClass = PropertyAccessorHelper.getGenericClass(columnField);

                                    for (Object sourceEcObj : (Collection) sourceEmbeddedObj)
                                    {
                                        Object targetEcObj = null;
                                        if (sourceEcObj != null
                                                && PersistenceType.BASIC.equals(embeddedColumn.getPersistenceType()))
                                        {
                                            PropertyAccessor accessor = PropertyAccessorFactory
                                                    .getPropertyAccessor(sourceEcObj.getClass());
                                            if (accessor != null)
                                            {
                                                targetEcObj = accessor.getCopy(sourceEcObj);
                                            }
                                        }
                                        else if (sourceEcObj != null
                                                && PersistenceType.EMBEDDABLE.equals(embeddedColumn
                                                        .getPersistenceType()))
                                        {
                                            targetEcObj = genericClass.newInstance();

                                            for (Field f : genericClass.getDeclaredFields())
                                            {
                                                if (f != null && !Modifier.isStatic(f.getModifiers()))
                                                {
                                                    PropertyAccessorHelper.set(targetEcObj, f,
                                                            PropertyAccessorHelper.getObjectCopy(sourceEcObj, f));
                                                }
                                            }
                                        }
                                        if (List.class.isAssignableFrom(ecDeclaredClass))
                                        {
                                            Method m = actualEcObjectClass.getMethod("add", Object.class);
                                            m.invoke(targetCollectionObject, targetEcObj);

                                        }
                                        else if (Set.class.isAssignableFrom(ecDeclaredClass))
                                        {
                                            Method m = actualEcObjectClass.getMethod("add", Object.class);
                                            m.invoke(targetCollectionObject, targetEcObj);
                                        }
                                    }
                                }

                                // Copy element collection for Map
                                else if (sourceEmbeddedObj instanceof Map)
                                {
                                    for (Object sourceKey : ((Map) sourceEmbeddedObj).keySet())
                                    {
                                        Object targetKey = null;
                                        Object targetValue = null;
                                        if (PersistenceType.BASIC.equals(embeddedColumn.getPersistenceType())
                                                || PersistenceType.EMBEDDABLE.equals(embeddedColumn
                                                        .getPersistenceType()))
                                        {
                                            // Create copy of map key
                                            if (sourceKey != null)
                                            {
                                                PropertyAccessor keyAccessor = PropertyAccessorFactory
                                                        .getPropertyAccessor(sourceKey.getClass());
                                                if (keyAccessor != null)
                                                {
                                                    targetKey = keyAccessor.getCopy(sourceKey);
                                                }
                                            }
                                            else
                                            {
                                                targetKey = null;
                                            }

                                            // Create copy of map value
                                            Object sourceValue = ((Map) sourceEmbeddedObj).get(sourceKey);
                                            if (sourceValue != null)
                                            {
                                                PropertyAccessor valueAccessor = PropertyAccessorFactory
                                                        .getPropertyAccessor(sourceValue.getClass());
                                                if (valueAccessor != null)
                                                {
                                                    targetValue = valueAccessor.getCopy(sourceValue);
                                                }
                                            }
                                            else
                                            {
                                                targetValue = null;
                                            }

                                            if (Map.class.isAssignableFrom(ecDeclaredClass))
                                            {
                                                Method m = actualEcObjectClass.getMethod("put", new Class[] {
                                                        Object.class, Object.class });
                                                m.invoke(targetCollectionObject,
                                                        new Object[] { targetKey, targetValue });
                                            }
                                        }
                                    }
                                }
                                PropertyAccessorHelper.set(target, columnField, targetCollectionObject);
                            }
                            else
                            {
                                // Copy embedded objects
                                Class<?> embeddedColumnClass = columnField.getType();
                                Object targetEmbeddedObj = embeddedColumnClass.newInstance();

                                Set<Attribute> columns = embeddedColumn.getAttributes();
                                for (Attribute column : columns)
                                {
                                    PropertyAccessorHelper.set(
                                            targetEmbeddedObj,
                                            (Field) column.getJavaMember(),
                                            PropertyAccessorHelper.getObjectCopy(sourceEmbeddedObj,
                                                    (Field) column.getJavaMember()));
                                }

                                PropertyAccessorHelper.set(target, columnField, targetEmbeddedObj);
                            }
                        }
                        else if (((AbstractAttribute) attrib).getJPAColumnName() != null)
                        {
                            // Copy columns
                            PropertyAccessorHelper.set(target, columnField, sourceEmbeddedObj);
                        }
                    }

                }
                else if (attrib.getPersistentAttributeType().equals(PersistentAttributeType.BASIC))
                {

                    PropertyAccessorHelper.set(target, columnField,
                            PropertyAccessorHelper.getObjectCopy(source, columnField));
                }
            }

            // Put this object into copied object map
            if (id != null)
            {
                StringBuilder keyBuilder = new StringBuilder(sourceObjectClass.getName());
                keyBuilder.append("#");
                keyBuilder.append(id);
                copiedObjectMap.put(keyBuilder.toString(), target);
            }
            // Copy Relationships recursively
            for (Relation relation : metadata.getRelations())
            {
                if (relation != null)
                {
                    Field relationField = relation.getProperty();
                    Object sourceRelationObject = PropertyAccessorHelper.getObject(source, relationField);

                    if (sourceRelationObject != null)
                    {
                        if (sourceRelationObject instanceof KunderaProxy)
                        {
                            PropertyAccessorHelper.set(target, relationField, sourceRelationObject);
                            continue;
                        }
                        else if (ProxyHelper.isPersistentCollection(sourceRelationObject))
                        {
                            PropertyAccessorHelper.set(target, relationField, sourceRelationObject);
                            continue;
                        }
                        else if (ProxyHelper.isKunderaProxyCollection(sourceRelationObject))
                        {
                            ProxyCollection pc = ((ProxyCollection) sourceRelationObject).getCopy();
                            pc.setOwner(target);
                            PropertyAccessorHelper.set(target, relationField, pc);
                            continue;
                        }

                        Object targetRelationObject = null;

                        Class<?> relationObjectClass = relation.getProperty().getType();
                        Class<?> actualRelationObjectClass = sourceRelationObject.getClass();

                        if (Collection.class.isAssignableFrom(relationObjectClass))
                        {
                            targetRelationObject = actualRelationObjectClass.newInstance();
                            Method m = actualRelationObjectClass.getMethod("add", Object.class);

                            for (Object obj : (Collection) sourceRelationObject)
                            {
                                Object copyTargetRelObj = searchInCacheThenCopy(copiedObjectMap, obj, kunderaMetadata);
                                m.invoke(targetRelationObject, copyTargetRelObj);
                            }
                        }
                        else if (Map.class.isAssignableFrom(relationObjectClass))
                        {
                            targetRelationObject = actualRelationObjectClass.newInstance();
                            Method m = actualRelationObjectClass.getMethod("put", new Class<?>[] { Object.class,
                                    Object.class });

                            for (Object keyObj : ((Map) sourceRelationObject).keySet())
                            {
                                Object valObj = ((Map) sourceRelationObject).get(keyObj);

                                Object copyTargetKeyObj = searchInCacheThenCopy(copiedObjectMap, keyObj,
                                        kunderaMetadata);

                                Object copyTargetValueObj = searchInCacheThenCopy(copiedObjectMap, valObj,
                                        kunderaMetadata);

                                m.invoke(targetRelationObject, new Object[] { copyTargetKeyObj, copyTargetValueObj });
                            }
                        }
                        else
                        {
                            targetRelationObject = searchInCacheThenCopy(copiedObjectMap, sourceRelationObject,
                                    kunderaMetadata);
                        }
                        PropertyAccessorHelper.set(target, relationField, targetRelationObject);
                    }
                }
            }
        }
        catch (InstantiationException e)
        {
            log.warn("Error while instantiating entity/ embeddable class, did you define no-arg constructor?, Caused by:"
                    + e.getMessage());
            return null;
        }
        catch (Exception e)
        {
            log.warn("Returning null as error during clone, Caused by:" + e.getMessage());
            return null;
        }

        return target;
    }
144509
public void copyMetaDataFrom(EncodedImage encodedImage) {
    mImageFormat = encodedImage.getImageFormat();
    mWidth = encodedImage.getWidth();
    mHeight = encodedImage.getHeight();
    mRotationAngle = encodedImage.getRotationAngle();
    mExifOrientation = encodedImage.getExifOrientation();
    mSampleSize = encodedImage.getSampleSize();
    mStreamSize = encodedImage.getSize();
    mBytesRange = encodedImage.getBytesRange();
    mColorSpace = encodedImage.getColorSpace();
  }
908351
@Override
    public void endMetaData(MetaData metadata)
    {
        this.builder.addBlock(new MetaDataBlock(this.builder.endBlockList(), metadata));
    }
367677
@Override
    public void addRelationIntoMetadata(Field relationField, EntityMetadata metadata)
    {
        // taking field's type as foreign entity, ignoring "targetEntity"
        Class<?> targetEntity = relationField.getType();

        ManyToOne ann = relationField.getAnnotation(ManyToOne.class);
        Relation relation = new Relation(relationField, targetEntity, null, ann.fetch(), Arrays.asList(ann.cascade()),
                ann.optional(), null, // mappedBy is null
                Relation.ForeignKey.MANY_TO_ONE);

        boolean isJoinedByFK = relationField.isAnnotationPresent(JoinColumn.class);

        if (relationField.isAnnotationPresent(AssociationOverride.class))
        {
            AssociationOverride annotation = relationField.getAnnotation(AssociationOverride.class);
            JoinColumn[] joinColumns = annotation.joinColumns();

            relation.setJoinColumnName(joinColumns[0].name());

        }
        else if (isJoinedByFK)
        {
            JoinColumn joinColumnAnn = relationField.getAnnotation(JoinColumn.class);
            relation.setJoinColumnName(StringUtils.isBlank(joinColumnAnn.name()) ? relationField.getName()
                    : joinColumnAnn.name());
        }
        else
        {
            relation.setJoinColumnName(relationField.getName());
        }

        relation.setBiDirectionalField(metadata.getEntityClazz());
        metadata.addRelation(relationField.getName(), relation);

    }
111927
public void processMetadata(Metadata metadata) {
        synchronized (frameListeners) {
            Iterator<FrameListener> it = frameListeners.iterator();
            while (it.hasNext()) {
                FrameListener listener = it.next();
                listener.processMetadata(metadata);
            }
        }
    }
48175
public function mapOneEmbedded(ClassMetadata $class)
    {
        $this->embedded = true;
        $this->type     = self::TYPE_ONE;

        $this->mapAttribute($class);
    }
952078
private boolean matchMetadata(MetaData metadata)
    {
        boolean match;

        if (this.metadataValue != null) {
            Object value = metadata.getMetaData(this.metadataKey);
            match = value != null && value.equals(this.metadataValue);
        } else {
            match = metadata.contains(this.metadataKey);
        }

        return match;
    }
78758
public void prepareEmbeddedId(TopDocs docs, Map<String, Object> indexCol, IndexSearcher searcher,
            EntityMetadata metadata, MetamodelImpl metaModel)
    {
        try
        {
            for (ScoreDoc sc : docs.scoreDocs)
            {
                Document doc = searcher.doc(sc.doc);
                Map<String, Object> embeddedIdFields = new HashMap<String, Object>();
                EmbeddableType embeddableId = metaModel.embeddable(metadata.getIdAttribute().getBindableJavaType());
                Set<Attribute> embeddedAttributes = embeddableId.getAttributes();

                prepareEmbeddedIdFields(embeddedAttributes, metaModel, embeddedIdFields, doc, metadata);

                String entityId = doc.get(IndexingConstants.ENTITY_ID_FIELD);
                indexCol.put(entityId, embeddedIdFields);
            }
        }
        catch (Exception e)
        {
            log.error("Error while parsing Lucene Query {} ", e);
            throw new LuceneIndexingException(e);
        }
    }
1161864
@Override
    public void endMetaData(MetaData metadata)
    {
        for (Listener listener : this.listeners) {
            listener.endMetaData(metadata);
        }
    }
854768
public void init(Range annotation, PropertyMetadata propertyMetadata)
    {
        m_maxExclusive = getValue(annotation.maxExclusive());
        m_minExclusive = getValue(annotation.minExclusive());
        m_maxInclusive = getValue(annotation.maxInclusive());
        m_minInclusive = getValue(annotation.minInclusive());
        
        m_maxExclusiveMessage = annotation.maxExclusiveMessage();
        m_minExclusiveMessage = annotation.minExclusiveMessage();
        m_maxInclusiveMessage = annotation.maxInclusiveMessage();
        m_minInclusiveMessage = annotation.minInclusiveMessage();
        m_propertyMetadata = propertyMetadata;
    }
70729
public function getEmbeddedDiscriminatorValue(PropertyMetadata $mapping, $embeddedDocument)
    {
        if (!$mapping->embedded || get_class($embeddedDocument) !== $this->name) {
            throw new \InvalidArgumentException;
        }

        if ($mapping->targetDocument !== null) {
            return null;
        }

        $discriminatorMetadata = $this->getPropertyMetadata($mapping->discriminatorAttribute);
        $discriminatorValue    = $discriminatorMetadata->getValue($embeddedDocument);

        if ($discriminatorValue === null) {
            if ($discriminatorMetadata->discriminatorDefaultValue === null) {
                return null;
            }

            $discriminatorValue = $discriminatorMetadata->discriminatorDefaultValue;
        }

        if (isset($discriminatorMetadata->discriminatorMap[$discriminatorValue])) {
            return $discriminatorMetadata->discriminatorMap[$discriminatorValue];
        }

        return $discriminatorValue;
    }