Cast the identifier.

@param ClassMetadata $targetEntity The target entity
@param Connection    $connection   The doctrine connection

@return string
334912
public static function castIdentifier(ClassMetadata $targetEntity, Connection $connection)
    {
        if (!isset(self::$cacheCastIdentifiers[$targetEntity->getName()])) {
            $cast = '';

            if ($connection->getDriver() instanceof PgSqlDriver) {
                $type = self::getIdentifierType($targetEntity);
                $cast = '::'.$type->getSQLDeclaration(
                    $targetEntity->getIdentifierFieldNames(),
                    $connection->getDatabasePlatform()
                );
            }

            self::$cacheCastIdentifiers[$targetEntity->getName()] = $cast;
        }

        return self::$cacheCastIdentifiers[$targetEntity->getName()];
    }
696424
public static function select(Connection $connection)
    {
        return new EntitySelector(AbstractSelector::fromConnection($connection, static::$table, static::$types), get_called_class());
    }
491391
public function getRelatedResourceReference(
        ResourceSet $sourceResourceSet,
        $sourceEntityInstance,
        ResourceSet $targetResourceSet,
        ResourceProperty $targetProperty
    ) {
        $entityClassName = $targetResourceSet->getResourceType()->getInstanceType()->name;
        $entityName = $this->getEntityName($entityClassName);
        $fieldName = $this->getTableName($entityName) . '_id';

        return $this->getResource($targetResourceSet, null, [
            'id' => $sourceEntityInstance->$fieldName
        ]);
    }
961994
public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
    {
        return [
            '__identity' => $this->persistenceManager->getIdentifierByObject($source),
            '__type' => TypeHandling::getTypeForValue($source)
        ];
    }
835748
private function updateEntity($entity)
    {
        $change = false;

        $propertyAccessor = PropertyAccess::createPropertyAccessor();
        $targetProperty = $propertyAccessor->getValue($entity, $this->targetProperty);

        // if entity state is still proxy, we try to load its entity to make sure that target property is correct
        if($entity instanceof Proxy && $targetProperty === null) {
            $this->loadEntity($entity);
            $targetProperty = $propertyAccessor->getValue($entity, $this->targetProperty);
        }

        if($targetProperty) {
            // update id property
            $idProperty = $propertyAccessor->getValue($entity, $this->idProperty);
            $id = $propertyAccessor->getValue($targetProperty, 'id');
            if($idProperty != $id) {
                $propertyAccessor->setValue($entity, $this->idProperty, $id);
                $change = true;
            }

            // update class property
            $classProperty = $propertyAccessor->getValue($entity, $this->classProperty);
            $class = $this->targetClassResolver->resolveClass($targetProperty);
            if($classProperty != $class) {
                $propertyAccessor->setValue($entity, $this->classProperty, $class);
                $change = true;
            }
        } else {
            if(null !== $propertyAccessor->getValue($entity, $this->idProperty)) {
                $propertyAccessor->setValue($entity, $this->idProperty, null);
                $change = true;
            }

            if(null !== $propertyAccessor->getValue($entity, $this->classProperty)) {
                $propertyAccessor->setValue($entity, $this->classProperty, null);
                $change = true;
            }
        }

        return $change;
    }
855165
public function load(Connection $connection, array $primaryValues)
    {
        $targetAdapter = $connection->getAdapter($this->targetReflection->getAdapterName());

        if ($this->dominant) {

            $currentAdapter = $connection->getAdapter(
                $this->sourceReflection->getAdapterName()
            );
        } else{
            $currentAdapter = $targetAdapter;
        }

        $joinQuery = $currentAdapter->createSelect(
            $this->joinResource,
            [$this->joinKey, $this->referencingKey]
        );
        $joinQuery->setFilter(
            [$this->joinKey => [Filter::EQUAL => $primaryValues]]
        );

        $joinResult = $currentAdapter->execute($joinQuery);

        if (!$joinResult) {
            return [];
        }

        $joinResult = Association::groupResult(
            $joinResult,
            [$this->referencingKey, $this->joinKey]
        );

        $targetQuery = $targetAdapter->createSelect(
            $this->targetReflection->getAdapterResource()
        );
        $targetQuery->setFilter(
            [
                $this->targetReflection->getPrimaryProperty()->getUnmapped() => [
                    Entity\Filter::EQUAL => array_keys($joinResult)
                ]
            ]
        );

        $targetResult = $targetAdapter->execute($targetQuery);
        if (!$targetResult) {
            return [];
        }

        $targetResult = Association::groupResult(
            $targetResult,
            [$this->targetReflection->getPrimaryProperty()->getUnmapped()]
        );

        $result = [];
        foreach ($joinResult as $targetKey => $join) {

            foreach ($join as $originKey => $data) {
                if (!isset($targetResult[$targetKey])) {
                    throw new AssociationException(
                        "Can not merge associated result key '" . $targetKey
                        . "' not found in result from '"
                        . $this->targetReflection->getAdapterResource()
                        . "'! Maybe wrong value in join resource."
                    );
                }
                $result[$originKey][] = $targetResult[$targetKey];
            }
        }

        return $result;
    }
270629
public function initConnection(Connection $connection)
    {
        /** @var $pdo PDO */
        $pdo = $connection->getWrappedConnection();
        $this->fkSupported = version_compare('3.6.19', $pdo->getAttribute(PDO::ATTR_SERVER_VERSION)) < 0;
        $pdo->exec($this->buildEnableForeignKeysQuery());
    }
