Package dev.dokimos.server.tenant
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
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 Summary
Modifier and TypeMethodDescriptionlongcount(TenantScope scope) Counts the entities visible under the scope.voidRemoves an entity.findAll(TenantScope scope) Lists every entity visible under the scope.findById(UUID id, TenantScope scope) Loads an entity by id only if it is visible under the scope.<S extends T>
Ssave(S entity) Persists a new or updated entity.Persists all the given entities.
-
Method Details
-
findById
Description copied from interface:ScopedRepositoryLoads 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:
findByIdin interfaceScopedRepository<T>- Parameters:
id- the entity idscope- the tenant scope- Returns:
- the entity if visible, otherwise empty
-
findAll
Description copied from interface:ScopedRepositoryLists every entity visible under the scope.- Specified by:
findAllin interfaceScopedRepository<T>- Parameters:
scope- the tenant scope- Returns:
- the visible entities
-
count
Description copied from interface:ScopedRepositoryCounts the entities visible under the scope.- Specified by:
countin interfaceScopedRepository<T>- Parameters:
scope- the tenant scope- Returns:
- the count of visible rows
-
save
Description copied from interface:ScopedRepositoryPersists a new or updated entity. The caller stamps the tenant id from the resolved scope before calling this.- Specified by:
savein interfaceScopedRepository<T>- Type Parameters:
S- the concrete entity subtype- Parameters:
entity- the entity to persist- Returns:
- the managed, persisted entity
-
saveAll
Description copied from interface:ScopedRepositoryPersists all the given entities. The caller stamps each from the resolved scope first.- Specified by:
saveAllin interfaceScopedRepository<T>- Type Parameters:
S- the concrete entity subtype- Parameters:
entities- the entities to persist- Returns:
- the managed, persisted entities
-
delete
Description copied from interface:ScopedRepositoryRemoves an entity. Services load throughScopedRepository.findById(UUID, TenantScope)first, so a delete cannot reach across tenants.- Specified by:
deletein interfaceScopedRepository<T>- Parameters:
entity- the entity to remove
-