Package org.springframework.versions
Interface LockingAndVersioningRepository<T,ID extends Serializable>
public interface LockingAndVersioningRepository<T,ID extends Serializable>
-
Method Summary
Modifier and TypeMethodDescriptionvoidDeletes a given entity version.voiddeleteAllVersions(T entity) Deletes all versions of the given entity.findAllVersions(S entity) Returns a list of all versions for the given entity.findAllVersions(S entity, org.springframework.data.domain.Sort sort) Returns a sorted list of all versions for the given entityDeprecated.findAllVersionsLatest(Class<S> entityClass) Returns the latest version of all entities.<S extends T>
SfindWorkingCopy(S entity) Returns the working copy for the given entity if it exists.<S extends T>
booleanisPrivateWorkingCopy(S entity) Returns whether the given entity is a private working copy, or not<S extends T>
Slock(S entity) Locks the entity and returns the updated entity (@Version and @LockOwner) attributes updated, otherwise returns null.<S extends T>
Ssave(S entity) Overridden implementation of save that enforces locking semantics<S extends T>
Sunlock(S entity) Unlocks the entity and returns the updated entity (@Version and @LockOwner) attributes updated, otherwise returns null<S extends T>
Sversion(S entity, VersionInfo info) Creates and returns a new version of the entity.<S extends T>
SworkingCopy(S entity) Creates and returns a new version of the entity as a private working copy.
-
Method Details
-
lock
Locks the entity and returns the updated entity (@Version and @LockOwner) attributes updated, otherwise returns null.- Type Parameters:
S- the type of entity- Parameters:
entity- the entity to be locked- Returns:
- the locked entity
- Throws:
SecurityException- if no authentication exists
-
unlock
Unlocks the entity and returns the updated entity (@Version and @LockOwner) attributes updated, otherwise returns null- Type Parameters:
S- the type of entity- Parameters:
entity- the entity to unlock- Returns:
- the unlocked entity
- Throws:
LockOwnerException- if the current principal is not the lock ownerSecurityException- if no authentication exists
-
save
Overridden implementation of save that enforces locking semantics- Type Parameters:
S- the type of entity- Parameters:
entity- the entity to save- Returns:
- the saved entity
- Throws:
LockOwnerException- if the current principal is not the lock ownerSecurityException- if no authentication exists
-
workingCopy
Creates and returns a new version of the entity as a private working copy. The given entity remains the latest version. This method requires the entity class to have a copy constructor that will be used to clone the entity in order to create the new working copy.- Type Parameters:
S- the type of entity- Parameters:
entity- the entity to base the new versionWithEntity on- Returns:
- the private working copy
- Throws:
LockingAndVersioningException- if entity is not the latestLockOwnerException- if the current principal is not the lock ownerSecurityException- if no authentication exists
-
version
Creates and returns a new version of the entity. This new version becomes the latest version in the version list. If the supplied entity is a private working copy, it will be promoted from a working copy to the new version. If the supplied entity is not a private working copy, the entity will be cloned in order to create the new version. This requires the entity class to have a copy constructor that is used for the cloning process.- Type Parameters:
S- the type of entity- Parameters:
entity- the entity to base the new versionWithEntity oninfo- the version info- Returns:
- the new versionWithEntity
- Throws:
LockingAndVersioningException- if entity is not the latestLockOwnerException- if the current principal is not the lock ownerSecurityException- if no authentication exists
-
findAllVersionsLatest
Deprecated.Returns the latest version of all entities. When extending LockingAndVersioningRepository this method would usually be preferred over CrudRepository's findAll that would find all versions of all entities.- Type Parameters:
S- the type of entity- Returns:
- list of latest versionWithEntity entities
-
findAllVersionsLatest
Returns the latest version of all entities. When extending LockingAndVersioningRepository this method would usually be preferred over CrudRepository's findAll that would find all versions of all entities.- Type Parameters:
S- the type of entity- Parameters:
entityClass- the type of the entity to find- Returns:
- list of latest versionWithEntity entities
-
findAllVersions
Returns a list of all versions for the given entity.- Type Parameters:
S- the type of entity- Parameters:
entity- the entity to find versions for- Returns:
- list of entity versions
-
findAllVersions
Returns a sorted list of all versions for the given entity- Type Parameters:
S- the type of entity- Parameters:
entity- the entity to find versions forsort- the sort to apply- Returns:
- list of entity versions
-
delete
Deletes a given entity version. The entity must be the head of the version list. If the entity is locked the lock will be carried over to the previous version when it becomes the new head.- Parameters:
entity- the entity to delete- Throws:
LockingAndVersioningException- if entity is not the latestLockOwnerException- if the current principal is not the lock ownerSecurityException- if no authentication exists
-
deleteAllVersions
Deletes all versions of the given entity.- Parameters:
entity- the entity to delete
-
isPrivateWorkingCopy
Returns whether the given entity is a private working copy, or not- Type Parameters:
S- the type of entity- Parameters:
entity- the entity to delete- Returns:
- true if entity is a private working copy, otherwise false
-
findWorkingCopy
Returns the working copy for the given entity if it exists.- Type Parameters:
S- the type of entity- Parameters:
entity- the entity whose working copy is required- Returns:
- the working copy if it exists, or null
-