Creates the Doctrine nested set node
@param EntityManager $em
@param object $entity
554477
private function createNestedSetNode(LifecycleEventArgs $args)
	{
		$entity = $args->getEntity();

		if ($entity instanceof EntityNodeInterface) {
			// Read entity data from the event arguments
			$em = $args->getEntityManager();
			
			// Find the repository
			$entityName = $entity->getNestedSetRepositoryClassName();
			$repository = $em->getRepository($entityName);
			
			// In case of refresh it already exists..
			$doctrineNode = $entity->getNestedSetNode();
			
			// .. create new if doesn't
			if ($doctrineNode === null) {
				// Initialize the doctrine nested set node
				$doctrineNode = new DoctrineNode($repository);
				$entity->setNestedSetNode($doctrineNode);
			}

			$doctrineNode->belongsTo($entity);
		}
	}
1017287
private function setEntityManager()
    {
        try {
            if ($this->_instance_options['em'] instanceof EntityManager) {
                $this->_em = $this->_instance_options['em'];
            } else {
                $this->_em = EntityManagerCreator::create($this->_instance_options['dbal'], $this->getLogger());
            }
        } catch (InvalidArgumentException $e) {
            throw new CacheException('DAO cache: enable to create a database conneciton', CacheException::INVALID_DB_CONNECTION, $e);
        }

        return $this;
    }
1137908
public function createOriginalEntity(EntityManagerInterface $em, $entity)
    {
        $uow      = $em->getUnitOfWork();
        $id_data  = $uow->isInIdentityMap($entity) ? $uow->getEntityIdentifier($entity) : [];
        $data     = $uow->getOriginalEntityData($entity);
        $metadata = $em->getClassMetadata(get_class($entity));
        $original = $metadata->newInstance();
        $fields   = array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());

        if (empty($data) && !empty($fields)) {
            return null;
        }

        foreach ($fields as $field) {
            if (isset($data[$field])) {
                $metadata->setFieldValue($original, $field, $data[$field]);
            } elseif (isset($id_data[$field]) && $metadata->isIdentifier($field) && $metadata->isIdGeneratorIdentity()) {
                $metadata->setFieldValue($original, $field, $id_data[$field]);
            } elseif ($metadata->isAssociationInverseSide($field)) {
                $metadata->setFieldValue($original, $field, $metadata->getFieldValue($entity, $field));
            }
        }

        return $original;
    }
906090
public function normalizeFromPost($entity, $target)
    {
        $key = $this->mapping['fieldname'];
        $accessor = 'get' . ucfirst($key);

        $outerCollection = $entity->$accessor();
        if ($outerCollection === null || $outerCollection instanceof Collections\Collection) {
            return null;
        }

        /** @var Collection\Taxonomy|Collection\Relations $collection */
        $collection = $this->em->createCollection($target);

        if (is_string($outerCollection)) {
            $outerCollection = [$outerCollection];
        }

        if (is_array($outerCollection)) {
            $related = [
                $key => $outerCollection,
            ];
            $collection->setFromPost($related, $entity);
        }

        return $collection;
    }
