@CompileStatic @Slf4j class Tenants extends java.lang.Object
Helper methods for working with multi tenancy
| Modifiers | Name | Description |
|---|---|---|
static class |
Tenants.DatastoreLocator |
| Type | Name and description |
|---|---|
static Tenants.DatastoreLocator |
datastoreLocatorPluggable locator for Datastore instances, allowing for easier testing. |
| Constructor and description |
|---|
Tenants() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
static java.io.Serializable |
currentId()
|
|
static java.io.Serializable |
currentId(MultiTenantCapableDatastore multiTenantCapableDatastore)The current id for the given datastore. |
|
static java.io.Serializable |
currentId(java.lang.Class<? extends Datastore> datastoreClass)
|
|
static void |
eachTenant(Closure callable)Execute the given closure for each tenant. |
|
static void |
eachTenant(java.lang.Class<? extends Datastore> datastoreClass, Closure callable)Execute the given closure for each tenant. |
|
static void |
eachTenant(MultiTenantCapableDatastore multiTenantCapableDatastore, Closure callable)Execute the given closure for each tenant for the given datastore. |
|
static boolean |
isWithoutId()Whether the current thread runs without a tenant id for the default datastore, as it does inside withoutId(Closure) and in a method annotated with WithoutTenant. |
|
static boolean |
isWithoutId(Datastore datastore)Whether the current thread runs without a tenant id for the given datastore, as it does inside withoutId(MultiTenantCapableDatastore, Closure). |
<T> |
static T |
withCurrent(Closure<T> callable)Execute the given closure with the current tenant |
<T> |
static T |
withCurrent(java.lang.Class<? extends Datastore> datastoreClass, Closure<T> callable)Execute the given closure with the current tenant |
<T> |
static T |
withCurrent(MultiTenantCapableDatastore multiTenantCapableDatastore, Closure<T> callable)Execute the given closure with the current tenant for the given datastore. |
<T> |
static T |
withId(java.io.Serializable tenantId, Closure<T> callable)Execute the given closure with given tenant id |
<T> |
static T |
withId(java.lang.Class domainClass, java.io.Serializable tenantId, Closure<T> callable)Execute the given closure with given tenant id |
<T> |
static T |
withId(MultiTenantCapableDatastore multiTenantCapableDatastore, java.io.Serializable tenantId, Closure<T> callable)Execute the given closure with given tenant id for the given datastore. |
<T> |
static T |
withTenant(java.io.Serializable tenantId, Closure<T> callable)Binds the given tenant id to the current thread for the duration of the closure. |
<T> |
static T |
withTenant(java.lang.Class domainClass, java.io.Serializable tenantId, Closure<T> callable)Binds the given tenant id to the current thread for the datastore that maps the given domain class, for the duration of the closure. |
<T> |
static T |
withoutId(Closure<T> callable)Execute the given closure without any tenant id. |
<T> |
static T |
withoutId(MultiTenantCapableDatastore multiTenantCapableDatastore, Closure<T> callable)Execute the given closure without tenant id for the given datastore. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
Pluggable locator for Datastore instances, allowing for easier testing.
The current id for the given datastore. Inside withoutId(Closure) it is ConnectionSource.DEFAULT.
nullmultiTenantCapableDatastore - The multi tenant capable datastoreExecute the given closure for each tenant.
callable - The closureExecute the given closure for each tenant.
callable - The closureExecute the given closure for each tenant for the given datastore. This method will create a new datastore session for the scope of the call and hence is designed to be used to manage the connection life cycle
callable - The closureWhether the current thread runs without a tenant id for the default datastore, as it does inside withoutId(Closure) and in a method annotated with WithoutTenant. A tenant id that a TenantResolver returns or that is passed to withId(Serializable, Closure) never counts, even if it is the name of the default connection source, ConnectionSource.DEFAULT.
The tenant id is bound per datastore, so this method looks up the single configured datastore. When more than one GORM implementation is configured, use isWithoutId(Datastore) with the datastore in question instead.
Whether the current thread runs without a tenant id for the given datastore, as it does inside
withoutId(MultiTenantCapableDatastore, Closure). A tenant id that a TenantResolver returns or
that is passed to withId never counts, even if it is the name of the default connection source,
ConnectionSource.DEFAULT.
datastore - The datastoreExecute the given closure with the current tenant
callable - The closureExecute the given closure with the current tenant
datastoreClass - The datastore classcallable - The closureExecute the given closure with the current tenant for the given datastore. Inside withoutId(MultiTenantCapableDatastore, Closure) it runs without a tenant id, and a closure that takes the tenant id gets ConnectionSource.DEFAULT.
multiTenantCapableDatastore - The multi tenant capable datastorecallable - The closureExecute the given closure with given tenant id
tenantId - The tenant idcallable - The closureExecute the given closure with given tenant id
tenantId - The tenant idcallable - The closureExecute the given closure with given tenant id for the given datastore. This method will create a new datastore session for the scope of the call and hence is designed to be used to manage the connection life cycle
tenantId - The tenant idcallable - The closure Binds the given tenant id to the current thread for the duration of the closure.
This binds the tenant only. Unlike withId(Serializable, Closure) it opens no session and
manages no connection life cycle: the closure runs in whatever session the caller has already
established, and the caller remains responsible for opening and closing it. Reach for withId
when the tenant's work needs a session of its own - in DATABASE mode that is also what selects the
tenant's connection.
tenantId - The tenant idcallable - The closureBinds the given tenant id to the current thread for the datastore that maps the given domain class, for the duration of the closure. This binds the tenant only. Unlike withId(Class, Serializable, Closure) it opens no session and manages no connection: the caller owns the session the closure runs in.
domainClass - The domain class whose datastore the tenant should be bound fortenantId - The tenant idcallable - The closureExecute the given closure without any tenant id. In Multi tenancy mode SINGLE this will execute against the default data source. If multi tenancy mode MULTI this will execute without including the "tenantId" on any query. Use with caution.
callable - The closureExecute the given closure without tenant id for the given datastore. This method will create a new datastore session for the scope of the call and hence is designed to be used to manage the connection life cycle
callable - The closure