Package dev.dokimos.server.tenant
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 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
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 idscope- the tenant scope- Returns:
- the entity if visible, otherwise empty
-
findAll
Lists every entity visible under the scope.- Parameters:
scope- the tenant scope- Returns:
- the visible entities
-
count
Counts the entities visible under the scope.- Parameters:
scope- the tenant scope- Returns:
- the count of visible rows
-
save
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
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
Removes an entity. Services load throughfindById(UUID, TenantScope)first, so a delete cannot reach across tenants.- Parameters:
entity- the entity to remove
-