Version: 4.3

Class: UnitOfWork

Hierarchy

  • UnitOfWork

Constructors

constructor

+ new UnitOfWork(em: EntityManager): UnitOfWork

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:31

Parameters:

NameType
emEntityManager

Returns: UnitOfWork

Properties

changeSetComputer

Private Readonly changeSetComputer: ChangeSetComputer = new ChangeSetComputer(this.em.getValidator(), this.collectionUpdates, this.removeStack, this.metadata, this.platform, this.em.config)

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:29


changeSetPersister

Private Readonly changeSetPersister: ChangeSetPersister = new ChangeSetPersister(this.em.getDriver(), this.metadata, this.em.config.getHydrator(this.metadata), this.em.getEntityFactory(), this.em.config)

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:30


changeSets

Private Readonly changeSets: Map<AnyEntity<any>, ChangeSet<AnyEntity<any>>> = new Map<AnyEntity, ChangeSet<AnyEntity>>()

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:22


collectionUpdates

Private Readonly collectionUpdates: Set<Collection<AnyEntity<any>, unknown>> = new Set<Collection<AnyEntity>>()

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:23


comparator

Private Readonly comparator: EntityComparator = this.em.getComparator()

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:28


em

Private Readonly em: EntityManager

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:33


eventManager

Private Readonly eventManager: EventManager = this.em.getEventManager()

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:27


extraUpdates

Private Readonly extraUpdates: Set<[AnyEntity<any>, string, AnyEntity<any> | Reference<any> | Collection<any, unknown>]> = new Set<[AnyEntity, string, AnyEntity | Reference<any> | Collection<any>]>()

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:24


identityMap

Private Readonly identityMap: IdentityMap = new IdentityMap()

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:17

map of references to managed entities


metadata

Private Readonly metadata: MetadataStorage = this.em.getMetadata()

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:25


orphanRemoveStack

Private Readonly orphanRemoveStack: Set<AnyEntity<any>> = new Set<AnyEntity>()

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:21


persistStack

Private Readonly persistStack: Set<AnyEntity<any>> = new Set<AnyEntity>()

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:19


platform

Private Readonly platform: Platform = this.em.getDriver().getPlatform()

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:26


removeStack

Private Readonly removeStack: Set<AnyEntity<any>> = new Set<AnyEntity>()

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:20


working

Private working: boolean = false

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:31

Methods

cancelOrphanRemoval

cancelOrphanRemoval(entity: AnyEntity): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:291

Parameters:

NameType
entityAnyEntity

Returns: void


cascade

Privatecascade<T>(entity: T, type: Cascade, visited: WeakSet<AnyEntity>, options?: { checkRemoveStack?: boolean }): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:418

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameTypeDefault value
entityT-
typeCascade-
visitedWeakSet<AnyEntity>-
options{ checkRemoveStack?: boolean }{}

Returns: void


cascadeReference

PrivatecascadeReference<T>(entity: T, prop: EntityProperty<T>, type: Cascade, visited: WeakSet<AnyEntity>, options: { checkRemoveStack?: boolean }): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:436

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT
propEntityProperty<T>
typeCascade
visitedWeakSet<AnyEntity>
options{ checkRemoveStack?: boolean }

Returns: void


checkOrphanRemoval

PrivatecheckOrphanRemoval<T>(changeSet: ChangeSet<T>): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:323

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
changeSetChangeSet<T>

Returns: void


clear

clear(): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:251

Returns: void


commit

commit(): Promise<void>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:205

Returns: Promise<void>


commitCreateChangeSets

PrivatecommitCreateChangeSets<T>(changeSets: ChangeSet<T>[], ctx?: Transaction): Promise<void>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:568

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
changeSetsChangeSet<T>[]
ctx?Transaction

Returns: Promise<void>


commitDeleteChangeSets

