Permalink
Browse files

fix(unitofwork): separate cleaning tasks

  • Loading branch information...
edouardmenayde committed Sep 27, 2017
1 parent 83b08d5 commit 2406da061b3d9f9b334b4ad810ade5aea0b10f7e
Showing with 33 additions and 7 deletions.
  1. +1 −1 doc/API/unit-of-work.md
  2. +32 −6 src/UnitOfWork.ts
@@ -20,7 +20,7 @@ unitOfWork.cascadeSingle(entity, 'property', entity['property'], mapping);
{% method %}
## .clean()
Marks everything as clean.
Mark everything as clean, empty transactions and empty after commits.
{% common %}
```js
@@ -565,12 +565,18 @@ export class UnitOfWork {
.then(() => this.commitOrRollback(true))
.then(() => this.entityManager.getConfig().fetch('entityManager.refreshUpdated') && this.refreshDirty())
.then(() => this.entityManager.getConfig().fetch('entityManager.refreshCreated') && this.refreshNew())
.then(() => !skipClean && this.clean())
.then(() => !skipClean && this.cleanObjectsAndTransactions())
.then(() => !skipClean && this.processAfterCommit())
.then(() => !skipClean && this.cleanAfterCommit())
.catch(error => this.commitOrRollback(false, error));
}
private processAfterCommit() {
/**
* Execute post commit lifecyle callbacks.
*
* @return {Promise<Array<Function>>}
*/
private processAfterCommit(): Promise<Array<Function>> {
let methods = [];
this.afterCommit.forEach(action => {
@@ -1032,20 +1038,40 @@ export class UnitOfWork {
}
/**
* Mark everything as clean.
* Empty after commit.
*
* @returns {UnitOfWork}
* @return {Promise<void>}
*/
public clean(): Promise<void> {
private cleanAfterCommit(): Promise<void> {
this.afterCommit = [];
return Promise.resolve();
}
/**
* Mark everything as clean and empty transactions.
*
* @return {Promise<void>}
*/
private cleanObjectsAndTransactions(): Promise<void> {
this.newObjects.each(created => this.registerClean(created));
this.dirtyObjects.each(updated => this.registerClean(updated));
this.relationshipsChangedObjects.each(changed => this.registerClean(changed));
this.deletedObjects.each(deleted => this.clearEntityState(deleted));
this.deletedObjects = new ArrayCollection;
this.transactions = {};
this.afterCommit = [];
return Promise.resolve();
}
/**
* Mark everything as clean, empty transactions and empty after commits.
*
* @returns {UnitOfWork}
*/
public clean(): Promise<void> {
return this.cleanObjectsAndTransactions()
.then(() => this.cleanAfterCommit());
}
}

0 comments on commit 2406da0

Please sign in to comment.