Class AbstractUnitOfWork
- All Implemented Interfaces:
- ConfigurationHolder,- MetamodelProvider,- UnitOfWork,- Wrapper
- Direct Known Subclasses:
- ChangeTrackingUnitOfWork,- OnCommitChangePropagatingUnitOfWork,- ReadOnlyUnitOfWork
- 
Field SummaryFieldsFields inherited from class cz.cvut.kbss.jopa.sessions.AbstractSessionconfiguration
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected ConnectionWrapperAcquires connection to the underlying ontology storage.voidbegin()Notifies this Unit of Work that a transaction has begun.voidclear()Clears this Unit of Work.voidcommit()Commit changes to the repository.booleanChecks whether the specified entity is managed in this Unit of Work.protected static ObjectChangeSetcopyChangeSet(ObjectChangeSet changeSet, Object original, Object clone, Descriptor descriptor) protected <T> IdentifiableEntityType<T>entityType(Class<T> cls) protected voidevictAfterMerge(EntityType<?> et, URI identifier, Descriptor descriptor) getCloneForOriginal(Object original) Finds clone of the specified original.Gets repository contexts available to this session.Gets aCriteriaBuilderinstance for building Criteria API queries.protected <T> DescriptorgetFieldDescriptor(T entity, Field field, Descriptor entityDescriptor) protected <T> TgetInstanceForMerge(URI identifier, EntityType<T> et, Descriptor descriptor) Get the current live object cache.Gets the registry of entity load state descriptors.<T> TgetManagedOriginal(Class<T> cls, Object identifier, Descriptor descriptor) Gets managed original with the specified identifier ornullif there is none matching.Gets the metamodelgetOriginal(Object clone) Tries to find the original object for the given clone.<T> TgetReference(Class<T> cls, Object identifier, Descriptor descriptor) Retrieves a reference to an object with the specified identifier.Gets the lifecycle state of the specified entity.getState(Object entity, Descriptor descriptor) Gets the lifecycle state of the specified entity with respect to a repository context indicated by the specified descriptor.booleanbooleanisActive()Is this Unit of Work active?booleanisConsistent(URI context) Checks whether the specified repository context is consistent.booleanisEntityType(Class<?> cls) Checks whether the specified class is an entity type.booleanReturns true if this Unit of Work is currently flushing changes to the repository.<T> booleanisInferred(T entity, FieldSpecification<? super T, ?> attribute, Object value) Checks whether the specified attribute value of the specified entity is inferred in the underlying repository.protected booleanisInRepository(Descriptor descriptor, Object entity) booleanReturns true if thisUnitOfWorkrepresents the persistence context of a currently running transaction.Gets the load status of the specified entity.Gets the load status of the specified attribute on the specified entity.booleanisObjectManaged(Object entity) Return true if the given entity is managed.booleanisObjectNew(Object entity) Checks whether the specified entity has been registered in this Unit of Work as a new object for persist.boolean<T> ObjectloadEntityField(T entity, FieldSpecification<? super T, ?> fieldSpec) Loads value of the specified field for the specified entity.protected voidmarkCloneForDeletion(Object entity, Object identifier) <T> TmergeDetached(T entity, Descriptor descriptor) Merges the state of the given entity into the current persistence context.protected ObjectChangeSetprocessInferredValueChanges(ObjectChangeSet changeSet) voidputObjectIntoCache(Object identifier, Object entity, Descriptor descriptor) Puts the specified object into the live object cache.<T> TreadObject(Class<T> cls, Object identifier, Descriptor descriptor) Retrieves object with the specified identifier.<T> TreadObjectFromAxioms(Class<T> cls, Collection<Axiom<?>> axioms, Descriptor descriptor) Reads an object from the specified axioms.protected <T> TreadObjectInternal(Class<T> cls, Object identifier, Descriptor descriptor) <T> TreadObjectWithoutRegistration(Class<T> cls, Object identifier, Descriptor descriptor) Reads an object but does not register it with this persistence context.<T> voidrefreshObject(T object) Refreshes the state of the specified object from the repository, overwriting any changes made to it.registerExistingObject(Object entity, Descriptor descriptor) Register an existing object in this Unit of Work.registerExistingObject(Object entity, CloneRegistrationDescriptor registrationDescriptor) Register an existing object in this Unit of Work.voidregisterNewObject(Object entity, Descriptor descriptor) Registers the specified new object in this Unit of Work.voidregisterOriginalForNewClone(Object clone, Object original) Registers the specified original for the specified clone, assuming the clone is a new object.voidrelease()Releases this unit of work.protected voidRemovesIndirectWrapperandLazyLoadingProxyinstances from the specified entity (if present).voidremoveObjectFromCache(Object toRemove, URI context) Removes the specified object from the live object cache.voidrestoreRemovedObject(Object entity) Restores the specified removed object.voidrollback()Rolls back changes done since last commit.Gets aSparqlQueryFactoryinstance associated with this persistence context.Gets basic object info for logging.protected voidvoidunregisterObject(Object object) Detaches the specified registered object from this Unit of Work.<T> TUnwraps implementation of the specified class.voidWrites any uncommitted changes into the ontology.Methods inherited from class cz.cvut.kbss.jopa.sessions.AbstractSessiongetConfigurationMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface cz.cvut.kbss.jopa.sessions.ConfigurationHoldergetConfigurationMethods inherited from interface cz.cvut.kbss.jopa.sessions.MetamodelProvidergetNamedQueryManager, getResultSetMappingManagerMethods inherited from interface cz.cvut.kbss.jopa.sessions.UnitOfWorkattributeChanged, attributeChanged, createIndirectCollection, removeObject
- 
Field Details- 
LOGprotected static final org.slf4j.Logger LOG
 
