Package com.znize.platform.model.module
Class MultiTenant
- java.lang.Object
-
- com.znize.platform.model.module.MultiTenant
-
public class MultiTenant extends java.lang.ObjectMultiTenant: how to map entities to database for the instances(tenants) of an InstanceType.- Since:
- 5.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMultiTenant.SharedEntityAccessSharedEntityAccess: access limitation for the instances of the InstanceType.static classMultiTenant.SharedEntityTypeSharedEntityType: define entities that are shared by all the instances of the InstanceType.static classMultiTenant.TypeMultiTenant Type
-
Constructor Summary
Constructors Constructor Description MultiTenant()Default constructor: separate database schemas for instances of an InstanceType.MultiTenant(MultiTenant.Type type, java.lang.String schema)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSharedEntityType(MultiTenant.SharedEntityType sharedEntityType)Add shared entity typejava.lang.StringgetSchema()Get the database schema name for the associated InstanceType.java.util.List<MultiTenant.SharedEntityAccess>getSharedEntityAccessList(java.lang.Class entityType, boolean instanceType)Get the access list of the shared entity type.MultiTenant.SharedEntityTypegetSharedEntityType(java.lang.Class entityType)Get the shared entity definition for the entity typejava.util.Map<java.lang.Class,MultiTenant.SharedEntityType>getSharedEntityTypes()Get the shared entityTypes.MultiTenant.TypegetType()Get typebooleanisSharedEntityAccessLimited(java.lang.Class entityType, boolean instanceType)Is accessing the shared entities limited for instanceType or instance dataAccessUnit? If entities are shared for multitenancy, some actions may be denied and some properties of shared entities may not be visible even to system or super users for privacy in an instances.booleanisSharedEntityType(java.lang.Class entityType)Are entities of the entity type shared by all instances in case of singleTable multitenancy? For separate schema multitenancy, entities are not shared.booleanisSharedTable()Whether multiTenant type is shared table or separated schema?booleanisUserAccessLimited(boolean instanceType)Is accessing users limited in the instances of the InstanceType? For single identity multitenancy, user entities in subsystems are not fully searched or viewed for privacy.booleanisUserEntityShared()Are users shared by all instances in case of shared table multitenancy? If shared, User entity is not multitenant enabled, i.e.voidsetSchema(java.lang.String schema)Set the database schema name for the associated instanceType.voidsetType(MultiTenant.Type type)Set type
-
-
-
Constructor Detail
-
MultiTenant
public MultiTenant()
Default constructor: separate database schemas for instances of an InstanceType.
-
MultiTenant
public MultiTenant(MultiTenant.Type type, java.lang.String schema)
Constructor- Parameters:
type- share table or different schemas for tenants(instanceType instances).schema- instanceType schema name that can be an expression
-
-
Method Detail
-
getType
public MultiTenant.Type getType()
Get type- Returns:
- multitenant type
-
setType
public void setType(MultiTenant.Type type)
Set type- Parameters:
type- multitenant type
-
getSchema
public java.lang.String getSchema()
Get the database schema name for the associated InstanceType. It can be an expression that supports the following variables:#{db.schema.name}: schema base name #{instanceType.id}: instanceType idFor separated schema, the schema for an instance is [schema]_[instanceId].- Returns:
- database schema name. return null for default. The default schema for system is #{db.schema}, and it is #{db.schema}_i#{instanceType.id} for an instanceType.
-
setSchema
public void setSchema(java.lang.String schema)
Set the database schema name for the associated instanceType. It can be an expression that supports variables. seegetSchema()- Parameters:
schema- database schema name
-
isSharedTable
public boolean isSharedTable()
Whether multiTenant type is shared table or separated schema?- Returns:
- true for shared table, false for separated schema.
-
isUserEntityShared
public boolean isUserEntityShared()
Are users shared by all instances in case of shared table multitenancy? If shared, User entity is not multitenant enabled, i.e. no tenant discriminator column. For separate schema multitenancy, users are not shared.- Returns:
- true for single identity(users are shared), false otherwise.
- See Also:
isSharedEntityType(Class)
-
isUserAccessLimited
public boolean isUserAccessLimited(boolean instanceType)
Is accessing users limited in the instances of the InstanceType? For single identity multitenancy, user entities in subsystems are not fully searched or viewed for privacy.- Returns:
- true if limited, false otherwise
-
addSharedEntityType
public void addSharedEntityType(MultiTenant.SharedEntityType sharedEntityType)
Add shared entity type- Parameters:
sharedEntityType- shared entity type
-
isSharedEntityType
public boolean isSharedEntityType(java.lang.Class entityType)
Are entities of the entity type shared by all instances in case of singleTable multitenancy? For separate schema multitenancy, entities are not shared.- Returns:
- true for sharing entities, false otherwise.
-
getSharedEntityTypes
public java.util.Map<java.lang.Class,MultiTenant.SharedEntityType> getSharedEntityTypes()
Get the shared entityTypes.- Returns:
- a map. map key is entity type. return null if there are none.
- Since:
- 5.16
-
getSharedEntityType
public MultiTenant.SharedEntityType getSharedEntityType(java.lang.Class entityType)
Get the shared entity definition for the entity type- Parameters:
entityType- entity type- Returns:
- SharedEntityType instance. return null if the entity type is not shared.
-
isSharedEntityAccessLimited
public boolean isSharedEntityAccessLimited(java.lang.Class entityType, boolean instanceType)Is accessing the shared entities limited for instanceType or instance dataAccessUnit? If entities are shared for multitenancy, some actions may be denied and some properties of shared entities may not be visible even to system or super users for privacy in an instances.- Parameters:
instanceType- true for instanceType DataAccessUnit, false for instance DataAccessUnit- Returns:
- true if limited, false otherwise.
-
getSharedEntityAccessList
public java.util.List<MultiTenant.SharedEntityAccess> getSharedEntityAccessList(java.lang.Class entityType, boolean instanceType)
Get the access list of the shared entity type.- Parameters:
entityType- entity typeinstanceType- true for instanceType DataAccessUnit, false for instance DataAccessUnit- Returns:
- a list of accesses allowed. return empty if accessing entities is not allowed. return null if the entity type is not shared.
-
-