class DocumentPersister (View source)

The DocumentPersister is responsible for persisting documents.

Methods

__construct(PersistenceBuilder $pb, DocumentManager $dm, EventManager $evm, UnitOfWork $uow, HydratorFactory $hydratorFactory, ClassMetadata $class, CriteriaMerger $cm = null)

Initializes this instance.

array
getInserts()

No description

bool
isQueuedForInsert(object $document)

No description

addInsert(object $document)

Adds a document to the queued insertions.

array
getUpserts()

No description

boolean
isQueuedForUpsert(object $document)

No description

addUpsert(object $document)

Adds a document to the queued upserts.

getClassMetadata()

Gets the ClassMetadata instance of the document class this persister is used for.

executeInserts(array $options = array())

Executes all queued document insertions.

executeUpserts(array $options = array())

Executes all queued document upserts.

update(object $document, array $options = array())

Updates the already persisted document if it has any new changesets.

delete(mixed $document, array $options = array())

Removes document from mongo

refresh(string $id, object $document) deprecated

Refreshes a managed document.

object|null
load(mixed $criteria, object $document = null, array $hints = array(), integer $lockMode = 0, array $sort = null)

Finds a document by a set of criteria.

loadAll(array $criteria = array(), array $sort = null, integer|null $limit = null, integer|null $skip = null)

Finds documents by a set of criteria.

boolean
exists(object $document)

Checks whether the given managed document exists in the database.

lock(object $document, int $lockMode)

Locks document by storing the lock mode on the mapped lock field.

unlock(object $document)

Releases any lock that exists on this document.

loadCollection(PersistentCollectionInterface $collection)

Loads a PersistentCollection data. Used in the initialize() method.

array
prepareSortOrProjection(array $fields)

Prepare a sort or projection array by converting keys, which are PHP property names, to MongoDB field names.

string
prepareFieldName(string $fieldName)

Prepare a mongodb field name and convert the PHP property names to MongoDB field names.

array
addDiscriminatorToPreparedQuery(array $preparedQuery)

Adds discriminator criteria to an already-prepared query.

array
addFilterToPreparedQuery(array $preparedQuery)

Adds filter criteria to an already-prepared query.

array
prepareQueryOrNewObj(array $query, bool $isNewObj = false)

Prepares the query criteria or new document object.

Details

__construct(PersistenceBuilder $pb, DocumentManager $dm, EventManager $evm, UnitOfWork $uow, HydratorFactory $hydratorFactory, ClassMetadata $class, CriteriaMerger $cm = null)

Initializes this instance.

Parameters

PersistenceBuilder $pb
DocumentManager $dm
EventManager $evm
UnitOfWork $uow
HydratorFactory $hydratorFactory
ClassMetadata $class
CriteriaMerger $cm

array getInserts()

Return Value

array

bool isQueuedForInsert(object $document)

Parameters

object $document

Return Value

bool

addInsert(object $document)

Adds a document to the queued insertions.

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

Parameters

object $document The document to queue for insertion.

array getUpserts()

Return Value

array

boolean isQueuedForUpsert(object $document)

Parameters

object $document

Return Value

boolean

addUpsert(object $document)

Adds a document to the queued upserts.

The document remains queued until {@link executeUpserts} is invoked.

Parameters

object $document The document to queue for insertion.

ClassMetadata getClassMetadata()

Gets the ClassMetadata instance of the document class this persister is used for.

Return Value

ClassMetadata

executeInserts(array $options = array())

Executes all queued document insertions.

Queued documents without an ID will inserted in a batch and queued documents with an ID will be upserted individually.

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

Parameters

array $options Options for batchInsert() and update() driver methods

executeUpserts(array $options = array())

Executes all queued document upserts.

Queued documents with an ID are upserted individually.

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

Parameters

array $options Options for batchInsert() and update() driver methods

update(object $document, array $options = array())

Updates the already persisted document if it has any new changesets.

Parameters

object $document
array $options Array of options to be used with update()

Exceptions

LockException

delete(mixed $document, array $options = array())

Removes document from mongo

Parameters

mixed $document
array $options Array of options to be used with remove()

Exceptions

LockException

refresh(string $id, object $document) deprecated

deprecated The first argument is deprecated.

Refreshes a managed document.

Parameters

string $id
object $document The document to refresh.

object|null load(mixed $criteria, object $document = null, array $hints = array(), integer $lockMode = 0, array $sort = null)

Finds a document by a set of criteria.

If a scalar or MongoId is provided for $criteria, it will be used to match an _id value.

Parameters

mixed $criteria Query criteria
object $document Document to load the data into. If not specified, a new document is created.
array $hints Hints for document creation
integer $lockMode
array $sort Sort array for Cursor::sort()

Return Value

object|null The loaded and managed document instance or null if no document was found

Exceptions

LockException

Cursor loadAll(array $criteria = array(), array $sort = null, integer|null $limit = null, integer|null $skip = null)

Finds documents by a set of criteria.

Parameters

array $criteria Query criteria
array $sort Sort array for Cursor::sort()
integer|null $limit Limit for Cursor::limit()
integer|null $skip Skip for Cursor::skip()

Return Value

Cursor

boolean exists(object $document)

Checks whether the given managed document exists in the database.

Parameters

object $document

Return Value

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

lock(object $document, int $lockMode)

Locks document by storing the lock mode on the mapped lock field.

Parameters

object $document
int $lockMode

unlock(object $document)

Releases any lock that exists on this document.

Parameters

object $document

loadCollection(PersistentCollectionInterface $collection)

Loads a PersistentCollection data. Used in the initialize() method.

Parameters

PersistentCollectionInterface $collection

Query createReferenceManyInverseSideQuery(PersistentCollectionInterface $collection)

Parameters

PersistentCollectionInterface $collection

Return Value

Query

CursorInterface createReferenceManyWithRepositoryMethodCursor(PersistentCollectionInterface $collection)

Parameters

PersistentCollectionInterface $collection

Return Value

CursorInterface

array prepareSortOrProjection(array $fields)

Prepare a sort or projection array by converting keys, which are PHP property names, to MongoDB field names.

Parameters

array $fields

Return Value

array

string prepareFieldName(string $fieldName)

Prepare a mongodb field name and convert the PHP property names to MongoDB field names.

Parameters

string $fieldName

Return Value

string

array addDiscriminatorToPreparedQuery(array $preparedQuery)

Adds discriminator criteria to an already-prepared query.

This method should be used once for query criteria and not be used for nested expressions. It should be called before {@link DocumentPerister::addFilterToPreparedQuery()}.

Parameters

array $preparedQuery

Return Value

array

array addFilterToPreparedQuery(array $preparedQuery)

Adds filter criteria to an already-prepared query.

This method should be used once for query criteria and not be used for nested expressions. It should be called after {@link DocumentPerister::addDiscriminatorToPreparedQuery()}.

Parameters

array $preparedQuery

Return Value

array

array prepareQueryOrNewObj(array $query, bool $isNewObj = false)

Prepares the query criteria or new document object.

PHP field names and types will be converted to those used by MongoDB.

Parameters

array $query
bool $isNewObj

Return Value

array