Doctrine


Doctrine\ORM\EntityManager
/Doctrine/ORM/EntityManager.php at line 42

Class EntityManager

EntityManager

public class EntityManager

The EntityManager is the central access point to ORM functionality.

License:
http://www.opensource.org/licenses/lgpl-license.php LGPL
See Also:
www.doctrine-project.org
Since:
2.0
Version:
$Revision$
Author:
Benjamin Eberlei
Guilherme Blanco
Jonathan Wage
Roman Borschel

Constructor Summary

EntityManager(Doctrine\DBAL\Connection conn, Doctrine\ORM\Configuration config, Doctrine\Common\EventManager eventManager)

Creates a new EntityManager that operates on the given database connection and uses the given Configuration and EventManager implementations.

Method Summary
void

beginTransaction()

Starts a transaction on the underlying database connection.

void

clear(string entityName)

Clears the EntityManager.

void

close()

Closes the EntityManager.

void

commit()

Commits a transaction on the underlying database connection.

boolean

contains(object entity)

Determines whether an entity instance is managed in this EntityManager.

object

copy(object entity, mixed deep)

Creates a copy of the given entity.

static EntityManager

create(mixed conn, Configuration config, EventManager eventManager)

Factory method to create EntityManager instances.

Doctrine\ORM\NativeQuery

createNamedNativeQuery(string name)

Creates a NativeQuery from a named native query.

Doctrine\ORM\Query

createNamedQuery(string name)

Creates a Query from a named query.

NativeQuery

createNativeQuery(string sql, ResultSetMapping rsm)

Creates a native SQL query.

Doctrine\ORM\Query

createQuery(mixed dql, string The)

Creates a new Query object.

QueryBuilder

createQueryBuilder()

Create a QueryBuilder instance

void

detach(object entity)

Detaches an entity from the EntityManager, causing a managed entity to become detached.

object

find(string entityName, mixed identifier)

Finds an Entity by its identifier.

void

flush()

Flushes all changes to objects that have been queued up to now to the database.

Doctrine\ORM\Mapping\ClassMetadata

getClassMetadata(mixed className)

Returns the metadata for a class.

Doctrine\ORM\Configuration

getConfiguration()

Gets the Configuration used by the EntityManager.

Doctrine\DBAL\Connection

getConnection()

Gets the database connection object used by the EntityManager.

Doctrine\Common\EventManager

getEventManager()

Gets the EventManager used by the EntityManager.

ExpressionBuilder

getExpressionBuilder()

Gets an ExpressionBuilder used for object-oriented construction of query expressions.

Doctrine\ORM\Internal\Hydration\AbstractHydrator

getHydrator(int hydrationMode)

Gets a hydrator for the given hydration mode.

Doctrine\ORM\Mapping\ClassMetadataFactory

getMetadataFactory()

Gets the metadata factory used to gather the metadata of classes.

ProxyFactory

getProxyFactory()

Gets the proxy factory used by the EntityManager to create entity proxies.

object

getReference(mixed entityName, mixed identifier)

Gets a reference to the entity identified by the given type and identifier without actually loading it.

EntityRepository

getRepository(string entityName)

Gets the repository for an entity class.

Doctrine\ORM\UnitOfWork

getUnitOfWork()

Gets the UnitOfWork used by the EntityManager to coordinate operations.

object

merge(object entity)

Merges the state of a detached entity into the persistence context of this EntityManager and returns the managed copy of the entity.

Doctrine\ORM\Internal\Hydration\AbstractHydrator

newHydrator(int hydrationMode)

Create a new instance for the given hydration mode.

void

persist(mixed entity, object object)

Tells the EntityManager to make an instance managed and persistent.

void

refresh(object entity)

Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been persisted.

void

remove(object entity)

Removes an entity instance.

void

rollback()

Performs a rollback on the underlying database connection and closes the EntityManager as it may now be in a corrupted state.

Constructor Detail