- 
- 
Constructor Details- 
AbstractUnitOfWork
 
- 
- 
Method Details- 
acquireConnectionDescription copied from class:AbstractSessionAcquires connection to the underlying ontology storage.- Specified by:
- acquireConnectionin class- AbstractSession
- Returns:
- Connection
 
- 
releasepublic void release()Description copied from interface:UnitOfWorkReleases this unit of work.Releasing an active Unit of Work with uncommitted changes causes all pending changes to be discarded. - Specified by:
- releasein interface- UnitOfWork
 
- 
clearpublic void clear()Description copied from interface:UnitOfWorkClears this Unit of Work.- Specified by:
- clearin interface- UnitOfWork
 
- 
getLiveObjectCacheDescription copied from class:AbstractSessionGet the current live object cache.This manager represents the second level cache. - Specified by:
- getLiveObjectCachein class- AbstractSession
- Returns:
- Second level cache manager
 
- 
isActivepublic boolean isActive()Description copied from interface:UnitOfWorkIs this Unit of Work active?- Specified by:
- isActivein interface- UnitOfWork
- Returns:
- boolean
 
- 
beginpublic void begin()Description copied from interface:UnitOfWorkNotifies this Unit of Work that a transaction has begun.- Specified by:
- beginin interface- UnitOfWork
 
- 
commitpublic void commit()Description copied from interface:UnitOfWorkCommit changes to the repository.- Specified by:
- commitin interface- UnitOfWork
 
- 
rollbackpublic void rollback()Description copied from interface:UnitOfWorkRolls back changes done since last commit.- Specified by:
- rollbackin interface- UnitOfWork
- See Also:
 
- 
containsDescription copied from interface:UnitOfWorkChecks whether the specified entity is managed in this Unit of Work.- Specified by:
- containsin interface- UnitOfWork
- Parameters:
- entity- Entity to check
- Returns:
- true if entity is managed, false otherwise
 
- 
readObjectDescription copied from interface:UnitOfWorkRetrieves object with the specified identifier.The object as well as its fields are looked for in contexts specified by the descriptor. The result is then cast to the specified type. - Specified by:
- readObjectin interface- UnitOfWork
- Parameters:
- cls- The type of the returned object
- identifier- Instance identifier
- descriptor- Entity descriptor
- Returns:
- The retrieved object or nullif there is no object with the specified identifier in the specified repository
 
