class SingleTablePersister extends AbstractEntityInheritancePersister (View source)

Persister for entities that participate in a hierarchy mapped with the SINGLE_TABLE strategy.

Properties

protected ClassMetadata $class Metadata object that describes the mapping of the mapped entity class. from BasicEntityPersister
protected Connection $conn The underlying DBAL Connection of the used EntityManager. from BasicEntityPersister
protected AbstractPlatform $platform The database platform. from BasicEntityPersister
protected EntityManagerInterface $em The EntityManager instance. from BasicEntityPersister
protected ColumnMetadata[] $columns The map of column names to DBAL columns used when INSERTing or UPDATEing an entity. from BasicEntityPersister
protected CachedPersisterContext $currentPersisterContext from BasicEntityPersister

Methods

__construct(EntityManagerInterface $em, ClassMetadata $class)

Initializes a new BasicEntityPersister that uses the given EntityManager and persists instances of the class described by the given ClassMetadata descriptor.

getResultSetMapping()

Gets the ResultSetMapping used for hydration.

mixed[]
getIdentifier(object $entity)

Extracts the identifier values of an entity that relies on this persister.

setIdentifier(object $entity, array $id)

Populates the entity identifier of an entity.

void
insert($entity)

Inserts an entity. Returns any generated post-insert identifiers that were created as a result of the insertion.

assignDefaultVersionValue(object $entity, array $id)

Retrieves the default version value which was created by the preceding INSERT statement and assigns it back in to the entities version field.

mixed
fetchVersionValue(VersionFieldMetadata $versionProperty, array $id)

Fetches the current version value of a versioned entity.

void
update(object $entity)

Updates a managed entity. The entity is updated according to its current changeset in the running UnitOfWork.

bool
delete(object $entity)

Deletes a managed entity.

updateTable(object $entity, string $quotedTableName, array $updateData, bool $versioned = false)

Performs an UPDATE statement for an entity on a specific table.

deleteJoinTableRecords(mixed[] $identifier)

No description

mixed[]
prepareInsertData(object $entity)

Prepares the data changeset of a managed entity for database insertion (initial INSERT).

mixed[]
prepareUpdateData(object $entity)

Prepares the changeset of an entity for database insertion (UPDATE).

mixed|null
getColumnValue($entity, string $columnName)

No description

object|null
load(array $criteria, object|null $entity = null, AssociationMetadata|null $association = null, array $hints = [], int|null $lockMode = null, int|null $limit = null, array $orderBy = [])

Loads an entity by a list of field criteria.

object
loadById(array $identifier, object|null $entity = null)

Loads an entity by identifier.

object
loadToOneEntity(ToOneAssociationMetadata $association, object $sourceEntity, array $identifier = [])

Loads an entity of this persister's mapped class as part of a single-valued association from another entity.

void
refresh(array $id, object $entity, int|null $lockMode = null)

Refreshes a managed entity.

int
count(Criteria[]|Criteria $criteria = [])

Count entities (optionally filtered by a criteria)

mixed[]
loadCriteria(Criteria $criteria)

Loads Entities matching the given Criteria object.

mixed[][]
expandCriteriaParameters(Criteria $criteria)

Expands Criteria Parameters by walking the expressions and grabbing all parameters and types from it.

mixed[]
loadAll(array $criteria = [], array $orderBy = [], int|null $limit = null, int|null $offset = null)

Loads a list of entities by a list of field criteria.

mixed[]
getManyToManyCollection(ManyToManyAssociationMetadata $association, object $sourceEntity, int|null $offset = null, int|null $limit = null)

Gets (sliced or full) elements of the given collection.

mixed[]
loadManyToManyCollection(ManyToManyAssociationMetadata $association, object $sourceEntity, PersistentCollection $collection)

Loads a collection of entities of a many-to-many association.

string
getSelectSQL($criteria, AssociationMetadata|null $association = null, $lockMode = null, $limit = null, $offset = null, array $orderBy = [])

Gets the SELECT SQL to select one or more entities by a set of field criteria.

string
getCountSQL(Criteria|mixed[] $criteria = [])