/Doctrine/ORM/EntityManager.php at line 118

EntityManager

public EntityManager(Doctrine\DBAL\Connection conn, Doctrine\ORM\Configuration config, Doctrine\Common\EventManager eventManager)

Creates a new EntityManager that operates on the given database connection and uses the given Configuration and EventManager implementations.


Method Detail

/Doctrine/ORM/EntityManager.php at line 176

beginTransaction

public void beginTransaction()

Starts a transaction on the underlying database connection.


/Doctrine/ORM/EntityManager.php at line 331

clear

public void clear(string entityName)

Clears the EntityManager. All entities that are currently managed by this EntityManager become detached.


/Doctrine/ORM/EntityManager.php at line 346

close

public void close()

Closes the EntityManager. All entities that are currently managed by this EntityManager become detached. The EntityManager may no longer be used after it is closed.


/Doctrine/ORM/EntityManager.php at line 184

commit

public void commit()

Commits a transaction on the underlying database connection.


/Doctrine/ORM/EntityManager.php at line 482

contains

public boolean contains(object entity)

Determines whether an entity instance is managed in this EntityManager.

Returns:
TRUE if this EntityManager currently manages the given entity, FALSE otherwise.

/Doctrine/ORM/EntityManager.php at line 445

copy

public object copy(object entity, mixed deep)

Creates a copy of the given entity. Can create a shallow or a deep copy.

Parameters:
entity - The entity to copy.
Returns:
The new entity.
Todo:
Implementation or remove.

/Doctrine/ORM/EntityManager.php at line 596

create

public static EntityManager create(mixed conn, Configuration config, EventManager eventManager)

Factory method to create EntityManager instances.

Parameters:
conn - An array with the connection parameters or an existing Connection instance.
config - The Configuration instance to use.
eventManager - The EventManager instance to use.
Returns:
The created EntityManager.

/Doctrine/ORM/EntityManager.php at line 257

createNamedNativeQuery

public Doctrine\ORM\NativeQuery createNamedNativeQuery(string name)

Creates a NativeQuery from a named native query.


/Doctrine/ORM/EntityManager.php at line 231

createNamedQuery

public Doctrine\ORM\Query createNamedQuery(string name)

Creates a Query from a named query.


/Doctrine/ORM/EntityManager.php at line 243

createNativeQuery

public NativeQuery createNativeQuery(string sql, ResultSetMapping rsm)

Creates a native SQL query.

Parameters:
rsm - The ResultSetMapping to use.

/Doctrine/ORM/EntityManager.php at line 216

createQuery

public Doctrine\ORM\Query createQuery(mixed dql, string The)

Creates a new Query object.

Parameters:
The - DQL string.

/Doctrine/ORM/EntityManager.php at line 268

createQueryBuilder

public QueryBuilder createQueryBuilder()

Create a QueryBuilder instance

Returns:
$qb

/Doctrine/ORM/EntityManager.php at line 413

detach

public void detach(object entity)

Detaches an entity from the EntityManager, causing a managed entity to become detached. Unflushed changes made to the entity if any (including removal of the entity), will not be synchronized to the database. Entities which previously referenced the detached entity will continue to reference it.

Parameters:
entity - The entity to detach.

/Doctrine/ORM/EntityManager.php at line 293

find

public object find(string entityName, mixed identifier)

Finds an Entity by its identifier.

This is just a convenient shortcut for getRepository($entityName)->find($id).


/Doctrine/ORM/EntityManager.php at line 278

flush

public void flush()

Flushes all changes to objects that have been queued up to now to the database. This effectively synchronizes the in-memory state of managed objects with the database.


/Doctrine/ORM/EntityManager.php at line 205

getClassMetadata

public Doctrine\ORM\Mapping\ClassMetadata getClassMetadata(mixed className)

Returns the metadata for a class.

Internal:
Performance-sensitive method.

/Doctrine/ORM/EntityManager.php at line 504

getConfiguration