- 
readObjectInternal
- 
isInRepository
- 
getReferenceDescription copied from interface:UnitOfWorkRetrieves a reference to an object with the specified identifier.A reference is permitted to have its state fetched lazily. - Specified by:
- getReferencein interface- UnitOfWork
- Type Parameters:
- T- Entity type
- Parameters:
- cls- The type of the returned object
- identifier- Instance identifier
- descriptor- Entity descriptor
- Returns:
- The retrieved object or nullif none can be found
 
- 
readObjectWithoutRegistrationDescription copied from interface:UnitOfWorkReads an object but does not register it with this persistence context.Useful when the caller knows the object will be registered eventually by another routine. - Specified by:
- readObjectWithoutRegistrationin interface- UnitOfWork
- Parameters:
- cls- Expected result class
- identifier- Object identifier
- descriptor- Entity descriptor
- Returns:
- The retrieved object or nullif there is no object with the specified identifier in the specified repository
 
- 
readObjectFromAxiomsDescription copied from interface:UnitOfWorkReads an object from the specified axioms.It is assumed the axioms correspond to the provided descriptor. - Specified by:
- readObjectFromAxiomsin interface- UnitOfWork
- Type Parameters:
- T- Return type
- Parameters:
- cls- Expected result class
- axioms- Axioms representing the object
- descriptor- Entity descriptor
- Returns:
- The retrieved object or nullif no object of the expected target class can be reconstructed
 
- 
getStateDescription copied from interface:UnitOfWorkGets the lifecycle state of the specified entity.Note that since no repository is specified we can only determine if the entity is managed or removed. Therefore, if the case is different this method returns EntityState.NOT_MANAGED.- Specified by:
- getStatein interface- UnitOfWork
- Parameters:
- entity- Entity whose state to resolve
- Returns:
- Entity state
 
- 
getStateDescription copied from interface:UnitOfWorkGets the lifecycle state of the specified entity with respect to a repository context indicated by the specified descriptor.- Specified by:
- getStatein interface- UnitOfWork
- Parameters:
- entity- Entity whose state to resolve
- descriptor- Descriptor of repository contexts
- Returns:
- Entity state
 
- 
isObjectNewDescription copied from interface:UnitOfWorkChecks whether the specified entity has been registered in this Unit of Work as a new object for persist.- Specified by:
- isObjectNewin interface- UnitOfWork
- Parameters:
- entity- Object to check
- Returns:
- truewhen entity is managed and new,- falseotherwise
- See Also:
 
- 
isObjectManagedDescription copied from interface:UnitOfWorkReturn true if the given entity is managed.This means it is tracked by this persistence context either as a new object or an existing object loaded from the repository. - Specified by:
- isObjectManagedin interface- UnitOfWork
- Parameters:
- entity- Object to check
- Returns:
- truewhen the entity is managed,- falseotherwise
 
- 
mergeDetachedDescription copied from interface:UnitOfWorkMerges the state of the given entity into the current persistence context.The descriptorargument specified the ontology contexts into which the detached entity and its fields belong and should be merged.- Specified by:
- mergeDetachedin interface- UnitOfWork
- Parameters:
- entity- entity instance
- descriptor- Entity descriptor, specifies repository context
- Returns:
- the managed instance that the state was merged to
 
- 
registerExistingObjectDescription copied from interface:UnitOfWorkRegister an existing object in this Unit of Work.This is a shortcut for UnitOfWork.registerExistingObject(Object, CloneRegistrationDescriptor).- Specified by:
- registerExistingObjectin interface- UnitOfWork
- Parameters:
- entity- Object
- descriptor- Entity descriptor identifying repository contexts
- Returns:
- Registered clone of the specified object
- See Also:
 
- 
registerExistingObjectpublic Object registerExistingObject(Object entity, CloneRegistrationDescriptor registrationDescriptor) Description copied from interface:UnitOfWorkRegister an existing object in this Unit of Work.Creates a working clone of the specified object according to the configuration and puts the given object into this Unit of Work cache. - Specified by:
- registerExistingObjectin interface- UnitOfWork
- Parameters:
- entity- Object
- registrationDescriptor- Configuration of the registration
- Returns:
- Registered clone of the specified object
 
