Class AbstractScopedRepository<T>

java.lang.Object
dev.dokimos.server.tenant.AbstractScopedRepository<T>
Type Parameters:
T - the scoped entity type
All Implemented Interfaces:
ScopedRepository<T>
Direct Known Subclasses:
AlertWebhookRepositoryFragmentImpl, DatasetRepositoryFragmentImpl, ExperimentRepositoryFragmentImpl, ExperimentRunRepositoryFragmentImpl, LlmConnectionRepositoryFragmentImpl, ProjectRepositoryFragmentImpl, TraceEvalRuleRepositoryFragmentImpl, TraceRepositoryFragmentImpl

public abstract class AbstractScopedRepository<T> extends Object implements ScopedRepository<T>
Base implementation of ScopedRepository. It owns the EntityManager and delegates scoped reads to a TenantScopedFinder; fragment implementations extend this, pass their entity class up, and add the entity-specific finders. Confining the EntityManager to this layer is what lets the architecture backstop forbid services from holding one and bypassing the scope predicate.
  • Method Details

    • findById

      public Optional<T> findById(UUID id, TenantScope scope)
      Description copied from interface: ScopedRepository
      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.
      Specified by:
      findById in interface ScopedRepository<T>
      Parameters:
      id - the entity id
      scope - the tenant scope
      Returns:
      the entity if visible, otherwise empty
    • findAll

      public List<T> findAll(TenantScope scope)
      Description copied from interface: ScopedRepository
      Lists every entity visible under the scope.
      Specified by:
      findAll in interface ScopedRepository<T>
      Parameters:
      scope - the tenant scope
      Returns:
      the visible entities
    • count

      public long count(TenantScope scope)
      Description copied from interface: ScopedRepository
      Counts the entities visible under the scope.
      Specified by:
      count in interface ScopedRepository<T>
      Parameters:
      scope - the tenant scope
      Returns:
      the count of visible rows
    • save

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

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

      public void delete(T entity)
      Description copied from interface: ScopedRepository
      Removes an entity. Services load through ScopedRepository.findById(UUID, TenantScope) first, so a delete cannot reach across tenants.
      Specified by:
      delete in interface ScopedRepository<T>
      Parameters:
      entity - the entity to remove