public Doctrine\ORM\Configuration getConfiguration()

Gets the Configuration used by the EntityManager.


/Doctrine/ORM/EntityManager.php at line 137

getConnection

public Doctrine\DBAL\Connection getConnection()

Gets the database connection object used by the EntityManager.


/Doctrine/ORM/EntityManager.php at line 494

getEventManager

public Doctrine\Common\EventManager getEventManager()

Gets the EventManager used by the EntityManager.


/Doctrine/ORM/EntityManager.php at line 165

getExpressionBuilder

public ExpressionBuilder getExpressionBuilder()

Gets an ExpressionBuilder used for object-oriented construction of query expressions.

Example:

[php] $qb = $em->createQueryBuilder(); $expr = $em->getExpressionBuilder(); $qb->select('u')->from('User', 'u') ->where($expr->orX($expr->eq('u.id', 1), $expr->eq('u.id', 2)));


/Doctrine/ORM/EntityManager.php at line 540

getHydrator

public Doctrine\ORM\Internal\Hydration\AbstractHydrator getHydrator(int hydrationMode)

Gets a hydrator for the given hydration mode.

This method caches the hydrator instances which is used for all queries that don't selectively iterate over the result.


/Doctrine/ORM/EntityManager.php at line 147

getMetadataFactory

public Doctrine\ORM\Mapping\ClassMetadataFactory getMetadataFactory()

Gets the metadata factory used to gather the metadata of classes.


/Doctrine/ORM/EntityManager.php at line 582

getProxyFactory

public ProxyFactory getProxyFactory()

Gets the proxy factory used by the EntityManager to create entity proxies.


/Doctrine/ORM/EntityManager.php at line 308

getReference

public object getReference(mixed entityName, mixed identifier)

Gets a reference to the entity identified by the given type and identifier without actually loading it.

If partial objects are allowed, this method will return a partial object that only has its identifier populated. Otherwise a proxy is returned that automatically loads itself on first access.

Returns:
The entity reference.

/Doctrine/ORM/EntityManager.php at line 456

getRepository

public EntityRepository getRepository(string entityName)

Gets the repository for an entity class.

Parameters:
entityName - The name of the Entity.
Returns:
The repository.

/Doctrine/ORM/EntityManager.php at line 526

getUnitOfWork

public Doctrine\ORM\UnitOfWork getUnitOfWork()

Gets the UnitOfWork used by the EntityManager to coordinate operations.


/Doctrine/ORM/EntityManager.php at line 429

merge

public object merge(object entity)

Merges the state of a detached entity into the persistence context of this EntityManager and returns the managed copy of the entity. The entity passed to merge will not become associated/managed with this EntityManager.

Parameters:
entity - The detached entity to merge into the persistence context.
Returns:
The managed copy of the entity.

/Doctrine/ORM/EntityManager.php at line 555

newHydrator

public Doctrine\ORM\Internal\Hydration\AbstractHydrator newHydrator(int hydrationMode)

Create a new instance for the given hydration mode.


/Doctrine/ORM/EntityManager.php at line 363

persist

public void persist(mixed entity, object object)

Tells the EntityManager to make an instance managed and persistent.

The entity will be entered into the database at or before transaction commit or as a result of the flush operation.

NOTE: The persist operation always considers entities that are not yet known to this EntityManager as NEW. Do not pass detached entities to the persist operation.

Parameters:
object - The instance to make managed and persistent.

/Doctrine/ORM/EntityManager.php at line 395

refresh

public void refresh(object entity)

Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been persisted.

Parameters:
entity - The entity to refresh.

/Doctrine/ORM/EntityManager.php at line 380

remove

public void remove(object entity)

Removes an entity instance.

A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.

Parameters:
entity - The entity instance to remove.

/Doctrine/ORM/EntityManager.php at line 193

rollback

public void rollback()

Performs a rollback on the underlying database connection and closes the EntityManager as it may now be in a corrupted state.


Doctrine