- 
entityType
- 
getOriginalTries to find the original object for the given clone. It searches the existing objects, new objects and deleted objects.- Parameters:
- clone- Object
- Returns:
- The original object for the given clone
 
- 
registerOriginalForNewCloneRegisters the specified original for the specified clone, assuming the clone is a new object.This method must be called during commit when new objects are persisted so that they can be referenced by other objects. - Parameters:
- clone- Already registered clone
- original- Original to register
 
- 
getManagedOriginalGets managed original with the specified identifier ornullif there is none matching.Descriptor is used to check repository context validity. - Parameters:
- cls- Return type of the original
- identifier- Instance identifier
- descriptor- Repository descriptor
- Returns:
- Original object managed by this UoW or nullif this UoW doesn't contain a matching instance
 
- 
getCloneForOriginalFinds clone of the specified original.- Specified by:
- getCloneForOriginalin interface- UnitOfWork
- Parameters:
- original- The original object whose clone we are looking for
- Returns:
- The clone or null, if there is none
 
- 
hasChangespublic boolean hasChanges()
- 
processInferredValueChanges
- 
getInstanceForMerge
- 
evictAfterMerge
- 
copyChangeSetprotected static ObjectChangeSet copyChangeSet(ObjectChangeSet changeSet, Object original, Object clone, Descriptor descriptor) 
- 
refreshObjectpublic <T> void refreshObject(T object) Description copied from interface:UnitOfWorkRefreshes the state of the specified object from the repository, overwriting any changes made to it.- Specified by:
- refreshObjectin interface- UnitOfWork
- Type Parameters:
- T- Object type
- Parameters:
- object- The object to revert
 
- 
registerNewObjectDescription copied from interface:UnitOfWorkRegisters the specified new object in this Unit of Work.The object will be persisted into the context specified by descriptor.- Specified by:
- registerNewObjectin interface- UnitOfWork
- Parameters:
- entity- The object to register
- descriptor- Entity descriptor
 
- 
restoreRemovedObjectDescription copied from interface:UnitOfWorkRestores the specified removed object.This means it is reinstated as a managed entity and reinserted into the repository. - Specified by:
- restoreRemovedObjectin interface- UnitOfWork
- Parameters:
- entity- The object to restore
 
- 
unregisterObjectDescription copied from interface:UnitOfWorkDetaches the specified registered object from this Unit of Work.- Specified by:
- unregisterObjectin interface- UnitOfWork
- Parameters:
- object- Clone to detach
 
- 
unregisterEntityFromOntologyContext
- 
removeIndirectWrappersAndProxiesRemovesIndirectWrapperandLazyLoadingProxyinstances from the specified entity (if present).- Parameters:
- entity- The entity to remove indirect wrappers from
 
- 
writeUncommittedChangespublic void writeUncommittedChanges()Description copied from interface:UnitOfWorkWrites any uncommitted changes into the ontology.- Specified by:
- writeUncommittedChangesin interface- UnitOfWork
 
- 
getMetamodelDescription copied from interface:MetamodelProviderGets the metamodel- Specified by:
- getMetamodelin interface- MetamodelProvider
- Returns:
- Metamodel
 
- 
isEntityTypeDescription copied from interface:MetamodelProviderChecks whether the specified class is an entity type.- Specified by:
- isEntityTypein interface- MetamodelProvider
- Parameters:
- cls- The class to check
- Returns:
- Whether type is managed
 
- 
isInTransactionpublic boolean isInTransaction()Description copied from interface:UnitOfWorkReturns true if thisUnitOfWorkrepresents the persistence context of a currently running transaction.- Specified by:
- isInTransactionin interface- UnitOfWork
- Returns:
- True if in an active transaction
 
- 
isFlushingChangespublic boolean isFlushingChanges()Description copied from interface:UnitOfWorkReturns true if this Unit of Work is currently flushing changes to the repository.- Specified by:
- isFlushingChangesin interface- UnitOfWork
- Returns:
- trueif the UoW is flushing changes,- falseotherwise
 
