Unit of Work

The methods from unit of work are commonly used indirectly by calling other methods from scope and entity manager. The unit of work static methods, such as isClean() or getObjectState() can be used to confirm or check the state of an object. To get the unit of work:

let unitOfWork = wetland.getManager().getUnitOfWork();

.cascadeSingle()

Prepares cascade for a single entity. This method is used in .prepareCascades().

unitOfWork.cascadeSingle(entity, 'property', entity['property'], mapping);

.clean()

Mark everything as clean, empty transactions and empty after commits.

unitOfWork.clean();

.clear()

Rolls back all affected objects. It reverts changes in dirty entities, un-persist new entities, un-stage deleted entities and refresh persisted entities.

unitOfWork.clear([entity1, entity2]);

.clearEntityState()

Clear the state for provided entity. Used by .clean() and .clear().

unitOfWork.clearEntityState(entity);

.commit()

Commits the current state to the database.

unitOfWork.commit();

.getCleanObjects()

Returns an array of objects marked as clean.

unitOfWork.getCleanObjects();

.getDeletedObjects()

Returns an array of objects marked as deleted.

unitOfWork.getDeletedObjects();

.getDirtyObjects()

Returns an array of objects marked as dirty.

unitOfWork.getDirtyObjects();

.getEntityManager()

Gets the entity manager used by this unit of work.

unitOfWork.getEntityManager();

.getNewObjects()

Returns an array of objects market as new.

unitOfWork.getNewObjects();

getObjectState(entity)

Static method to get the current state for provided entity as a string.

getObjectState(entity);

getRelationshipsChangedObjects()

Returns an array of objects marked as having relationship changes.

unitOfWork.getRelationshipsChangedObjects();

hasRelationChanges()

Static method that returns true if provided entity has relationship changes.

hasRelationChanges(entity);

isClean()

Static method that returns true if provided entity is clean.

isClean(entity);

isDirty()

Static method that returns true if provided entity is dirty.

isDirty(entity);

.prepareCascades()

This method prepares cascades for all stages changes. It is used internally by .commit().

unitOfWork.prepareCascades();

.prepareCascadesFor()

Prepares the cascades for provided entity. Used internally by .cascadeSingle() to cascade a property's child and by prepareCascades() to prepare cascades for every entity.

unitOfWork.prepareCascadesFor(entity);

.registerClean()

Registers an object as clean. This method is used by .clean() to mark all objects as clean.

unitOfWork.registerClean(object);

.registerCollectionChange()

Register a collection change between targetEntity and relationEntity. Used internally by .prepareCascadesFor() to link up a new relation with entity. Can also be used to remove a relationship.

unitOfWork.registerCollectionChange('relationship_added', targetEntity, 'property', relationEntity);

.registerDeleted()

Registers an object as deleted.

unitOfWork.registerDeleted(object);

.registerDirty()

Registers an object as dirty.

unitOfWork.registerDirty(object);

.registerNew()

Registers an object as new. Used by .cascadeSingle() to register new relation.

unitOfWork.registerNew(object);

.registerRelationChange()

Register a relationship change between targetEntity and relationEntity. Used by .prepareCascadesFor() to register relationship changes.

unitOfWork.registerRelationChange('relationship_added', targetEntity, 'property', relationEntity);

.setEntityState()

Sets the state of an entity. Used internally by .registerClean(), .registerNew(), .registerDirty() and .registerDeleted().

unitOfWork.setEntityState(entity, 'clean');

results matching ""

    No results matching ""