Package com.axelor.db.tenants
Class TenantAware
- java.lang.Object
-
- java.lang.Thread
-
- com.axelor.db.tenants.TenantAware
-
- All Implemented Interfaces:
Runnable
public class TenantAware extends Thread
A Thread implementation that makes a thread tenant-aware by setting the tenant configuration before executing its task and clearing it afterward.This class ensures that any operations performed in the thread are associated with the correct tenant. It uses a tenant resolver (e.g.,
TenantResolver
) to set and manage the tenant information during thread execution.By default, it will run the task inside a new transaction.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description TenantAware(Runnable task)
Constructs a TenantAware using the current tenant.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
run()
TenantAware
tenantHost(String tenantHost)
Specify the tenant hostTenantAware
tenantId(String tenantId)
Specify the tenant identifierTenantAware
withTransaction(boolean withTransaction)
Whatever the task should run inside a new transaction-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Constructor Detail
-
TenantAware
public TenantAware(Runnable task)
Constructs a TenantAware using the current tenant.- Parameters:
task
- the task to execute
-
-
Method Detail
-
tenantId
public TenantAware tenantId(String tenantId)
Specify the tenant identifier- Parameters:
tenantId
- the tenant identifier- Returns:
- this
-
tenantHost
public TenantAware tenantHost(String tenantHost)
Specify the tenant host- Parameters:
tenantHost
- the tenant host- Returns:
- this
-
withTransaction
public TenantAware withTransaction(boolean withTransaction)
Whatever the task should run inside a new transaction- Parameters:
withTransaction
- false to not open a transaction, else true- Returns:
- this
-
-