BasicEntityPersister
class BasicEntityPersister implements EntityPersister (View source)
A BasicEntityPersister maps an entity to a single table in a relational database.
A persister is always responsible for a single entity type.
EntityPersisters are used during a UnitOfWork to apply any changes to the persistent state of entities onto a relational database when the UnitOfWork is committed, as well as for basic querying of entities and their associations (not DQL).
The persisting operations that are invoked during a commit of a UnitOfWork to persist the persistent entity state are:
- {@link addInsert} : To schedule an entity for insertion.
- {@link executeInserts} : To execute all scheduled insertions.
- {@link update} : To update the persistent state of an entity.
- {@link delete} : To delete the persistent state of an entity.
As can be seen from the above list, insertions are batched and executed all at once for increased efficiency.
The querying operations invoked during a UnitOfWork, either through direct find requests or lazy-loading, are the following:
- {@link load} : Loads (the state of) a single, managed entity.
- {@link loadAll} : Loads multiple, managed entities.
- {@link loadOneToOneEntity} : Loads a one/many-to-one entity association (lazy-loading).
- {@link loadOneToManyCollection} : Loads a one-to-many entity association (lazy-loading).
- {@link loadManyToManyCollection} : Loads a many-to-many entity association (lazy-loading).
The BasicEntityPersister implementation provides the default behavior for persisting and querying entities that are mapped to a single database table.
Subclasses can be created to provide custom persisting and querying strategies, i.e. spanning multiple tables.
Properties
protected ClassMetadata | $class | Metadata object that describes the mapping of the mapped entity class. | |
protected Connection | $conn | The underlying DBAL Connection of the used EntityManager. | |
protected AbstractPlatform | $platform | The database platform. | |
protected EntityManagerInterface | $em | The EntityManager instance. | |
protected array | $queuedInserts | Queued inserts. | |
protected array | $columnTypes | The map of column names to DBAL mapping types of all prepared columns used when INSERTing or UPDATEing an entity. | |
protected array | $quotedColumns | The map of quoted column names. | |
protected QuoteStrategy | $quoteStrategy | The quote strategy. | |
protected CachedPersisterContext | $currentPersisterContext |
Methods
Initializes a new BasicEntityPersister that uses the given EntityManager and persists instances of the class described by the given ClassMetadata descriptor.
No description
Gets the ResultSetMapping used for hydration.
Adds an entity to the queued insertions.
Get all queued inserts.
Executes all queued entity insertions and returns any generated post-insert identifiers that were created as a result of the insertions.
Retrieves the default version value which was created by the preceding INSERT statement and assigns it back in to the entities version field.
Fetches the current version value of a versioned 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.
Performs an UPDATE statement for an entity on a specific table.
No description
Deletes a managed entity.
Prepares the changeset of an entity for database insertion (UPDATE).
Prepares the data changeset of a managed entity for database insertion (initial INSERT).
Gets the name of the table that owns the column the given field is mapped to.
Loads an entity by a list of field criteria.
Loads an entity by identifier.
Loads an entity of this persister's mapped class as part of a single-valued association from another entity.
Refreshes a managed entity.
Count entities (optionally filtered by a criteria)
Loads Entities matching the given Criteria object.
Expands Criteria Parameters by walking the expressions and grabbing all parameters and types from it.
Loads a list of entities by a list of field criteria.
Gets (sliced or full) elements of the given collection.
Loads a collection of entities of a many-to-many association.
Gets the SELECT SQL to select one or more entities by a set of field criteria.
Get the COUNT SQL to count entities (optionally based on a criteria)
Gets the ORDER BY SQL snippet for ordered collections.
Gets the SQL fragment with the list of columns to select when querying for an entity in this persister.
Gets the SQL join fragment used when selecting entities from an association.
Gets the SQL join fragment used when selecting entities from a many-to-many association.
No description
Gets the list of columns to put in the INSERT SQL statement.
Gets the SQL snippet of a qualified column name for the given field name.
Gets the SQL table alias for the given class name.
Locks all rows of this entity matching the given criteria with the specified pessimistic lock mode.
Gets the FROM and optionally JOIN conditions to lock the entity managed by this persister.
Gets the Select Where Condition from a Criteria object.
Gets the SQL WHERE condition for matching a field with a given value.
Gets the conditional SQL fragment used in the WHERE clause when selecting entities in this persister.
Returns an array with (sliced or full list) of elements in the specified collection.
Loads a collection of entities in a one-to-many association.
Expands the parameters from the given criteria and use the correct binding types if found.
Checks whether the given managed entity exists in the database.
Generates the appropriate join SQL for the given join column.
{@inheritdoc}
Generates the filter SQL for a given entity and table alias.
Switches persister context according to current query offset/limits
Details
at line 202
__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.
at line 225
ClassMetadata
getClassMetadata()
at line 233
ResultSetMapping
getResultSetMapping()
Gets the ResultSetMapping used for hydration.
at line 241
void
addInsert(object $entity)
Adds an entity to the queued insertions.
The entity remains queued until {@link executeInserts} is invoked.
at line 249
array
getInserts()
Get all queued inserts.
at line 257
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.
at line 317
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.
at line 332
protected mixed
fetchVersionValue(ClassMetadata $versionedClass, array $id)
Fetches the current version value of a versioned entity.
at line 354
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.
at line 389
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.
at line 494
protected void
deleteJoinTableRecords(array $identifier)
at line 551
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.
at line 604
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
Example:
array(
'foo_table' => array('column1' => 'value1', 'column2' => 'value2', ...),
'bar_table' => array('columnX' => 'valueX', 'columnY' => 'valueY', ...),
...
)
at line 690
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.
at line 698
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.
at line 706
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.
at line 728
object
loadById(array $identifier, object|null $entity = null)
Loads an entity by identifier.
at line 736
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.
at line 802
void
refresh(array $id, object $entity, int|null $lockMode = null)
Refreshes a managed entity.
at line 815
int
count(array|Criteria $criteria = array())
Count entities (optionally filtered by a criteria)
at line 829
array
loadCriteria(Criteria $criteria)
Loads Entities matching the given Criteria object.
at line 847
array
expandCriteriaParameters(Criteria $criteria)
Expands Criteria Parameters by walking the expressions and grabbing all parameters and types from it.
at line 878
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.
at line 894
array
getManyToManyCollection(array $assoc, object $sourceEntity, int|null $offset = null, int|null $limit = null)
Gets (sliced or full) elements of the given collection.
at line 952
array
loadManyToManyCollection(array $assoc, object $sourceEntity, PersistentCollection $coll)
Loads a collection of entities of a many-to-many association.
at line 1036
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.
at line 1098
string
getCountSQL(array|Criteria $criteria = array())
Get the COUNT SQL to count entities (optionally based on a criteria)
at line 1132
final protected string
getOrderBySQL(array $orderBy, string $baseTableAlias)
Gets the ORDER BY SQL snippet for ordered collections.
at line 1190
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.
at line 1311
protected string
getSelectColumnAssociationSQL(string $field, array $assoc, ClassMetadata $class, string $alias = 'r')
Gets the SQL join fragment used when selecting entities from an association.
at line 1343
protected string
getSelectManyToManyJoinSQL(array $manyToMany)
Gets the SQL join fragment used when selecting entities from a many-to-many association.
at line 1371
string
getInsertSQL()
at line 1420
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.
at line 1463
protected string
getSelectColumnSQL(string $field, ClassMetadata $class, string $alias = 'r')
Gets the SQL snippet of a qualified column name for the given field name.
at line 1491
protected string
getSQLTableAlias(string $className, string $assocName = '')
Gets the SQL table alias for the given class name.
at line 1511
void
lock(array $criteria, int $lockMode)
Locks all rows of this entity matching the given criteria with the specified pessimistic lock mode.
at line 1546
protected string
getLockTablesSql(integer $lockMode)
Gets the FROM and optionally JOIN conditions to lock the entity managed by this persister.
at line 1563
protected string
getSelectConditionCriteriaSQL(Criteria $criteria)
Gets the Select Where Condition from a Criteria object.
at line 1579
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.
at line 1719
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.
at line 1733
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.
at line 1745
array
loadOneToManyCollection(array $assoc, object $sourceEntity, PersistentCollection $coll)
Loads a collection of entities in a one-to-many association.
at line 1814
array
expandParameters($criteria)
Expands the parameters from the given criteria and use the correct binding types if found.
at line 1968
boolean
exists(object $entity, Criteria $extraConditions = null)
Checks whether the given managed entity exists in the database.
at line 2006
protected string
getJoinSQLForJoinColumns(array $joinColumns)
Generates the appropriate join SQL for the given join column.
at line 2021
getSQLColumnAlias($columnName)
{@inheritdoc}
at line 2034
protected string
generateFilterConditionSQL(ClassMetadata $targetEntity, string $targetTableAlias)
Generates the filter SQL for a given entity and table alias.
at line 2056
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