Get the COUNT SQL to count entities (optionally based on a criteria)

string
getOrderBySQL(array $orderBy, string $baseTableAlias)

Gets the ORDER BY SQL snippet for ordered collections.

string
getSelectColumnsSQL()

Gets the SQL fragment with the list of columns to select when querying for an entity in this persister.

string
getSelectColumnAssociationSQL($field, AssociationMetadata $association, ClassMetadata $class, $alias = 'r')

Gets the SQL join fragment used when selecting entities from an association.

string
getSelectManyToManyJoinSQL(ManyToManyAssociationMetadata $association)

Gets the SQL join fragment used when selecting entities from a many-to-many association.

getInsertSQL()

{@inheritdoc}

string[]
getInsertColumnList()

Gets the list of columns to put in the INSERT SQL statement.

string
getSelectColumnSQL(string $field, ClassMetadata $class, string $alias = 'r')

Gets the SQL snippet of a qualified column name for the given field name.

string
getSQLTableAlias(string $tableName, string $assocName = '')

Gets the SQL table alias for the given class name.

void
lock(array $criteria, int $lockMode)

Locks all rows of this entity matching the given criteria with the specified pessimistic lock mode.

string
getLockTablesSql(int $lockMode)

Gets the FROM and optionally JOIN conditions to lock the entity managed by this persister.

string
getSelectConditionCriteriaSQL(Criteria $criteria)

Gets the Select Where Condition from a Criteria object.

string
getSelectConditionStatementSQL($field, $value, AssociationMetadata|null $association = null, $comparison = null)

Gets the SQL WHERE condition for matching a field with a given value.

string
getSelectConditionSQL(array $criteria, AssociationMetadata|null $association = null)

Gets the conditional SQL fragment used in the WHERE clause when selecting entities in this persister.

mixed[]
getOneToManyCollection(OneToManyAssociationMetadata $association, object $sourceEntity, int|null $offset = null, int|null $limit = null)

Returns an array with (sliced or full list) of elements in the specified collection.

mixed[]
loadOneToManyCollection(OneToManyAssociationMetadata $association, object $sourceEntity, PersistentCollection $collection)

Loads a collection of entities in a one-to-many association.

mixed[][]
expandParameters(mixed[] $criteria)

Expands the parameters from the given criteria and use the correct binding types if found.

bool
exists($entity, Criteria|null $extraConditions = null)

Checks whether the given managed entity exists in the database.

string
getJoinSQLForAssociation(AssociationMetadata $association)

Generates the appropriate join SQL for the given association.

string
getSQLColumnAlias()

Gets an SQL column alias for a column name.

string
generateFilterConditionSQL(ClassMetadata $targetEntity, string $targetTableAlias)

Generates the filter SQL for a given entity and table alias.

switchPersisterContext(int|null $offset, int|null $limit)

Switches persister context according to current query offset/limits

string
getSelectJoinColumnSQL(JoinColumnMetadata $joinColumnMetadata)

No description

string

Details

__construct(EntityManagerInterface $em, ClassMetadata $class)

Initializes a new BasicEntityPersister that uses the given EntityManager and persists instances of the class described by the given ClassMetadata descriptor.

Parameters

EntityManagerInterface $em
ClassMetadata $class

ClassMetadata getClassMetadata()

Return Value

ClassMetadata

ResultSetMapping getResultSetMapping()

Gets the ResultSetMapping used for hydration.

Return Value

ResultSetMapping

mixed[] getIdentifier(object $entity)

Extracts the identifier values of an entity that relies on this persister.

