Initialize.

@param entityMetadata
the entity metadata
@return the map
4061
private Map<String, Object> initialize(EntityMetadata entityMetadata)
    {
        Map<String, Object> relationMap = null;
        if (entityMetadata.getRelationNames() != null && !entityMetadata.getRelationNames().isEmpty())
        {
            relationMap = new HashMap<String, Object>();
        }
        return relationMap;
    }
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);
  }
752410
public void addEntityMetadata(Class<?> clazz, EntityMetadata entityMetadata)
    {
        getEntityMetadataMap().put(clazz.getName(), entityMetadata);
    }
1149565
@java.lang.Deprecated
  public java.util.Map<java.lang.String, java.lang.String> getMetadata() {
    return getMetadataMap();
  }
942745
private MapObject populateRmap(EntityMetadata entityMetadata, Object entity)
    {
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                .getMetamodel(entityMetadata.getPersistenceUnit());
        Class entityClazz = entityMetadata.getEntityClazz();
        EntityType entityType = metaModel.entity(entityClazz);
        Set<Attribute> attributes = entityType.getAttributes();
        Iterator<Attribute> iterator = attributes.iterator();
        return iterateAndPopulateRmap(entity, metaModel, iterator);
    }
770194
public static void populateColumnAndSuperColumnMaps(EntityMetadata m, Map<String, Field> columnNameToFieldMap,
            Map<String, Field> superColumnNameToFieldMap, final KunderaMetadata kunderaMetadata)
    {

        getEmbeddableType(m, columnNameToFieldMap, superColumnNameToFieldMap, kunderaMetadata);
    }
239572
private static String initRemoveEntityQuery(EntityKeyMetadata entityKeyMetadata) {
		StringBuilder queryBuilder = new StringBuilder( "MATCH " );
		appendEntityNode( "n", entityKeyMetadata, queryBuilder );
		queryBuilder.append( " OPTIONAL MATCH (n)-[r]->(e:EMBEDDED), path=(e)-[*0..]->(:EMBEDDED) " );
		queryBuilder.append( " DELETE r " );
		queryBuilder.append( " FOREACH (er IN relationships(path) | DELETE er) " );
		queryBuilder.append( " FOREACH (en IN nodes(path) | DELETE en) " );
		queryBuilder.append( " WITH n " );
		queryBuilder.append( " OPTIONAL MATCH (n)-[r]-() " );
		queryBuilder.append( " DELETE r,n " );
		return queryBuilder.toString();
	}
309487
public static Map<String, Field> createSuperColumnsFieldMap(final EntityMetadata m,
            final KunderaMetadata kunderaMetadata)
    {
        Map<String, Field> superColumnNameToFieldMap = new HashMap<String, Field>();
        getEmbeddableType(m, null, superColumnNameToFieldMap, kunderaMetadata);
        return superColumnNameToFieldMap;
    }
789064
public void setCreatedTimestampMetadata(PropertyMetadata createdTimestampMetadata) {
    if (this.createdTimestampMetadata != null) {
      throwDuplicateAnnotationException(entityClass, CreatedTimestamp.class,
          this.createdTimestampMetadata, createdTimestampMetadata);
    }
    this.createdTimestampMetadata = createdTimestampMetadata;
  }
1177
public EventDetails withEventMetadata(java.util.Map<String, String> eventMetadata) {
        setEventMetadata(eventMetadata);
        return this;
    }
598876
private function createInitializer(ClassMetadata $classMetadata)
    {
        $className = $classMetadata->getName();
        $documentManager = $this->documentManager;

        if ($classMetadata->getReflectionClass()->hasMethod('__wakeup')) {
            return function (Proxy $proxy) use ($className, $documentManager) {
                $proxy->__setInitializer(null);
                $proxy->__setCloner(null);

                if ($proxy->__isInitialized()) {
                    return;
                }

                $properties = $proxy->__getLazyProperties();

                foreach ($properties as $propertyName => $property) {
                    if (!isset($proxy->$propertyName)) {
                        $proxy->$propertyName = $properties[$propertyName];
                    }
                }

                $proxy->__setInitialized(true);
                $proxy->__wakeup();
                $documentManager->getRepository($className)->refreshDocumentForProxy($proxy);
            };
        }

        return function (Proxy $proxy) use ($className, $documentManager) {
            $proxy->__setInitializer(null);
            $proxy->__setCloner(null);

            if ($proxy->__isInitialized()) {
                return;
            }

            $properties = $proxy->__getLazyProperties();

            foreach ($properties as $propertyName => $property) {
                if (!isset($proxy->$propertyName)) {
                    $proxy->$propertyName = $properties[$propertyName];
                }
            }

            $proxy->__setInitialized(true);
            $documentManager->getRepository($className)->refreshDocumentForProxy($proxy);
        };
    }
