Completes the ID generator mapping. If "auto" is specified we choose the generator
most appropriate for the targeted database platform.

@throws ORMException
977697
private function completeIdentifierGeneratorMappings(ClassMetadata $class) : void
    {
        foreach ($class->getDeclaredPropertiesIterator() as $property) {
            if (! $property instanceof FieldMetadata /*&& ! $property instanceof AssocationMetadata*/) {
                continue;
            }

            $this->completeFieldIdentifierGeneratorMapping($property);
        }
    }
1360026
private function verifyConfig()
    {
        foreach (Config::KEYS as $key) {
            if (!isset(Config::get()[$key])) {
                throw new OrmException('Key "'.$key.'" is not given.');
            }
        }
    }
1219031
public function afterFind()
    {
        parent::afterFind();
        static::$propertyIdToKey[$this->id] = $this->key;
        static::$identityMap[$this->id] = $this;

        // cast scalar values
        $this->allow_multiple_values = (bool) $this->allow_multiple_values;
        $this->is_internal = (bool) $this->is_internal;
        $this->data_type = (int) $this->data_type;
        $this->property_handler_id = (int) $this->property_handler_id;
    }
1183207
protected function autoWiringId(
        /*# string */ $id,
        /*# bool */ $withAutowiring
    )/*# : bool */ {
        if ($withAutowiring && class_exists($id)) {
            $this->add($id);
            return true;
        }
        return false;
    }
155396
protected function mapAutoIDs(array $arr_auto_id_requested)
    {
        if (!empty($arr_auto_id_requested)) {
            $arr_auto_ids = $this->extractAutoIDs();
            if(count($arr_auto_id_requested) === count($arr_auto_ids)) {
                foreach ($arr_auto_id_requested as $int_idx => $obj_gds_entity) {
                    $obj_gds_entity->setKeyId($arr_auto_ids[$int_idx]);
                }
            } else {
                throw new \Exception("Mismatch count of requested & returned Auto IDs");
            }
        }
    }
202143
public void setGenerator(final IdGenerator generator) {
        if (generator != null) {
            this.idGenerator = generator;
            swidTag.setId(idGenerator.nextId());
        }
    }
365811
public function generateDeleteModel()
    {
        $newModelKeys = array_merge(
            $this->newModelKeys,
            $this->newUnmanagedKeys
        );
        $deletedModels = array_diff($this->oldModelKeys, $newModelKeys);
        $deletedUnmanagedModels = array_diff(
            $this->oldUnmanagedKeys,
            $newModelKeys
        );
        $allDeletedModels = array_merge(
            $deletedModels,
            $deletedUnmanagedModels
        );

        /* @var $modelState ModelState */
        foreach ($allDeletedModels as $deletedModel) {
            $modelState = $this->fromState->getModelState($deletedModel);
            $meta = $this->oldRegistry
                ->getModel($deletedModel)->getMeta();

            // at this point if we the model is un manged just stop ,
            // since we just need to have it recorded in our
            // migrations, we don't need to create the relationship fields also,
            // its not our problem anymore
            if (!$meta->managed) {
                continue;
            }

            $localFields = $meta->localFields;
            $localM2MFields = $meta->localManyToMany;

            $relatedFields = [];

            // get all the relationship fields that we initiated since they
            // will need to be created on there own  operations aside from
            //  the one that creates the model
            // remember the model needs to exist first before enforcing the
            // relationships.

            /** @var $localField Field */
            foreach ($localFields as $localField) {
                if ($localField->relation && $localField->relation->toModel) {
                    $relatedFields[$localField->getName()] = $localField;
                }
            }

            /** @var $localM2MField Field */
            foreach ($localM2MFields as $localM2MField) {
                if ($localField->relation && $localField->relation->toModel) {
                    $relatedFields[$localM2MField->getName()] = $localM2MField;
                }
            }

            // take care of relationships
            foreach ($relatedFields as $fieldName => $relationField) {
                //remove the operation
                $this->addOperation(
                    $meta->getAppName(),
                    RemoveField::createObject(
                        [
                            'modelName' => $deletedModel,
                            'name' => $fieldName,
                        ]
                    )
                );
            }

            $opDep = [];

            // we also need to drop all relationship fields that point to us,
            // initiated by other models.
            $reverseRelatedFields = $meta->getReverseRelatedObjects();

            /** @var $reverseRelatedField RelatedField */
            foreach ($reverseRelatedFields as $reverseRelatedField) {
                $modelName = $reverseRelatedField
                    ->relation->getFromModel()->getMeta()->getNSModelName();
                $fieldName = $reverseRelatedField->relation->fromField->getName();
                $opDep[] = [
                    'target' => $fieldName,
                    'model' => $modelName,
                    'type' => self::TYPE_FIELD,
                    'action' => self::ACTION_DROPPED,
                ];
                if (!$reverseRelatedField->relation->isManyToMany()) {
                    $opDep[] = [
                        'app' => $reverseRelatedField->relation
                            ->getFromModel()->getMeta()->getAppName(),
                        'target' => $fieldName,
                        'model' => $modelName,
                        'type' => self::TYPE_FIELD,
                        'action' => self::ACTION_ALTER,
                    ];
                }
            }

            // finally remove the model
            $this->addOperation(
                $meta->getAppName(),
                DeleteModel::createObject(['name' => $modelState->name]),
                $opDep
            );
        }
    }