For composite identifiers, the identifier values are returned as an array with the same order as the field order in {@link ClassMetadata#identifier}.

Parameters

object $entity

Return Value

mixed[]

setIdentifier(object $entity, array $id)

Populates the entity identifier of an entity.

Parameters

object $entity
array $id

void insert($entity)

Inserts an entity. Returns any generated post-insert identifiers that were created as a result of the insertion.

The insertion happens instantaneously.

Subclasses may override this method to customize the semantics of entity deletion.

Parameters

$entity

Return Value

void

protected assignDefaultVersionValue(object $entity, array $id)

Retrieves the default version value which was created by the preceding INSERT statement and assigns it back in to the entities version field.

Parameters

object $entity
array $id

protected mixed fetchVersionValue(VersionFieldMetadata $versionProperty, array $id)

Fetches the current version value of a versioned entity.

Parameters

VersionFieldMetadata $versionProperty
array $id

Return Value

mixed

void update(object $entity)

Updates a managed entity. The entity is updated according to its current changeset in the running UnitOfWork.

If there is no changeset, nothing is updated.

Subclasses may override this method to customize the semantics of entity update.

Parameters

object $entity The entity to update.

Return Value

void

bool delete(object $entity)

Deletes a managed entity.

The entity to delete must be managed and have a persistent identifier. The deletion happens instantaneously.

Subclasses may override this method to customize the semantics of entity deletion.

Parameters

object $entity The entity to delete.

Return Value

bool TRUE if the entity got deleted in the database, FALSE otherwise.

final protected updateTable(object $entity, string $quotedTableName, array $updateData, bool $versioned = false)

Performs an UPDATE statement for an entity on a specific table.

The UPDATE can optionally be versioned, which requires the entity to have a version field.

Parameters

object $entity The entity object being updated.
string $quotedTableName The quoted name of the table to apply the UPDATE on.
array $updateData The map of columns to update (column => value).
bool $versioned Whether the UPDATE should be versioned.

Exceptions

ORMException
OptimisticLockException

protected deleteJoinTableRecords(mixed[] $identifier)

Parameters

mixed[] $identifier

protected mixed[] prepareInsertData(object $entity)

Prepares the data changeset of a managed entity for database insertion (initial INSERT).

The changeset of the entity is obtained from the currently running UnitOfWork.

The default insert data preparation is the same as for updates.

Parameters

object $entity The entity for which to prepare the data.

Return Value

mixed[] The prepared data for the tables to update.

protected mixed[] prepareUpdateData(object $entity)

Prepares the changeset of an entity for database insertion (UPDATE).

The changeset is obtained from the currently running UnitOfWork.

During this preparation the array that is passed as the second parameter is filled with => pairs, grouped by table name.

Example: array( 'foo_table' => array('column1' => 'value1', 'column2' => 'value2', ...), 'bar_table' => array('columnX' => 'valueX', 'columnY' => 'valueY', ...), ... )

Parameters

object $entity The entity for which to prepare the data.

Return Value

mixed[] The prepared data.

mixed|null getColumnValue($entity, string $columnName)

Parameters

$entity
string $columnName

Return Value

mixed|null

object|null load(array $criteria, object|null $entity = null, AssociationMetadata|null $association = null, array $hints = [], int|null $lockMode = null, int|null $limit = null, array $orderBy = [])

Loads an entity by a list of field criteria.

Parameters

array $criteria The criteria by which to load the entity.
object|null $entity The entity to load the data into. If not specified, a new entity is created.
AssociationMetadata|null $association The association that connects the entity to load to another entity, if any.
array $hints Hints for entity creation.
int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants or NULL if no specific lock mode should be used for loading the entity.
int|null $limit Limit number of results.
array $orderBy Criteria to order by.

Return Value

object|null The loaded and managed entity instance or NULL if the entity can not be found.

object loadById(array $identifier, object|null $entity = null)

Loads an entity by identifier.

Parameters

array $identifier The entity identifier.
object|null $entity The entity to load the data into. If not specified, a new entity is created.

Return Value

object The loaded and managed entity instance or NULL if the entity can not be found.

object loadToOneEntity(ToOneAssociationMetadata $association, object $sourceEntity, array $identifier = [])

Loads an entity of this persister's mapped class as part of a single-valued association from another entity.

Parameters

ToOneAssociationMetadata $association The association to load.
object $sourceEntity The entity that owns the association (not necessarily the "owning side").
array $identifier The identifier of the entity to load. Must be provided if the association to load represents the owning side, otherwise the identifier is derived from the $sourceEntity.

Return Value

object The loaded and managed entity instance or NULL if the entity can not be found.

Exceptions

MappingException

void refresh(array $id, object $entity, int|null $lockMode = null)

Refreshes a managed entity.

Parameters

array $id The identifier of the entity as an associative array from column or field names to values.
object $entity The entity to refresh.
int|null $lockMode One of the \Doctrine\DBAL\LockMode::* constants or NULL if no specific lock mode should be used for refreshing the managed entity.

Return Value

void

int count(Criteria[]|Criteria $criteria = [])

Count entities (optionally filtered by a criteria)

Parameters

Criteria[]|Criteria $criteria

Return Value

int

mixed[] loadCriteria(Criteria $criteria)

Loads Entities matching the given Criteria object.

Parameters

Criteria $criteria

Return Value

mixed[]

mixed[][] expandCriteriaParameters(Criteria $criteria)

Expands Criteria Parameters by walking the expressions and grabbing all parameters and types from it.

Parameters

Criteria $criteria

Return Value

mixed[][]

mixed[] loadAll(array $criteria = [], array $orderBy = [], int|null $limit = null, int|null $offset = null)

Loads a list of entities by a list of field criteria.

Parameters

array $criteria
array $orderBy
int|null $limit Limit number of results.
int|null $offset

Return Value

mixed[]

mixed[] getManyToManyCollection(ManyToManyAssociationMetadata $association, object $sourceEntity, int|null $offset = null, int|null $limit = null)

Gets (sliced or full) elements of the given collection.

Parameters

ManyToManyAssociationMetadata $association The association mapping of the association being loaded.
object $sourceEntity The entity that owns the collection.
int|null $offset
int|null $limit Limit number of results.

Return Value

mixed[]

mixed[] loadManyToManyCollection(ManyToManyAssociationMetadata $association, object $sourceEntity, PersistentCollection $collection)

Loads a collection of entities of a many-to-many association.

Parameters

ManyToManyAssociationMetadata $association The association mapping of the association being loaded.
object $sourceEntity The entity that owns the collection.
PersistentCollection $collection The collection to load/fill.

Return Value

mixed[]

string getSelectSQL($criteria, AssociationMetadata|null $association = null, $lockMode = null, $limit = null, $offset = null, array $orderBy = [])

Gets the SELECT SQL to select one or more entities by a set of field criteria.

Parameters

$criteria
AssociationMetadata|null $association
$lockMode
$limit
$offset
array $orderBy

Return Value

string

string getCountSQL(Criteria|mixed[] $criteria = [])

Get the COUNT SQL to count entities (optionally based on a criteria)

Parameters

Criteria|mixed[] $criteria

Return Value

string

final protected string getOrderBySQL(array $orderBy, string $baseTableAlias)

Gets the ORDER BY SQL snippet for ordered collections.

Parameters

array $orderBy
string $baseTableAlias

Return Value

string

Exceptions

ORMException

protected string getSelectColumnsSQL()

Gets the SQL fragment with the list of columns to select when querying for an entity in this persister.

Subclasses should override this method to alter or change the select column list SQL fragment. Note that in the implementation of BasicEntityPersister the resulting SQL fragment is generated only once and cached in {@link selectColumnListSql}. Subclasses may or may not do the same.

Return Value

string The SQL fragment.

protected string getSelectColumnAssociationSQL($field, AssociationMetadata $association, ClassMetadata $class, $alias = 'r')

Gets the SQL join fragment used when selecting entities from an association.

Parameters

$field
AssociationMetadata $association
ClassMetadata $class
$alias

Return Value

string

protected string getSelectManyToManyJoinSQL(ManyToManyAssociationMetadata $association)

Gets the SQL join fragment used when selecting entities from a many-to-many association.

Parameters

ManyToManyAssociationMetadata $association

Return Value

string

getInsertSQL()

{@inheritdoc}

protected string[] getInsertColumnList()

Gets the list of columns to put in the INSERT SQL statement.

Subclasses should override this method to alter or change the list of columns placed in the INSERT statements used by the persister.

Return Value

string[] The list of columns.

protected string getSelectColumnSQL(string $field, ClassMetadata $class, string $alias = 'r')

Gets the SQL snippet of a qualified column name for the given field name.

Parameters

string $field The field name.
ClassMetadata $class The class that declares this field. The table this class is mapped to must own the column for the given field.
string $alias

Return Value

string

protected string getSQLTableAlias(string $tableName, string $assocName = '')

Gets the SQL table alias for the given class name.

Parameters

string $tableName
string $assocName

Return Value

string The SQL table alias.

void lock(array $criteria, int $lockMode)

Locks all rows of this entity matching the given criteria with the specified pessimistic lock mode.

Parameters

array $criteria
int $lockMode One of the Doctrine\DBAL\LockMode::* constants.

Return Value

void

protected string getLockTablesSql(int $lockMode)

Gets the FROM and optionally JOIN conditions to lock the entity managed by this persister.

Parameters

int $lockMode One of the Doctrine\DBAL\LockMode::* constants.

Return Value

string

protected string getSelectConditionCriteriaSQL(Criteria $criteria)

Gets the Select Where Condition from a Criteria object.

Parameters

Criteria $criteria

Return Value

string

string getSelectConditionStatementSQL($field, $value, AssociationMetadata|null $association = null, $comparison = null)

Gets the SQL WHERE condition for matching a field with a given value.

Parameters

$field
$value
AssociationMetadata|null $association
$comparison

Return Value

string

protected string getSelectConditionSQL(array $criteria, AssociationMetadata|null $association = null)

Gets the conditional SQL fragment used in the WHERE clause when selecting entities in this persister.

Subclasses are supposed to override this method if they intend to change or alter the criteria by which entities are selected.

Parameters

array $criteria
AssociationMetadata|null $association

Return Value

string

mixed[] getOneToManyCollection(OneToManyAssociationMetadata $association, object $sourceEntity, int|null $offset = null, int|null $limit = null)

Returns an array with (sliced or full list) of elements in the specified collection.

Parameters

OneToManyAssociationMetadata $association The association mapping of the association being loaded.
object $sourceEntity The entity that owns the collection.
int|null $offset
int|null $limit Limit number of results.

Return Value

mixed[]

mixed[] loadOneToManyCollection(OneToManyAssociationMetadata $association, object $sourceEntity, PersistentCollection $collection)

Loads a collection of entities in a one-to-many association.

Parameters

OneToManyAssociationMetadata $association The association mapping of the association being loaded.
object $sourceEntity The entity that owns the collection.
PersistentCollection $collection The collection to load/fill.

Return Value

mixed[]

mixed[][] expandParameters(mixed[] $criteria)

Expands the parameters from the given criteria and use the correct binding types if found.

Parameters

mixed[] $criteria

Return Value

mixed[][]

bool exists($entity, Criteria|null $extraConditions = null)

Checks whether the given managed entity exists in the database.

Parameters

$entity
Criteria|null $extraConditions

Return Value

bool TRUE if the entity exists in the database, FALSE otherwise.

protected string getJoinSQLForAssociation(AssociationMetadata $association)

Generates the appropriate join SQL for the given association.

Parameters

AssociationMetadata $association

Return Value

string LEFT JOIN if one of the columns is nullable, INNER JOIN otherwise.

string getSQLColumnAlias()

Gets an SQL column alias for a column name.

Return Value

string

protected string generateFilterConditionSQL(ClassMetadata $targetEntity, string $targetTableAlias)

Generates the filter SQL for a given entity and table alias.

Parameters

ClassMetadata $targetEntity Metadata of the target entity.
string $targetTableAlias The table alias of the joined/selected table.

Return Value

string The SQL query part to add to a query.

protected switchPersisterContext(int|null $offset, int|null $limit)

Switches persister context according to current query offset/limits

This is due to the fact that to-many associations cannot be fetch-joined when a limit is involved

Parameters

int|null $offset
int|null $limit

protected string getSelectJoinColumnSQL(JoinColumnMetadata $joinColumnMetadata)

Parameters

JoinColumnMetadata $joinColumnMetadata

Return Value

string

protected string getSelectConditionDiscriminatorValueSQL()

Return Value

string