87711
private EntityMetadata getMetadata(Class<?> clazz)
    {
        EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, clazz);
        if (metadata == null)
        {
            log.error("Entity metadata not found for {}, possible reasons may be: "
                    + "1) not annotated with @Entity. 2) is annotated with @MappedSuperclass."
                    + "3) does not properly with mapped persistence unit for persistence unit and keyspace. Please verify with @Table annotation or persistence.xml "
                    + clazz);
            throw new KunderaException("Entity metadata not found for " + clazz.getName());
        }
        return metadata;
    }
636960
public static MetamodelImpl getMetamodel(final KunderaMetadata kunderaMetadata, String... persistenceUnits)
    {
        MetamodelImpl metamodel = null;
        for (String pu : persistenceUnits)
        {
            metamodel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(pu);

            if (metamodel != null)
            {
                return metamodel;
            }
        }

        // FIXME: I need to verify this why we need common entity metadata now!
        // if (metamodel == null)
        // {
        // metamodel = (MetamodelImpl)
        // kunderaMetadata.getApplicationMetadata().getMetamodel(
        // Constants.COMMON_ENTITY_METADATAS);
        // }
        return metamodel;
    }
231268
private static String initUpdateEmbeddedNodeQuery(EntityKeyMetadata entityKeyMetadata) {
		StringBuilder queryBuilder = new StringBuilder( "MERGE " );
		appendEntityNode( "owner", entityKeyMetadata, queryBuilder );
		queryBuilder.append( " MERGE (owner)" );
		return queryBuilder.toString();
	}
