Package com.codename1.backend.tenancy


package com.codename1.backend.tenancy

Multi-tenancy: one deployment serving many customers whose data must never mix.

TenantContext holds the tenant of the work running on this thread. TenantFilter sets it for each request. Two ways to keep the data apart build on it, and an application can use either or both:

  • A shared table. An entity with a TenantId field is partitioned by the managed session itself: every insert is stamped with the current tenant, and every query, count, update and delete is limited to it. With no tenant set the session refuses the entity instead of answering every tenant's rows.
  • A database or schema per tenant. TenantDataSources keeps one DataSource per tenant, opened on first use from a URL template.