720178
public function generateEntityPageFromTemplate(BusinessTemplate $businessTemplate, $entity, EntityManager $em)
    {
        $page = new VirtualBusinessPage();
        $currentLocale = $businessTemplate->getCurrentLocale();

        $reflect = new \ReflectionClass($businessTemplate);
        $templateProperties = $reflect->getProperties();
        $accessor = PropertyAccess::createPropertyAccessor();

        foreach ($templateProperties as $property) {
            if (!in_array($property->getName(), ['id', 'widgetMap', 'slots', 'seo', 'i18n', 'widgets', 'translations', 'createdAt', 'updatedAt']) && !$property->isStatic()) {
                $value = $accessor->getValue($businessTemplate, $property->getName());
                $setMethod = 'set'.ucfirst($property->getName());
                if (method_exists($page, $setMethod)) {
                    $accessor->setValue($page, $property->getName(), $value);
                }
            }
        }

        //find Victoire\Bundle\BusinessEntityBundle\Entity\BusinessEntity object according to the given $entity
        $businessEntity = $this->businessEntityHelper->findByEntityInstance($entity);

        if ($businessEntity !== null) {
            //the business properties usable in a url
            $businessProperties = $this->getBusinessProperties($businessEntity);

            $entityProxy = $this->entityProxyProvider->getEntityProxy($entity, $businessEntity, $em);

            $page->setEntityProxy($entityProxy);
            $page->setTemplate($businessTemplate);
            /*
             * Returns class and parent's uses
             *
             * @param $class
             * @param bool $autoload
             * @return array
             */
            $class_uses_deep = function ($class, $autoload = true) {
                $traits = [];
                do {
                    $traits = array_merge(class_uses($class, $autoload), $traits);
                } while ($class = get_parent_class($class));
                foreach ($traits as $trait => $same) {
                    $traits = array_merge(class_uses($trait, $autoload), $traits);
                }

                return array_unique($traits);
            };

            $isTranslatableEntity = in_array(Translatable::class, $class_uses_deep($entity));
            foreach ($businessTemplate->getTranslations() as $translation) {
                if ($entity instanceof Article &&
                    !in_array($translation->getLocale(), $entity->getBlog()->getAvailableLocales())
                ) {
                    continue;
                }

                if ($isTranslatableEntity) {
                    $entity->setCurrentLocale($translation->getLocale());
                }
                $page->setCurrentLocale($translation->getLocale());
                $businessTemplate->setCurrentLocale($translation->getLocale());
                $page = $this->populatePage($page, $businessTemplate, $businessProperties, $em, $entity);
            }

            if ($isTranslatableEntity) {
                $entity->setCurrentLocale($currentLocale);
            }
            $page->setCurrentLocale($currentLocale);
            $businessTemplate->setCurrentLocale($currentLocale);

            if ($seo = $businessTemplate->getSeo()) {
                $pageSeo = clone $seo;
                $page->setSeo($pageSeo);
            }
        }

        return $page;
    }
478216
public function build(Entity $entity): void
    {
        $attributes = $entity->getEntityAttributes();

        // We will manually add a relationship for every attribute registered
        // of this entity. Once we know the relation method we have to use,
        // we will just add it to the entityAttributeRelations property.
        foreach ($attributes as $attribute) {
            $relation = $this->getRelationClosure($entity, $attribute);

            $entity->setEntityAttributeRelation($attribute->getAttribute('slug'), $relation);
        }
    }
487288
public Map<String, Object> createNodeProperties(Object entity, EntityMetadata m)
    {
        Map<String, Object> props = new HashMap<String, Object>();

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

        EntityType entityType = metaModel.entity(m.getEntityClazz());

        // Iterate over entity attributes
        Set<Attribute> attributes = entityType.getSingularAttributes();
        for (Attribute attribute : attributes)
        {
            Field field = (Field) attribute.getJavaMember();

            // Set Node level properties
            if (!attribute.isCollection() && !attribute.isAssociation())
            {

                String columnName = ((AbstractAttribute) attribute).getJPAColumnName();
                Object value = PropertyAccessorHelper.getObject(entity, field);
                if (value != null)
                {
                    props.put(columnName, toNeo4JProperty(value));
                }
            }
        }
        return props;
    }
270618
protected function createSubAggregate($entity, string $relation): self
    {
        // If root isn't defined, then this is the Aggregate Root
        $root = is_null($this->root) ? $this : $this->root;

        return new self($entity, $this, $relation, $root);
    }
225653
public function load(ObjectManager $em) {
    $bridge = new DoctrineBridge($em);
    $bridge->beginTransaction();

    $nodes = $this->convertNodes($this->example->toParentPointerArray(), $em);

    foreach($nodes as $node) {
      $bridge->persist($node);
    }

    $bridge->commit();
    $em->flush();
  }
400022
private function tableExists(EntityManager $em, $table)
    {
        return (Boolean) $em->createNativeQuery(
            'SHOW TABLE STATUS WHERE Name = :table', (new ResultSetMapping())->addScalarResult('Name', 'Name')
        )->setParameter(':table', $table)->getOneOrNullResult();
    }
258211
private function detachAndPersist($entity)
    {
        $this->em->detach($entity);
        $this->em->persist($entity);
    }
