Interface LockingAndVersioningRepository<T,ID extends Serializable>


public interface LockingAndVersioningRepository<T,ID extends Serializable>
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(T entity)
    Deletes a given entity version.
    void
    Deletes all versions of the given entity.
    <S extends T>
    List<S>
    findAllVersions(S entity)
    Returns a list of all versions for the given entity.
    <S extends T>
    List<S>
    findAllVersions(S entity, org.springframework.data.domain.Sort sort)
    Returns a sorted list of all versions for the given entity
    <S extends T>
    List<S>
    Deprecated. 
    <S extends T>
    List<S>
    findAllVersionsLatest(Class<S> entityClass)
    Returns the latest version of all entities.
    <S extends T>
    S
    findWorkingCopy(S entity)
    Returns the working copy for the given entity if it exists.
    <S extends T>
    boolean
    Returns whether the given entity is a private working copy, or not
    <S extends T>
    S
    lock(S entity)
    Locks the entity and returns the updated entity (@Version and @LockOwner) attributes updated, otherwise returns null.
    <S extends T>
    S
    save(S entity)
    Overridden implementation of save that enforces locking semantics
    <S extends T>
    S
    unlock(S entity)
    Unlocks the entity and returns the updated entity (@Version and @LockOwner) attributes updated, otherwise returns null
    <S extends T>
    S
    version(S entity, VersionInfo info)
    Creates and returns a new version of the entity.
    <S extends T>
    S
    workingCopy(S entity)
    Creates and returns a new version of the entity as a private working copy.
  • Method Details

    • lock

      <S extends T> S lock(S entity)
      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

      <S extends T> S unlock(S entity)
      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 owner
      SecurityException - if no authentication exists
    • save

      <S extends T> S save(S entity)
      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 owner
      SecurityException - if no authentication exists
    • workingCopy

      <S extends T> S workingCopy(S entity)
      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 latest
      LockOwnerException - if the current principal is not the lock owner
      SecurityException - if no authentication exists
    • version

      <S extends T> S version(S entity, VersionInfo info)
      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 on
      info - the version info
      Returns:
      the new versionWithEntity
      Throws:
      LockingAndVersioningException - if entity is not the latest
      LockOwnerException - if the current principal is not the lock owner
      SecurityException - if no authentication exists
    • findAllVersionsLatest

      @Deprecated <S extends T> List<S> 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

      <S extends T> List<S> findAllVersionsLatest(Class<S> entityClass)
      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

      <S extends T> List<S> findAllVersions(S entity)
      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

      <S extends T> List<S> findAllVersions(S entity, org.springframework.data.domain.Sort sort)
      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 for
      sort - the sort to apply
      Returns:
      list of entity versions
    • delete

      void delete(T entity)
      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 latest
      LockOwnerException - if the current principal is not the lock owner
      SecurityException - if no authentication exists
    • deleteAllVersions

      void deleteAllVersions(T entity)
      Deletes all versions of the given entity.
      Parameters:
      entity - the entity to delete
    • isPrivateWorkingCopy

      <S extends T> boolean isPrivateWorkingCopy(S entity)
      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

      <S extends T> S findWorkingCopy(S entity)
      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