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 array $queuedInserts Queued inserts. from BasicEntityPersister
protected array $columnTypes The map of column names to DBAL mapping types of all prepared columns used when INSERTing or UPDATEing an entity. from BasicEntityPersister
protected array $quotedColumns The map of quoted column names. from BasicEntityPersister
protected QuoteStrategy $quoteStrategy The quote strategy. 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.

void
addInsert(object $entity)

Adds an entity to the queued insertions.

array
getInserts()

Get all queued inserts.

array
executeInserts()

Executes all queued entity insertions and returns any generated post-insert identifiers that were created as a result of the insertions.

void
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(ClassMetadata $versionedClass, 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. If there is no changeset, nothing is updated.

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

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

void
deleteJoinTableRecords(array $identifier)

No description

bool
delete(object $entity)

Deletes a managed entity.

array
prepareUpdateData(object $entity)

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

array
prepareInsertData(object $entity)

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

string
getOwningTable(string $fieldName)

Gets the name of the table that owns the column the given field is mapped to.

object|null
load(array $criteria, object|null $entity = null, array|null $assoc = null, array $hints = array(), int|null $lockMode = null, int|null $limit = null, array $orderBy = null)

Loads an entity by a list of field criteria.

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

Loads an entity by identifier.

object
loadOneToOneEntity(array $assoc, object $sourceEntity, array $identifier = array())

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(array|Criteria $criteria = array())

Count entities (optionally filtered by a criteria)

array
loadCriteria(Criteria $criteria)

Loads Entities matching the given Criteria object.

array
expandCriteriaParameters(Criteria $criteria)

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

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

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

array
getManyToManyCollection(array $assoc, object $sourceEntity, int|null $offset = null, int|null $limit = null)

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

array
loadManyToManyCollection(array $assoc, object $sourceEntity, PersistentCollection $coll)

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

string
getSelectSQL(array|Criteria $criteria, array|null $assoc = null, int|null $lockMode = null, int|null $limit = null, int|null $offset = null, array $orderBy = null)

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

string
getCountSQL(array|Criteria $criteria = array())

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(string $field, array $assoc, ClassMetadata $class, string $alias = 'r')

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

string
getSelectManyToManyJoinSQL(array $manyToMany)

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

string
getInsertSQL()

No description

array
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 $className, 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(integer $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(string $field, mixed $value, array|null $assoc = null, string|null $comparison = null)

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

string
getSelectConditionSQL(array $criteria, array|null $assoc = null)

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

array
getOneToManyCollection(array $assoc, object $sourceEntity, int|null $offset = null, int|null $limit = null)

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

array
loadOneToManyCollection(array $assoc, object $sourceEntity, PersistentCollection $coll)

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

array
expandParameters($criteria)

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

boolean
exists(object $entity, Criteria $extraConditions = null)

Checks whether the given managed entity exists in the database.

string
getJoinSQLForJoinColumns(array $joinColumns)

Generates the appropriate join SQL for the given join column.

getSQLColumnAlias($columnName)

{@inheritdoc}

string
generateFilterConditionSQL(ClassMetadata $targetEntity, string $targetTableAlias)

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

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

Switches persister context according to current query offset/limits

string
getDiscriminatorColumnTableName()

Gets the name of the table that contains the discriminator column.

string
getSelectJoinColumnSQL(string $tableAlias, string $joinColumnName, string $className, string $type)

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

void addInsert(object $entity)

Adds an entity to the queued insertions.

The entity remains queued until {@link executeInserts} is invoked.

Parameters

object $entity The entity to queue for insertion.

Return Value

void

array getInserts()

Get all queued inserts.

Return Value

array

array executeInserts()

Executes all queued entity insertions and returns any generated post-insert identifiers that were created as a result of the insertions.

If no inserts are queued, invoking this method is a NOOP.

Return Value

array An array of any generated post-insert IDs. This will be an empty array if the entity class does not use the IDENTITY generation strategy.

protected void 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

Return Value

void

protected mixed fetchVersionValue(ClassMetadata $versionedClass, array $id)

Fetches the current version value of a versioned entity.

Parameters

ClassMetadata $versionedClass
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.

Parameters

object $entity The entity to update.

Return Value

void

final protected void updateTable(object $entity, string $quotedTableName, array $updateData, boolean $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).
boolean $versioned Whether the UPDATE should be versioned.

Return Value

void

Exceptions

ORMException
OptimisticLockException

protected void deleteJoinTableRecords(array $identifier)

Parameters

array $identifier

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.

protected array 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

array The prepared data.

protected array 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

array The prepared data for the tables to update.

string getOwningTable(string $fieldName)

Gets the name of the table that owns the column the given field is mapped to.

The default implementation in BasicEntityPersister always returns the name of the table the entity type of this persister is mapped to, since an entity is always persisted to a single table with a BasicEntityPersister.

Parameters

string $fieldName The field name.

Return Value

string The table name.

object|null load(array $criteria, object|null $entity = null, array|null $assoc = null, array $hints = array(), int|null $lockMode = null, int|null $limit = null, array $orderBy = null)

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.
array|null $assoc 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 loadOneToOneEntity(array $assoc, object $sourceEntity, array $identifier = array())

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

Parameters

array $assoc 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(array|Criteria $criteria = array())

Count entities (optionally filtered by a criteria)

Parameters

array|Criteria $criteria

Return Value

int

array loadCriteria(Criteria $criteria)

Loads Entities matching the given Criteria object.

Parameters

Criteria $criteria

Return Value

array

array expandCriteriaParameters(Criteria $criteria)

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

Parameters

Criteria $criteria

Return Value

array

array loadAll(array $criteria = array(), array $orderBy = null, 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
int|null $offset

Return Value

array

array getManyToManyCollection(array $assoc, object $sourceEntity, int|null $offset = null, int|null $limit = null)

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

Parameters

array $assoc
object $sourceEntity
int|null $offset
int|null $limit

Return Value

array

array loadManyToManyCollection(array $assoc, object $sourceEntity, PersistentCollection $coll)

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

Parameters

array $assoc The association mapping of the association being loaded.
object $sourceEntity The entity that owns the collection.
PersistentCollection $coll

Return Value

array

string getSelectSQL(array|Criteria $criteria, array|null $assoc = null, int|null $lockMode = null, int|null $limit = null, int|null $offset = null, array $orderBy = null)

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

Parameters

array|Criteria $criteria
array|null $assoc
int|null $lockMode
int|null $limit
int|null $offset
array $orderBy

Return Value

string

string getCountSQL(array|Criteria $criteria = array())

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

Parameters

array|Criteria $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(string $field, array $assoc, ClassMetadata $class, string $alias = 'r')

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

Parameters

string $field
array $assoc
ClassMetadata $class
string $alias

Return Value

string

protected string getSelectManyToManyJoinSQL(array $manyToMany)

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

Parameters

array $manyToMany

Return Value

string

string getInsertSQL()

Return Value

string

protected array 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

array 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 $className, string $assocName = '')

Gets the SQL table alias for the given class name.

Parameters

string $className
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(integer $lockMode)

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

Parameters

integer $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(string $field, mixed $value, array|null $assoc = null, string|null $comparison = null)

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

Parameters

string $field
mixed $value
array|null $assoc
string|null $comparison

Return Value

string

protected string getSelectConditionSQL(array $criteria, array|null $assoc = 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
array|null $assoc

Return Value

string

array getOneToManyCollection(array $assoc, 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

array $assoc
object $sourceEntity
int|null $offset
int|null $limit

Return Value

array

array loadOneToManyCollection(array $assoc, object $sourceEntity, PersistentCollection $coll)

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

Parameters

array $assoc
object $sourceEntity
PersistentCollection $coll

Return Value

array

array expandParameters($criteria)

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

Parameters

$criteria

Return Value

array

boolean exists(object $entity, Criteria $extraConditions = null)

Checks whether the given managed entity exists in the database.

Parameters

object $entity
Criteria $extraConditions

Return Value

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

protected string getJoinSQLForJoinColumns(array $joinColumns)

Generates the appropriate join SQL for the given join column.

Parameters

array $joinColumns The join columns definition of an association.

Return Value

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

getSQLColumnAlias($columnName)

{@inheritdoc}

Parameters

$columnName

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(null|int $offset, null|int $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

null|int $offset
null|int $limit

protected string getDiscriminatorColumnTableName()

Gets the name of the table that contains the discriminator column.

Return Value

string The table name.

protected string getSelectJoinColumnSQL(string $tableAlias, string $joinColumnName, string $className, string $type)

Parameters

string $tableAlias
string $joinColumnName
string $className
string $type

Return Value

string

protected string getSelectConditionDiscriminatorValueSQL()

Return Value

string