448576
private Map<String, Object> getEntityAsMap(
      Entity entity,
      EntityType meta,
      Set<String> attributesSet,
      Map<String, Set<String>> attributeExpandsSet) {
    if (null == entity) throw new IllegalArgumentException("entity is null");

    if (null == meta) throw new IllegalArgumentException("meta is null");

    Map<String, Object> entityMap = new LinkedHashMap<>();
    entityMap.put("href", UriUtils.createEntityUriPath(meta.getId(), entity.getIdValue()));

    for (Attribute attr : meta.getAtomicAttributes()) {
      // filter fields
      if (attributesSet != null && !attributesSet.contains(attr.getName().toLowerCase())) continue;

      String attrName = attr.getName();
      AttributeType attrType = attr.getDataType();

      if (attrType == COMPOUND) {
        if (attributeExpandsSet != null
            && attributeExpandsSet.containsKey(attrName.toLowerCase())) {
          Set<String> subAttributesSet = attributeExpandsSet.get(attrName.toLowerCase());
          entityMap.put(
              attrName,
              new AttributeResponse(
                  meta.getId(),
                  meta,
                  attr,
                  subAttributesSet,
                  null,
                  permissionService,
                  dataService));
        } else {
          entityMap.put(
              attrName,
              Collections.singletonMap(
                  "href",
                  UriUtils.createEntityAttributeUriPath(
                      meta.getId(), entity.getIdValue(), attrName)));
        }
      } else if (attrType == DATE) {
        LocalDate date = entity.getLocalDate(attrName);
        entityMap.put(attrName, date != null ? date.toString() : null);
      } else if (attrType == DATE_TIME) {
        Instant date = entity.getInstant(attrName);
        entityMap.put(attrName, date != null ? date.toString() : null);
      } else if (attrType != XREF
          && attrType != CATEGORICAL
          && attrType != MREF
          && attrType != CATEGORICAL_MREF
          && attrType != ONE_TO_MANY
          && attrType != FILE) {
        entityMap.put(attrName, entity.get(attr.getName()));
      } else if ((attrType == XREF || attrType == CATEGORICAL || attrType == FILE)
          && attributeExpandsSet != null
          && attributeExpandsSet.containsKey(attrName.toLowerCase())) {
        Entity refEntity = entity.getEntity(attr.getName());
        if (refEntity != null) {
          Set<String> subAttributesSet = attributeExpandsSet.get(attrName.toLowerCase());
          EntityType refEntityType = dataService.getEntityType(attr.getRefEntity().getId());
          Map<String, Object> refEntityMap =
              getEntityAsMap(refEntity, refEntityType, subAttributesSet, null);
          entityMap.put(attrName, refEntityMap);
        }
      } else if ((attrType == MREF || attrType == CATEGORICAL_MREF || attrType == ONE_TO_MANY)
          && attributeExpandsSet != null
          && attributeExpandsSet.containsKey(attrName.toLowerCase())) {
        EntityType refEntityType = dataService.getEntityType(attr.getRefEntity().getId());
        Iterable<Entity> mrefEntities = entity.getEntities(attr.getName());

        Set<String> subAttributesSet = attributeExpandsSet.get(attrName.toLowerCase());
        List<Map<String, Object>> refEntityMaps = new ArrayList<>();
        for (Entity refEntity : mrefEntities) {
          Map<String, Object> refEntityMap =
              getEntityAsMap(refEntity, refEntityType, subAttributesSet, null);
          refEntityMaps.add(refEntityMap);
        }

        EntityPager pager =
            new EntityPager(
                0,
                new EntityCollectionRequest().getNum(),
                (long) refEntityMaps.size(),
                mrefEntities);

        EntityCollectionResponse ecr =
            new EntityCollectionResponse(
                pager,
                refEntityMaps,
                UriUtils.createEntityAttributeUriPath(meta.getId(), entity.getIdValue(), attrName),
                null,
                permissionService,
                dataService);

        entityMap.put(attrName, ecr);
      } else if ((attrType == XREF && entity.get(attr.getName()) != null)
          || (attrType == CATEGORICAL && entity.get(attr.getName()) != null)
          || (attrType == FILE && entity.get(attr.getName()) != null)
          || attrType == MREF
          || attrType == CATEGORICAL_MREF
          || attrType == ONE_TO_MANY) {
        // Add href to ref field
        Map<String, String> ref = new LinkedHashMap<>();
        ref.put(
            "href",
            UriUtils.createEntityAttributeUriPath(meta.getId(), entity.getIdValue(), attrName));
        entityMap.put(attrName, ref);
      }
    }

    return entityMap;
  }
16914
@Override
    public void initialize(Map<String, Object> puProperties)
    {
        reader = new RethinkDBEntityReader(kunderaMetadata);
        setExternalProperties(puProperties);
        initializePropertyReader();
        PersistenceUnitMetadata pum = kunderaMetadata.getApplicationMetadata()
                .getPersistenceUnitMetadata(getPersistenceUnit());

        Properties pumProps = pum.getProperties();

        if (puProperties != null)
        {
            pumProps.putAll(puProperties);
        }

        String host = pumProps.getProperty("kundera.nodes");
        String port = pumProps.getProperty("kundera.port");

        if (host == null || port == null)
        {
            throw new KunderaException("Hostname/IP or Port is null.");
        }

        connection = r.connection().hostname(host).port(Integer.parseInt(port)).connect();

    }
927016
@Override
    public void configure()
    {
        log.debug("Loading Entity Metadata...");
        ApplicationMetadata appMetadata = kunderaMetadata.getApplicationMetadata();

        for (String persistenceUnit : persistenceUnits)
        {
            if (appMetadata.getMetamodelMap().get(persistenceUnit.trim()) != null)
            {
                if (log.isDebugEnabled())
                {
                    log.debug("Metadata already exists for the Persistence Unit " + persistenceUnit + ". Nothing to do");
                }
            }
            else
            {
                loadEntityMetadata(persistenceUnit);
            }
        }
    }