Package dev.dokimos.server.tenant
Record Class TenantScope
java.lang.Object
java.lang.Record
dev.dokimos.server.tenant.TenantScope
- Record Components:
restricted- whether a tenant predicate applies;falseforunrestricted()tenantId- the tenant to filter and stamp by whenrestrictedis true, possiblynullfor shared-only
Immutable tenant visibility used by every scoped repository read and by service-side write stamping.
unrestricted()applies no predicate; reads see every row and writes stampnull. This is the scope of the system principal (no-key and legacy single-key deployments) and of background workers, so existing single-tenant and no-key behavior is preserved exactly.scoped(String)appliestenant_id = :tenantId OR tenant_id IS NULL, so a tenant sees its own rows plus shared (null-tenant) rows, and writes stamptenantId. Anulltenant id collapses to shared-only. This is the scope of a scoped API key and of an anonymous keyless reader.
The scope is required on every finder, so an unscoped load does not compile.
-
Constructor Summary
ConstructorsConstructorDescriptionTenantScope(boolean restricted, String tenantId) Creates an instance of aTenantScoperecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanReturns the value of therestrictedrecord component.static TenantScopeReturns a scope restricted to the given tenant.Returns the tenant id to stamp on a newly written row, ornullfor a shared row (the unrestricted and shared-only scopes).tenantId()Returns the value of thetenantIdrecord component.final StringtoString()Returns a string representation of this record class.static TenantScopeReturns the scope that applies no tenant predicate.
-
Constructor Details
-
TenantScope
Creates an instance of aTenantScoperecord class.- Parameters:
restricted- the value for therestrictedrecord componenttenantId- the value for thetenantIdrecord component
-
-
Method Details
-
unrestricted
Returns the scope that applies no tenant predicate. Reads see every row; writes stampnull.- Returns:
- the unrestricted scope
-
scoped
Returns a scope restricted to the given tenant. Reads seetenant_id = tenantId OR tenant_id IS NULL; writes stamptenantId. Anulltenant id yields a shared-only scope (reads see only null-tenant rows, writes stampnull).- Parameters:
tenantId- the tenant to scope to, ornullfor shared-only- Returns:
- a restricted scope for the tenant
-
stampTenantId
Returns the tenant id to stamp on a newly written row, ornullfor a shared row (the unrestricted and shared-only scopes).- Returns:
- the tenant id to stamp, or
null
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
restricted
public boolean restricted()Returns the value of therestrictedrecord component.- Returns:
- the value of the
restrictedrecord component
-
tenantId
Returns the value of thetenantIdrecord component.- Returns:
- the value of the
tenantIdrecord component
-