Record Class TenantScope

java.lang.Object
java.lang.Record
dev.dokimos.server.tenant.TenantScope
Record Components:
restricted - whether a tenant predicate applies; false for unrestricted()
tenantId - the tenant to filter and stamp by when restricted is true, possibly null for shared-only

public record TenantScope(boolean restricted, String tenantId) extends Record
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 stamp null. 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) applies tenant_id = :tenantId OR tenant_id IS NULL, so a tenant sees its own rows plus shared (null-tenant) rows, and writes stamp tenantId. A null tenant 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

    Constructors
    Constructor
    Description
    TenantScope(boolean restricted, String tenantId)
    Creates an instance of a TenantScope record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
    Returns the value of the restricted record component.
    scoped(String tenantId)
    Returns a scope restricted to the given tenant.
    Returns the tenant id to stamp on a newly written row, or null for a shared row (the unrestricted and shared-only scopes).
    Returns the value of the tenantId record component.
    final String
    Returns a string representation of this record class.
    Returns the scope that applies no tenant predicate.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • TenantScope

      public TenantScope(boolean restricted, String tenantId)
      Creates an instance of a TenantScope record class.
      Parameters:
      restricted - the value for the restricted record component
      tenantId - the value for the tenantId record component
  • Method Details

    • unrestricted

      public static TenantScope unrestricted()
      Returns the scope that applies no tenant predicate. Reads see every row; writes stamp null.
      Returns:
      the unrestricted scope
    • scoped

      public static TenantScope scoped(String tenantId)
      Returns a scope restricted to the given tenant. Reads see tenant_id = tenantId OR tenant_id IS NULL; writes stamp tenantId. A null tenant id yields a shared-only scope (reads see only null-tenant rows, writes stamp null).
      Parameters:
      tenantId - the tenant to scope to, or null for shared-only
      Returns:
      a restricted scope for the tenant
    • stampTenantId

      public String stampTenantId()
      Returns the tenant id to stamp on a newly written row, or null for a shared row (the unrestricted and shared-only scopes).
      Returns:
      the tenant id to stamp, or null
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • restricted

      public boolean restricted()
      Returns the value of the restricted record component.
      Returns:
      the value of the restricted record component
    • tenantId

      public String tenantId()
      Returns the value of the tenantId record component.
      Returns:
      the value of the tenantId record component