PrivatecommitDeleteChangeSets<T>(changeSets: ChangeSet<T>[], ctx?: Transaction): Promise<void>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:625

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
changeSetsChangeSet<T>[]
ctx?Transaction

Returns: Promise<void>


commitUpdateChangeSets

PrivatecommitUpdateChangeSets<T>(changeSets: ChangeSet<T>[], ctx?: Transaction, batched?: boolean): Promise<void>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:608

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameTypeDefault value
changeSetsChangeSet<T>[]-
ctx?Transaction-
batchedbooleantrue

Returns: Promise<void>


computeChangeSet

computeChangeSet<T>(entity: T): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:147

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT

Returns: void


computeChangeSets

computeChangeSets(): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:263

Returns: void


findExtraUpdates

PrivatefindExtraUpdates<T>(changeSet: ChangeSet<T>, props: EntityProperty<T>[]): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:591

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
changeSetChangeSet<T>
propsEntityProperty<T>[]

Returns: void


findNewEntities

PrivatefindNewEntities<T>(entity: T, visited?: WeakSet<AnyEntity<any>>): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:295

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameTypeDefault value
entityT-
visitedWeakSet<AnyEntity<any>>new WeakSet<AnyEntity>()

Returns: void


fixMissingReference

PrivatefixMissingReference<T>(entity: T, prop: EntityProperty<T>): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:512

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT
propEntityProperty<T>

Returns: void


getById

getById<T>(entityName: string, id: Primary<T> | Primary<T>[]): T

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:80

Returns entity from the identity map. For composite keys, you need to pass an array of PKs in the same order as they are defined in meta.primaryKeys.

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityNamestring
idPrimary<T> | Primary<T>[]

Returns: T


getChangeSetGroups

PrivategetChangeSetGroups(): object

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:645

Orders change sets so FK constrains are maintained, ensures stable order (needed for node < 11)

Returns: object


getChangeSets

getChangeSets(): ChangeSet<AnyEntity>[]

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:135

Returns: ChangeSet<AnyEntity>[]


getCollectionUpdates

getCollectionUpdates(): Collection<AnyEntity>[]

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:139

Returns: Collection<AnyEntity>[]


getCommitOrder

PrivategetCommitOrder(): string[]

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:661

Returns: string[]


getExtraUpdates

getExtraUpdates(): Set<[AnyEntity, string, AnyEntity | Reference<any> | Collection<any>]>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:143

Returns: Set<[AnyEntity, string, AnyEntity | Reference<any> | Collection<any>]>


getIdentityMap

getIdentityMap(): IdentityMap

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:100

Returns map of all managed entities.

Returns: IdentityMap


getOriginalEntityData

getOriginalEntityData<T>(): AnyEntity[]

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:107

Returns stored snapshot of entity state that is used for change set computation.

deprecated use uow.getOriginalEntityData(entity)

Type parameters:

NameType
TAnyEntity<T>

Returns: AnyEntity[]

getOriginalEntityData<T>(entity: T): EntityData<T> | undefined

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:112

Returns stored snapshot of entity state that is used for change set computation.

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT

Returns: EntityData<T> | undefined


getPersistStack

getPersistStack(): Set<AnyEntity>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:127

Returns: Set<AnyEntity>


getRemoveStack

getRemoveStack(): Set<AnyEntity>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:131

Returns: Set<AnyEntity>


initIdentifier

PrivateinitIdentifier<T>(entity: T): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:338

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT

Returns: void


isCollectionSelfReferenced

PrivateisCollectionSelfReferenced(collection: Collection<AnyEntity>, visited: WeakSet<AnyEntity>): boolean

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:464

Parameters:

NameType
collectionCollection<AnyEntity>
visitedWeakSet<AnyEntity>

Returns: boolean


lock

lock<T>(entity: T, mode: LockMode, version?: number | Date): Promise<void>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:237

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT
modeLockMode
version?number | Date

Returns: Promise<void>


lockOptimistic

