Class JdbcIdentityRepository

java.lang.Object
org.jwcarman.who.jdbc.JdbcIdentityRepository
All Implemented Interfaces:
IdentityRepository

public class JdbcIdentityRepository extends Object implements IdentityRepository
JDBC implementation of IdentityRepository backed by the who_identity table.
  • Constructor Details

    • JdbcIdentityRepository

      public JdbcIdentityRepository(org.springframework.jdbc.core.simple.JdbcClient jdbcClient)
      Creates the repository, which keeps identities in who's tables.
      Parameters:
      jdbcClient - the database
  • Method Details

    • findById

      public Optional<Identity> findById(UUID id)
      Description copied from interface: IdentityRepository
      Finds an identity by its UUID.
      Specified by:
      findById in interface IdentityRepository
      Parameters:
      id - the identity UUID
      Returns:
      the identity, or empty if not found
    • lockById

      public Optional<Identity> lockById(UUID id)
      Description copied from interface: IdentityRepository
      Finds an identity and locks its row until the surrounding transaction ends, so that concurrent callers serialize on it. Call it inside a transaction.
      Specified by:
      lockById in interface IdentityRepository
      Parameters:
      id - the identity UUID
      Returns:
      the identity, or empty if not found
    • findPage

      public List<Identity> findPage(Optional<IdentityStatus> status, Optional<UUID> roleId, Optional<Set<UUID>> ids, int page, int size)
      Description copied from interface: IdentityRepository
      Returns one page of identities, oldest first: ordered by creation time, then by id. Every filter given must match.
      Specified by:
      findPage in interface IdentityRepository
      Parameters:
      status - only identities with this status; empty for any status
      roleId - only identities assigned this who-rbac role, matched in the query against who-rbac's role assignments, so a role's holders are never listed first; empty for any role. Give one only where who-rbac's schema is installed
      ids - only identities among these ids; empty for any id. An empty set matches none
      page - the zero-based page number; must not be negative
      size - the most identities on a page; must be positive
      Returns:
      the identities on that page (never null; empty past the last page)
    • count

      public long count(Optional<IdentityStatus> status, Optional<UUID> roleId, Optional<Set<UUID>> ids)
      Description copied from interface: IdentityRepository
      Counts the identities IdentityRepository.findPage(Optional, Optional, Optional, int, int) pages through for the same filters.
      Specified by:
      count in interface IdentityRepository
      Parameters:
      status - only identities with this status; empty for any status
      roleId - only identities assigned this who-rbac role; empty for any role
      ids - only identities among these ids; empty for any id. An empty set matches none
      Returns:
      how many identities match
    • save

      public Identity save(Identity identity)
      Description copied from interface: IdentityRepository
      Persists the given identity, inserting or updating as necessary.
      Specified by:
      save in interface IdentityRepository
      Parameters:
      identity - the identity to save
      Returns:
      the saved identity
    • existsById

      public boolean existsById(UUID id)
      Description copied from interface: IdentityRepository
      Returns whether an identity with the given UUID exists.
      Specified by:
      existsById in interface IdentityRepository
      Parameters:
      id - the identity UUID
      Returns:
      true if an identity exists with that UUID
    • deleteById

      public void deleteById(UUID id)
      Description copied from interface: IdentityRepository
      Deletes the identity with the given UUID.
      Specified by:
      deleteById in interface IdentityRepository
      Parameters:
      id - the identity UUID
    • changeStatus

      public boolean changeStatus(UUID id, IdentityStatus status)
      Description copied from interface: IdentityRepository
      Sets the status of the identity with the given UUID, reporting whether anything changed. The default finds then saves; implementations backed by a database should override it with one conditional update, so that concurrent callers cannot both see a change.
      Specified by:
      changeStatus in interface IdentityRepository
      Parameters:
      id - the identity UUID
      status - the new status
      Returns:
      true only if the identity exists and its status was different