- 
loadEntityFieldDescription copied from interface:UnitOfWorkLoads value of the specified field for the specified entity.The value is set on the entity. - Specified by:
- loadEntityFieldin interface- UnitOfWork
- Parameters:
- entity- The entity to load field for
- fieldSpec- Metamodel element representing the field to load
- Returns:
- The loaded field value
 
- 
stringifyGets basic object info for logging.This works around using Object.toString()for entities, which could inadvertently trigger lazy field fetching and cause an infinite field loading loop.- Parameters:
- object- Object to stringify
- Returns:
- String info about the specified object
 
- 
getFieldDescriptor
- 
putObjectIntoCacheDescription copied from interface:UnitOfWorkPuts the specified object into the live object cache.- Specified by:
- putObjectIntoCachein interface- UnitOfWork
- Parameters:
- identifier- Object identifier
- entity- Object to cache
- descriptor- Descriptor of repository context
 
- 
removeObjectFromCacheDescription copied from interface:UnitOfWorkRemoves the specified object from the live object cache.This is particularly meant for merging deleted objects from transactions. - Specified by:
- removeObjectFromCachein interface- UnitOfWork
- Parameters:
- toRemove- Object to remove from cache
- context- Entity context URI
 
- 
isConsistentDescription copied from interface:UnitOfWorkChecks whether the specified repository context is consistent.- Specified by:
- isConsistentin interface- UnitOfWork
- Parameters:
- context- Context URI,- nullindicates the whole repository should be checked
- Returns:
- trueif the context is consistent,- falseotherwise
 
- 
getContextsDescription copied from interface:UnitOfWorkGets repository contexts available to this session.- Specified by:
- getContextsin interface- UnitOfWork
- Returns:
- Unmodifiable list of context URIs
 
- 
isInferredDescription copied from interface:UnitOfWorkChecks whether the specified attribute value of the specified entity is inferred in the underlying repository.Note that given the nature of the repository implementation, this method may return true if the corresponding statement is both inferred and asserted. Also note that this method will use the descriptor associated with the specified entity in this persistence context to resolve the repository context, but some underlying repositories do not store inferences in data contexts, so the attribute context may be ignored. - Specified by:
- isInferredin interface- UnitOfWork
- Parameters:
- entity- Entity whose attribute to examine. Must be managed by this persistence context
- attribute- Attribute whose value to examine
- value- The value whose inference to examine
- Returns:
- trueif the entity attribute value is inferred,- falseotherwise
 
- 
isLoadedDescription copied from interface:UnitOfWorkGets the load status of the specified attribute on the specified entity.- Specified by:
- isLoadedin interface- UnitOfWork
- Parameters:
- entity- Entity instance
- attributeName- Attribute whose load status is to be determined
- Returns:
- Attribute load status
- See Also:
 
- 
isLoadedDescription copied from interface:UnitOfWorkGets the load status of the specified entity.- Specified by:
- isLoadedin interface- UnitOfWork
- Parameters:
- entity- Entity whose load status is to be determined.
- Returns:
- Entity load status
- See Also:
 
- 
sparqlQueryFactoryDescription copied from interface:UnitOfWorkGets aSparqlQueryFactoryinstance associated with this persistence context.- Specified by:
- sparqlQueryFactoryin interface- UnitOfWork
- Returns:
- SPARQL query factory
 
- 
getCriteriaBuilderDescription copied from class:AbstractSessionGets aCriteriaBuilderinstance for building Criteria API queries.- Specified by:
- getCriteriaBuilderin interface- UnitOfWork
- Specified by:
- getCriteriaBuilderin class- AbstractSession
- Returns:
- Criteria query builder
 
- 
getLoadStateRegistryDescription copied from interface:UnitOfWorkGets the registry of entity load state descriptors.- Specified by:
- getLoadStateRegistryin interface- UnitOfWork
- Returns:
- LoadStateDescriptorRegistryfor this persistence context
 
- 
unwrapDescription copied from interface:WrapperUnwraps implementation of the specified class.
- 
markCloneForDeletion
- 
isReadOnlypublic boolean isReadOnly()
 
-