PrivatelockOptimistic<T>(entity: T, meta: EntityMetadata<T>, version: number | Date): Promise<void>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:490

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT
metaEntityMetadata<T>
versionnumber | Date

Returns: Promise<void>


lockPessimistic

PrivatelockPessimistic<T>(entity: T, mode: LockMode): Promise<void>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:482

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT
modeLockMode

Returns: Promise<void>


merge

merge<T>(entity: T, visited?: WeakSet<AnyEntity>): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:35

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT
visited?WeakSet<AnyEntity>

Returns: void


persist

persist<T>(entity: T, visited?: WeakSet<AnyEntity<any>>, checkRemoveStack?: boolean): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:177

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameTypeDefault value
entityT-
visitedWeakSet<AnyEntity<any>>new WeakSet<AnyEntity>()
checkRemoveStackbooleanfalse

Returns: void


persistToDatabase

PrivatepersistToDatabase(groups: {}, tx?: Transaction): Promise<void>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:528

Parameters:

NameType
groups{}
tx?Transaction

Returns: Promise<void>


postCommitCleanup

PrivatepostCommitCleanup(): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:408

Returns: void


processReference

PrivateprocessReference<T>(parent: T, prop: EntityProperty<T>, reference: any, visited: WeakSet<AnyEntity>): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:348

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
parentT
propEntityProperty<T>
referenceany
visitedWeakSet<AnyEntity>

Returns: void


processToManyReference

PrivateprocessToManyReference<T>(reference: Collection<AnyEntity>, visited: WeakSet<AnyEntity>, parent: T, prop: EntityProperty<T>): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:372

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
referenceCollection<AnyEntity>
visitedWeakSet<AnyEntity>
parentT
propEntityProperty<T>

Returns: void


processToOneReference

PrivateprocessToOneReference<T>(reference: any, visited: WeakSet<AnyEntity>, parent: T, prop: EntityProperty<T>): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:360

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
referenceany
visitedWeakSet<AnyEntity>
parentT
propEntityProperty<T>

Returns: void


recomputeSingleChangeSet

recomputeSingleChangeSet<T>(entity: T): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:161

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT

Returns: void


registerManaged

registerManaged<T>(entity: T, data?: EntityData<T>, refresh?: boolean, newEntity?: boolean): T

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:60

internal

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameType
entityT
data?EntityData<T>
refresh?boolean
newEntity?boolean

Returns: T


remove

remove(entity: AnyEntity, visited?: WeakSet<AnyEntity<any>>): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:191

Parameters:

NameTypeDefault value
entityAnyEntity-
visitedWeakSet<AnyEntity<any>>new WeakSet<AnyEntity>()

Returns: void


runHooks

PrivaterunHooks<T>(type: EventType, changeSet: ChangeSet<T>, sync?: boolean): Promise<unknown>

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:385

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameTypeDefault value
typeEventType-
changeSetChangeSet<T>-
syncbooleanfalse

Returns: Promise<unknown>


scheduleOrphanRemoval

scheduleOrphanRemoval(entity: AnyEntity): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:287

Parameters:

NameType
entityAnyEntity

Returns: void


shouldCascade

PrivateshouldCascade(prop: EntityProperty, type: Cascade): boolean

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:469

Parameters:

NameType
propEntityProperty
typeCascade

Returns: boolean


tryGetById

tryGetById<T>(entityName: string, where: FilterQuery<T>, strict?: boolean): T | null

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:87

Type parameters:

NameType
TAnyEntity<T>

Parameters:

NameTypeDefault value
entityNamestring-
whereFilterQuery<T>-
strictbooleantrue

Returns: T | null


unsetIdentity

unsetIdentity(entity: AnyEntity): void

Defined in packages/core/src/unit-of-work/UnitOfWork.ts:256

Parameters:

NameType
entityAnyEntity

Returns: void

Last updated on by Martin Adámek