Interface ScopedRepository<T>

Type Parameters:
T - the scoped entity type
All Known Subinterfaces:
AlertWebhookRepository, AlertWebhookRepositoryFragment, DatasetRepository, DatasetRepositoryFragment, ExperimentRepository, ExperimentRepositoryFragment, ExperimentRunRepository, ExperimentRunRepositoryFragment, LlmConnectionRepository, LlmConnectionRepositoryFragment, ProjectRepository, ProjectRepositoryFragment, TraceEvalRuleRepository, TraceEvalRuleRepositoryFragment, TraceRepository, TraceRepositoryFragment
All Known Implementing Classes:
AbstractScopedRepository, AlertWebhookRepositoryFragmentImpl, DatasetRepositoryFragmentImpl, ExperimentRepositoryFragmentImpl, ExperimentRunRepositoryFragmentImpl, LlmConnectionRepositoryFragmentImpl, ProjectRepositoryFragmentImpl, TraceEvalRuleRepositoryFragmentImpl, TraceRepositoryFragmentImpl

public interface ScopedRepository<T>
Common tenant-scoped operations shared by every scoped repository. A scoped repository extends Spring Data's empty Repository<T, UUID> plus this fragment, so the dangerous inherited finders (findById(id), findAll(), getReferenceById, getById) do not exist and an unscoped load does not compile.

Every read takes a TenantScope. Request paths pass the principal's scope; background workers pass TenantScope.unrestricted() explicitly. Writes are stamped by the service from the resolved scope before save(Object) is called, so persistence itself stays scope-agnostic.

  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Counts the entities visible under the scope.
    void
    delete(T entity)
    Removes an entity.
    Lists every entity visible under the scope.
    Loads an entity by id only if it is visible under the scope.
    <S extends T>
    S
    save(S entity)
    Persists a new or updated entity.
    <S extends T>
    List<S>
    saveAll(Iterable<S> entities)
    Persists all the given entities.
  • Method Details

    • findById

      Optional<T> findById(UUID id, TenantScope scope)
      Loads an entity by id only if it is visible under the scope. A row of another tenant returns empty, which the service maps to a 404 so existence is not leaked.
      Parameters:
      id - the entity id
      scope - the tenant scope
      Returns:
      the entity if visible, otherwise empty
    • findAll

      List<T> findAll(TenantScope scope)
      Lists every entity visible under the scope.
      Parameters:
      scope - the tenant scope
      Returns:
      the visible entities
    • count

      long count(TenantScope scope)
      Counts the entities visible under the scope.
      Parameters:
      scope - the tenant scope
      Returns:
      the count of visible rows
    • save

      <S extends T> S save(S entity)
      Persists a new or updated entity. The caller stamps the tenant id from the resolved scope before calling this.
      Type Parameters:
      S - the concrete entity subtype
      Parameters:
      entity - the entity to persist
      Returns:
      the managed, persisted entity
    • saveAll

      <S extends T> List<S> saveAll(Iterable<S> entities)
      Persists all the given entities. The caller stamps each from the resolved scope first.
      Type Parameters:
      S - the concrete entity subtype
      Parameters:
      entities - the entities to persist
      Returns:
      the managed, persisted entities
    • delete

      void delete(T entity)
      Removes an entity. Services load through findById(UUID, TenantScope) first, so a delete cannot reach across tenants.
      Parameters:
      entity - the entity to remove