571207
public function triggerReindex()
    {
        if (!$this->owner->ID) {
            return;
        }

        $id = $this->owner->ID;
        $class = $this->owner->ClassName;
        $state = SearchVariant::current_state($class);
        $base = DataObject::getSchema()->baseDataClass($class);
        $key = "$id:$base:" . serialize($state);

        $statefulids = array(array(
            'id' => $id,
            'state' => $state
        ));

        $writes = array(
            $key => array(
                'base' => $base,
                'class' => $class,
                'id' => $id,
                'statefulids' => $statefulids,
                'fields' => array()
            )
        );

        SearchUpdater::process_writes($writes);
    }
479048
public function setID($id)
    {
        /*
         * TODO validate/tokenize the actual ID
         */
        if (empty((string) $id)) {
            throw new ConfigurationException(
                'The configuration must specify a non-empty (and globally unique) ID for the Tool Provider.',
                ConfigurationException::TOOL_PROVIDER
            );
        } else {
            $this->id = (string) $id;
        }
    }
1188087
public function registerAutoloader()
    {
        $this->app->afterResolving(DocumentManagerRegistry::class, function (ManagerRegistryInterface $registry) {
            /** @var DocumentManager $manager */
            foreach ($registry->getManagers() as $manager) {
                Autoloader::register(
                    $manager->getConfiguration()->getProxyDir(),
                    $manager->getConfiguration()->getProxyNamespace()
                );

            }
        });
    }
24998
@Inject
	public void guiceSetupComplete()
	{
		// Force us to re-register with guice-supplied values
		this.registered = false;

		// Normally guice would call this but we must call it manually because the object was created manually
		postConstruct();

		if (onGuiceTakeover != null)
		{
			onGuiceTakeover.run();

			onGuiceTakeover = null;
		}
	}
815216
public static boolean onAutoGenerateId(Field idField, Object idValue)
    {
        if (idField.isAnnotationPresent(GeneratedValue.class))
        {
            return !isIdSet(idValue, idField);
        }

        return false;
    }
1063260
protected void configureGeneratedIdSequence(StringBuilder sb, FieldType fieldType, List<String> statementsBefore,
			List<String> additionalArgs, List<String> queriesAfter) throws SQLException {
		throw new SQLException(
				"GeneratedIdSequence is not supported by database " + getDatabaseName() + " for field " + fieldType);
	}
656108
public void autoRegisterNodes() {
        // if java did atomic blocks, this would be one
        synchronized (this) {
            if (autoRegistrationRunning || autoRegistrationComplete) {
                // registration already done or in process, abort
                return;
            }
        }
        autoRegistrationRunning = true;
        try {
            callAutoRegisterMethods(getClass());
        } finally {
            autoRegistrationComplete = true;
            autoRegistrationRunning = false;
        }
    }
1230710
public function commit()
    {
        try {
            $this->connection->commit();
        } catch (DBALException $e) {
            throw new OrmException("Unable to commit changes.\n" . $e->getMessage(), 0, $e);
        }
    }
111247
private function completeDefinition($id, Definition $definition)
    {
        if (!$reflectionClass = $this->getReflectionClass($id, $definition)) {
            return;
        }

        if ($this->container->isTrackingResources()) {
            $this->container->addResource(static::createResourceForClass($reflectionClass));
        }

        if (!$constructor = $reflectionClass->getConstructor()) {
            return;
        }

        $arguments = $definition->getArguments();
        foreach ($constructor->getParameters() as $index => $parameter) {
            if (array_key_exists($index, $arguments) && '' !== $arguments[$index]) {
                continue;
            }

            try {
                if (!$typeHint = $parameter->getClass()) {
                    // no default value? Then fail
                    if (!$parameter->isOptional()) {
                        throw new RuntimeException(sprintf('Unable to autowire argument index %d ($%s) for the service "%s". If this is an object, give it a type-hint. Otherwise, specify this argument\'s value explicitly.', $index, $parameter->name, $id));
                    }

                    if (!array_key_exists($index, $arguments)) {
                        // specifically pass the default value
                        $arguments[$index] = $parameter->getDefaultValue();
                    }

                    continue;
                }

                if (null === $this->types) {
                    $this->populateAvailableTypes();
                }

                if (isset($this->types[$typeHint->name])) {
                    $value = new Reference($this->types[$typeHint->name]);
                } else {
                    try {
                        $value = $this->createAutowiredDefinition($typeHint, $id);
                    } catch (RuntimeException $e) {
                        if ($parameter->allowsNull()) {
                            $value = null;
                        } elseif ($parameter->isDefaultValueAvailable()) {
                            $value = $parameter->getDefaultValue();
                        } else {
                            throw $e;
                        }
                    }
                }
            } catch (\ReflectionException $e) {
                // Typehint against a non-existing class

                if (!$parameter->isDefaultValueAvailable()) {
                    throw new RuntimeException(sprintf('Cannot autowire argument %s for %s because the type-hinted class does not exist (%s).', $index + 1, $definition->getClass(), $e->getMessage()), 0, $e);
                }

                $value = $parameter->getDefaultValue();
            }

            $arguments[$index] = $value;
        }

        // it's possible index 1 was set, then index 0, then 2, etc
        // make sure that we re-order so they're injected as expected
        ksort($arguments);
        $definition->setArguments($arguments);
    }
733534
protected function shouldRegenerateId()
    {
        if (($this->idRequestsLimit) && ($this->requestsCount >= $this->idRequestsLimit)) {
            return true;
        }

        if (($this->idTtl && $this->regenerationTrace) && ($this->regenerationTrace + $this->idTtl < time())) {
            return true;
        }

        return false;
    }