409773
public function getPresenceVerifierFor($connection)
    {
        return tap($this->getPresenceVerifier(), function ($verifier) use ($connection) {
            $verifier->setConnection($connection);
        });
    }
143261
protected function identifyUser(ConnectionInterface $connection, WriteStream $writeStream)
    {
        $password = $connection->getPassword();
        if ($password) {
            $writeStream->ircPass($password);
        }

        $writeStream->ircUser(
            $connection->getUsername(),
            $connection->getHostname(),
            $connection->getServername(),
            $connection->getRealname()
        );

        $writeStream->ircNick($connection->getNickname());
    }
163252
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
    {
        $class = $targetEntity->getName();

        if (\count($this->enabled) && !(\array_key_exists($class, $this->enabled) && true === $this->enabled[$class])) {
            return '';
        }

        if (\array_key_exists($class, $this->disabled) && true === $this->disabled[$class]) {
            return '';
        }

        if (\array_key_exists($targetEntity->rootEntityName, $this->disabled) && true === $this->disabled[$targetEntity->rootEntityName]) {
            return '';
        }

        $em = $this->getEntityManager();

        $config = $this->getListener()->getConfiguration($em, $targetEntity->name);

        if (!isset($config['softDeleteable']) || !$config['softDeleteable']) {
            return '';
        }

        /** @var \Doctrine\DBAL\Connection $conn */
        $conn = $em->getConnection();

        $platform = $conn->getDatabasePlatform();

        $quoteStrategy = $em->getConfiguration()->getQuoteStrategy();

        $column = $quoteStrategy->getColumnName($config['fieldName'], $targetEntity, $platform);

        $addCondSql = $platform->getIsNotNullExpression($targetTableAlias . '.' . $column);

        if (!empty($config['timeAware'])) {
            $now = $conn->quote(date('Y-m-d H:i:s')); // should use UTC in database and PHP
            $addCondSql = "({$addCondSql} OR {$targetTableAlias}.{$column} > {$now})";
        }

        return $addCondSql;
    }
813448
public function getIdentifierPhp($columnValueMutator, $connectionVariableName = '$con', $sequenceName = '', $tab = "			")
    {
        return sprintf(
            "
%s%s = %s->lastInsertId(%s);",
            $tab,
            $columnValueMutator,
            $connectionVariableName,
            $sequenceName ? ("'" . $sequenceName . "'") : ''
        );
    }
1207740
public function buildEntityIdMetadata(\SimpleXMLElement $node, $className, \ReflectionClass $reflection)
    {
        if (!isset($node->id) || !isset($node->id['name'])) {
            throw new MappingException(
                sprintf('Class "%s" OGM XML configuration has invalid or missing "id" element', $className)
            );
        }

        return new EntityIdMetadata(
            (string) $node->id['name'],
            $reflection->getProperty((string) $node->id['name']),
            new IdAnnotationMetadata()
        );
    }
379586
protected function handle(Connection $connection, $request)
    {
        $this->loadSession($connection);
        
        return $this->Kernel->handle($request);
    }
397216
private function getEntityId($entity, $entityClass)
    {
        $ids = $this->em->getClassMetadata($entityClass)->getIdentifierValues($entity);

        return reset($ids);
    }
321865
public function saveChanges($primaryValue, Connection $connection, Collection $collection)
    {
        if ($collection->getEntityClass() !== $this->targetReflection->getClassName()) {
            throw new AssociationException(
                "Input collection should be type of "
                . $this->targetReflection->getClassName()
                . " but type of " . $collection->getEntityClass() . " given!"
            );
        }

        $changes = array_filter($collection->getChanges());
        if (empty($changes)) {
            return;
        }

        $sourceAdapter = $connection->getAdapter($this->sourceReflection->getAdapterName());
        $targetAdapter = $connection->getAdapter($this->targetReflection->getAdapterName());
        $mapper = $connection->getMapper();

        if (!$this->dominant) {
            $sourceAdapter = $targetAdapter;
        }

        // Unmap primary value
        $primaryValue = $mapper->unmapValue(
            $this->sourceReflection->getPrimaryProperty(),
            $primaryValue
        );

        $this->_saveAdd(
            $primaryValue,
            $sourceAdapter,
            $targetAdapter,
            $collection->getChanges(),
            $mapper
        );

        $this->_saveRemove(
            $primaryValue,
            $sourceAdapter,
            $targetAdapter,
            $collection->getChanges(),
            $mapper
        );
    }
1187153
public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
    {
        if (is_array($source)) {
            $result = [];
            /** @var NodeInterface $node */
            foreach ($source as $node) {
                $result[] = $node->getIdentifier();
            }
        } else {
            if ($source instanceof NodeInterface) {
                $result = $source->getIdentifier();
            } else {
                $result = '';
            }
        }

        return $result;
    }
104766
public static function mergeArrayIntoEntity($targetEntity, $array)
    {
        foreach ($array as $property => $value) {
            if (!empty($value)) {
                if (is_a($targetEntity->{'get' . ucfirst($property)}(),
                    '\\TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage')
                ) {
                    $targetEntity->{'set' . ucfirst($property)}(new ObjectStorage());
                    if (is_array($value)) {
                        $singular = (preg_match('~s$~i', $property) > 0) ? rtrim($property, 's') : sprintf('%ss',
                            $property);
                        foreach ($value as $item) {
                            $targetEntity->{'add' . ucfirst($singular)}($item);
                        }
                    }
                } else {
                    $targetEntity->{'set' . ucfirst($property)}($value);
                }
            }
        }

        return $targetEntity;
    }