Interface UnitOfWork
- All Superinterfaces:
- ConfigurationHolder,- MetamodelProvider,- Wrapper
- All Known Implementing Classes:
- AbstractUnitOfWork,- ChangeTrackingUnitOfWork,- OnCommitChangePropagatingUnitOfWork,- ReadOnlyUnitOfWork
All interactions with objects managed in a persistence context are tracked by its corresponding UoW and on commit, the UoW propagates them into the repository.
- 
Method SummaryModifier and TypeMethodDescriptionvoidattributeChanged(Object entity, FieldSpecification<?, ?> fieldSpec) Persists changed value of the specified field.voidattributeChanged(Object entity, Field f) Persists changed value of the specified field.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.createIndirectCollection(Object collection, Object owner, Field field) Creates an indirect collection that wraps the specified collection instance and propagates changes to this persistence context.getCloneForOriginal(Object original) Finds clone of the specified original object.Gets repository contexts available to this session.Gets aCriteriaBuilderinstance for building Criteria API queries.Gets the registry of entity load state descriptors.<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.booleanisActive()Is this Unit of Work active?booleanisConsistent(URI context) Checks whether the specified repository context is consistent.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.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.<T> ObjectloadEntityField(T entity, FieldSpecification<? super T, ?> fieldSpec) Loads value of the specified field for the specified entity.<T> TmergeDetached(T entity, Descriptor descriptor) Merges the state of the given entity into the current persistence context.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.<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 object, Descriptor descriptor) Register an existing object in this Unit of Work.registerExistingObject(Object object, CloneRegistrationDescriptor registrationDescriptor) Register an existing object in this Unit of Work.voidregisterNewObject(Object object, Descriptor descriptor) Registers the specified new object in this Unit of Work.voidrelease()Releases this unit of work.voidremoveObject(Object object) Remove the given object from the repository.voidremoveObjectFromCache(Object object, 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.voidunregisterObject(Object object) Detaches the specified registered object from this Unit of Work.voidWrites any uncommitted changes into the ontology.Methods inherited from interface cz.cvut.kbss.jopa.sessions.ConfigurationHoldergetConfigurationMethods inherited from interface cz.cvut.kbss.jopa.sessions.MetamodelProvidergetMetamodel, getNamedQueryManager, getResultSetMappingManager, isEntityType
- 
Method Details- 
clearvoid clear()Clears this Unit of Work.
- 
beginvoid begin()Notifies this Unit of Work that a transaction has begun.
- 
commitvoid commit()Commit changes to the repository.
- 
rollbackvoid rollback()Rolls back changes done since last commit.- See Also:
 
- 
containsChecks whether the specified entity is managed in this Unit of Work.- Parameters:
- entity- Entity to check
- Returns:
- true if entity is managed, false otherwise
 
- 
isActiveboolean isActive()Is this Unit of Work active?- Returns:
- boolean
 
- 
isInTransactionboolean isInTransaction()Returns true if thisUnitOfWorkrepresents the persistence context of a currently running transaction.- Returns:
- True if in an active transaction
 
- 
isFlushingChangesboolean isFlushingChanges()Returns true if this Unit of Work is currently flushing changes to the repository.- Returns:
- trueif the UoW is flushing changes,- falseotherwise
 
- 
isObjectManagedReturn 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. - Parameters:
- entity- Object to check
- Returns:
- truewhen the entity is managed,- falseotherwise
 
- 
isObjectNewChecks whether the specified entity has been registered in this Unit of Work as a new object for persist.- Parameters:
- entity- Object to check
- Returns:
- truewhen entity is managed and new,- falseotherwise
- See Also:
 
- 
isConsistentChecks whether the specified repository context is consistent.- Parameters:
- context- Context URI,- nullindicates the whole repository should be checked
- Returns:
- trueif the context is consistent,- falseotherwise
- Throws:
- OWLPersistenceException- If an ontology access error occurs
 
- 
loadEntityFieldLoads value of the specified field for the specified entity.The value is set on the entity. - Parameters:
- entity- The entity to load field for
- fieldSpec- Metamodel element representing the field to load
- Returns:
- The loaded field value
- Throws:
- NullPointerException- If- entityor- fieldis- null
- OWLPersistenceException- If an error occurs, this may be e.g. that the field is not present on the entity, an ontology access error occurred etc.
 
- 
mergeDetachedMerges 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.- Parameters:
- entity- entity instance
- descriptor- Entity descriptor, specifies repository context
- Returns:
- the managed instance that the state was merged to
- Throws:
- NullPointerException- If- entityor- repositoryis- null
 
- 
readObjectRetrieves 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. - 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
- Throws:
- NullPointerException- If- cls,- identifieror- repositoryis- null
- OWLPersistenceException- If an error occurs during object loading
 
- 
readObjectWithoutRegistrationReads 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. - 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
 
- 
readObjectFromAxiomsReads an object from the specified axioms.It is assumed the axioms correspond to the provided descriptor. - 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
 
- 
getReferenceRetrieves a reference to an object with the specified identifier.A reference is permitted to have its state fetched lazily. - 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
- Throws:
- OWLPersistenceException- If an error occurs during object loading
 
- 
registerExistingObjectRegister an existing object in this Unit of Work.This is a shortcut for registerExistingObject(Object, CloneRegistrationDescriptor).- Parameters:
- object- Object
- descriptor- Entity descriptor identifying repository contexts
- Returns:
- Registered clone of the specified object
- See Also:
 
- 
registerExistingObjectRegister 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. - Parameters:
- object- Object
- registrationDescriptor- Configuration of the registration
- Returns:
- Registered clone of the specified object
 
- 
registerNewObjectRegisters the specified new object in this Unit of Work.The object will be persisted into the context specified by descriptor.- Parameters:
- object- The object to register
- descriptor- Entity descriptor
- Throws:
- NullPointerException- If- entityor- contextis- null
- OWLPersistenceException- If- contextis not a valid context URI or if an error during registration occurs
 
- 
removeObjectRemove the given object from the repository.- Parameters:
- object- Object to remove
 
- 
restoreRemovedObjectRestores the specified removed object.This means it is reinstated as a managed entity and reinserted into the repository. - Parameters:
- entity- The object to restore
 
- 
putObjectIntoCachePuts the specified object into the live object cache.- Parameters:
- identifier- Object identifier
- entity- Object to cache
- descriptor- Descriptor of repository context
 
- 
removeObjectFromCacheRemoves the specified object from the live object cache.This is particularly meant for merging deleted objects from transactions. - Parameters:
- object- Object to remove from cache
- context- Entity context URI
 
- 
releasevoid release()Releases this unit of work.Releasing an active Unit of Work with uncommitted changes causes all pending changes to be discarded. 
- 
refreshObject<T> void refreshObject(T object) Refreshes the state of the specified object from the repository, overwriting any changes made to it.- Type Parameters:
- T- Object type
- Parameters:
- object- The object to revert
- Throws:
- IllegalArgumentException- If the object is not managed
 
- 
getCloneForOriginalFinds clone of the specified original object.- Parameters:
- original- The original object whose clone we are looking for
- Returns:
- The clone or null, if there is none
 
- 
unregisterObjectDetaches the specified registered object from this Unit of Work.- Parameters:
- object- Clone to detach
 
- 
writeUncommittedChangesvoid writeUncommittedChanges()Writes any uncommitted changes into the ontology.
- 
getContextsGets repository contexts available to this session.- Returns:
- Unmodifiable list of context URIs
 
- 
getLoadStateRegistryLoadStateDescriptorRegistry getLoadStateRegistry()Gets the registry of entity load state descriptors.- Returns:
- LoadStateDescriptorRegistryfor this persistence context
 
- 
isLoadedGets the load status of the specified attribute on the specified entity.- Parameters:
- entity- Entity instance
- attributeName- Attribute whose load status is to be determined
- Returns:
- Attribute load status
- See Also:
 
- 
isLoadedGets the load status of the specified entity.- Parameters:
- entity- Entity whose load status is to be determined.
- Returns:
- Entity load status
- See Also:
 
- 
getStateGets 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.- Parameters:
- entity- Entity whose state to resolve
- Returns:
- Entity state
 
- 
getStateGets the lifecycle state of the specified entity with respect to a repository context indicated by the specified descriptor.- Parameters:
- entity- Entity whose state to resolve
- descriptor- Descriptor of repository contexts
- Returns:
- Entity state
 
- 
isInferredChecks 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. - 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
 
- 
attributeChangedPersists changed value of the specified field.- Parameters:
- entity- Entity with changes (the clone)
- f- The field whose value has changed
- Throws:
- IllegalStateException- If this UoW is not in transaction
- See Also:
 
- 
attributeChangedPersists changed value of the specified field.- Parameters:
- entity- Entity with changes (the clone)
- fieldSpec- Metamodel element representing the attribute that changed
- Throws:
- IllegalStateException- If this UoW is not in transaction
 
- 
createIndirectCollectionCreates an indirect collection that wraps the specified collection instance and propagates changes to this persistence context.- Parameters:
- collection- Collection to be proxied
- owner- Collection owner instance
- field- Field filled with the collection
- Returns:
- Indirect collection
 
- 
sparqlQueryFactorySparqlQueryFactory sparqlQueryFactory()Gets aSparqlQueryFactoryinstance associated with this persistence context.- Returns:
- SPARQL query factory
 
- 
getCriteriaBuilderCriteriaBuilder getCriteriaBuilder()Gets aCriteriaBuilderinstance for building Criteria API queries.- Returns:
- Criteria query builder
 
 
-