Class TenantScopedFinder<T>

java.lang.Object
dev.dokimos.server.tenant.TenantScopedFinder<T>
Type Parameters:
T - the scoped entity type

public class TenantScopedFinder<T> extends Object
Reusable tenant-scoped query helper shared by every scoped repository implementation. It owns the EntityManager and applies the TenantPredicate so individual repositories never touch the entity manager themselves and never expose an unscoped finder.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TenantScopedFinder(jakarta.persistence.EntityManager entityManager, Class<T> entityType)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Counts the entities visible under the scope.
    findAll(TenantScope scope, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,List<jakarta.persistence.criteria.Order>> order)
    Lists every entity visible under the scope, with an optional order.
    Loads an entity by id under the scope; a row of another tenant returns empty, never leaking existence.
    Loads an entity by id under the scope and a pessimistic write lock, to serialize concurrent writers.
    findFirst(TenantScope scope, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,jakarta.persistence.criteria.Predicate> extra, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,List<jakarta.persistence.criteria.Order>> order)
    Returns the first entity matching extra and visible under the scope, with an optional order.
    findFirstForUpdate(TenantScope scope, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,jakarta.persistence.criteria.Predicate> extra)
    Returns the first entity matching extra under the scope and a pessimistic write lock.
    org.springframework.data.domain.Page<T>
    findPage(TenantScope scope, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,jakarta.persistence.criteria.Predicate> extra, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,List<jakarta.persistence.criteria.Order>> order, org.springframework.data.domain.Pageable pageable)
    Returns a page of entities matching extra and visible under the scope.
    findWhere(TenantScope scope, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,jakarta.persistence.criteria.Predicate> extra, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,List<jakarta.persistence.criteria.Order>> order)
    Lists entities matching extra and visible under the scope, with an optional order.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TenantScopedFinder

      public TenantScopedFinder(jakarta.persistence.EntityManager entityManager, Class<T> entityType)
  • Method Details

    • findById

      public Optional<T> findById(UUID id, TenantScope scope)
      Loads an entity by id under the scope; a row of another tenant returns empty, never leaking existence.
    • findByIdForUpdate

      public Optional<T> findByIdForUpdate(UUID id, TenantScope scope)
      Loads an entity by id under the scope and a pessimistic write lock, to serialize concurrent writers.
    • findFirstForUpdate

      public Optional<T> findFirstForUpdate(TenantScope scope, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,jakarta.persistence.criteria.Predicate> extra)
      Returns the first entity matching extra under the scope and a pessimistic write lock.
    • findAll

      public List<T> findAll(TenantScope scope, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,List<jakarta.persistence.criteria.Order>> order)
      Lists every entity visible under the scope, with an optional order.
    • findWhere

      public List<T> findWhere(TenantScope scope, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,jakarta.persistence.criteria.Predicate> extra, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,List<jakarta.persistence.criteria.Order>> order)
      Lists entities matching extra and visible under the scope, with an optional order.
    • findFirst

      public Optional<T> findFirst(TenantScope scope, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,jakarta.persistence.criteria.Predicate> extra, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,List<jakarta.persistence.criteria.Order>> order)
      Returns the first entity matching extra and visible under the scope, with an optional order.
    • findPage

      public org.springframework.data.domain.Page<T> findPage(TenantScope scope, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,jakarta.persistence.criteria.Predicate> extra, BiFunction<jakarta.persistence.criteria.CriteriaBuilder,jakarta.persistence.criteria.Root<T>,List<jakarta.persistence.criteria.Order>> order, org.springframework.data.domain.Pageable pageable)
      Returns a page of entities matching extra and visible under the scope. The total count honors the same predicates so paging metadata is correct.
    • count

      public long count(TenantScope scope)
      Counts the entities visible under the scope.