1275068
protected function buildCountQuery(EntityManager $em, Request $request)
	{
		$searchWords = preg_split('/[^[:alnum:]]+/', $request->getSearchText());
		$selects = array();
		foreach($this->databaseMapping as $tableMapping)
		{
			$score = $this->buildScoreColumn($tableMapping['columns'], count($searchWords));
			$joinsExpressions = $this->buildJoinExpressions($tableMapping['joins']);

			$selects[] = 'SELECT COUNT(*) '
					. 'FROM ' . $tableMapping['table'] . ' ' . $tableMapping['tableAlias'] . ' '
					. implode(' ', $joinsExpressions) . ' '
					. 'WHERE ' . $score['expression'] . '<>0 '
			;
		}
		$bigSelect = 'SELECT (' . implode(')+(', $selects) . ')';
		$stmt = $em->getConnection()->prepare($bigSelect);
		foreach($searchWords as $key => $searchWord)
		{
			$stmt->bindValue('p' . $key, $searchWord);
		}
		return $stmt;
	}
1265838
public function buildRelationshipEntityMetadata(\SimpleXMLElement $node, $className)
    {
        if (!isset($node->{'start-node'}) || !isset($node->{'end-node'})) {
            throw new MappingException(
                sprintf('Class "%s" OGM XML configuration is missing "start-node" or "end-node" attributes', $className)
            );
        }

        $startNode = $node->{'start-node'};
        if (!isset($startNode['name']) || !isset($startNode['target-entity'])) {
            throw new MappingException(
                sprintf('Class "%s" OGM XML start-node configuration is missing mandatory attributes', $className)
            );
        }
        $startNodeKey = (string) $startNode['name'];
        $startNodeClass = ClassUtils::getFullClassName((string) $startNode['target-entity'], $className);

        $endNode = $node->{'end-node'};
        if (!isset($endNode['name']) || !isset($endNode['target-entity'])) {
            throw new MappingException(
                sprintf('Class "%s" OGM XML end-node configuration is missing mandatory attributes', $className)
            );
        }
        $endNodeKey = (string) $endNode['name'];
        $endNodeClass = ClassUtils::getFullClassName((string) $endNode['target-entity'], $className);

        $reflection = new \ReflectionClass($className);

        return new RelationshipEntityMetadata(
            $className,
            $reflection,
            $this->buildRelationshipMetadata($node, $className),
            $this->idXmlMetadataFactory->buildEntityIdMetadata($node, $className, $reflection),
            $startNodeClass,
            $startNodeKey,
            $endNodeClass,
            $endNodeKey,
            $this->propertyXmlMetadataFactory->buildPropertiesMetadata($node, $className, $reflection)
        );
    }
31457
public function setEntitiesAttribute($entities): void
    {
        static::saved(function ($model) use ($entities) {
            $this->entities()->delete();
            ! $entities || $this->entities()->createMany(array_map(function ($entity) {
                return ['entity_type' => $entity];
            }, $entities));
        });
    }
982528
public static function createHelperSet(EntityManagerInterface $entityManager) : HelperSet
    {
        return new HelperSet(
            [
                'db' => new DBALConsole\Helper\ConnectionHelper($entityManager->getConnection()),
                'em' => new EntityManagerHelper($entityManager),
            ]
        );
    }
49137
protected function _setChildrenLevel($entity)
    {
        $config = $this->getConfig();

        if ($entity->get($config['left']) + 1 === $entity->get($config['right'])) {
            return;
        }

        $primaryKey = $this->_getPrimaryKey();
        $primaryKeyValue = $entity->get($primaryKey);
        $depths = [$primaryKeyValue => $entity->get($config['level'])];

        $children = $this->_table->find('children', [
            'for' => $primaryKeyValue,
            'fields' => [$this->_getPrimaryKey(), $config['parent'], $config['level']],
            'order' => $config['left'],
        ]);

        /* @var \Cake\Datasource\EntityInterface $node */
        foreach ($children as $node) {
            $parentIdValue = $node->get($config['parent']);
            $depth = $depths[$parentIdValue] + 1;
            $depths[$node->get($primaryKey)] = $depth;

            $this->_table->updateAll(
                [$config['level'] => $depth],
                [$primaryKey => $node->get($primaryKey)]
            );
        }
    }
484570
public function setEntity(Entity $entity)
    {
        /** @var SharedEventManager $events */
        $events = $this->getContainer()->get('sharedEventManager');
        $name = $entity->getClassName();
        $events->attach(
            $name,
            Delete::BEFORE_DELETE,
            [$this, 'beforeDelete']
        );
        $events->attach(
            $name,
            Save::AFTER_SAVE,
            [$this, 'afterSave']
        );
        $this->getContainer()->set('sharedEventManager', $events);
        return parent::setEntity($entity);
    }