Class MultiTenant


  • public class MultiTenant
    extends java.lang.Object
    MultiTenant: 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 class  MultiTenant.SharedEntityAccess
      SharedEntityAccess: access limitation for the instances of the InstanceType.
      static class  MultiTenant.SharedEntityType
      SharedEntityType: define entities that are shared by all the instances of the InstanceType.
      static class  MultiTenant.Type
      MultiTenant 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
      void addSharedEntityType​(MultiTenant.SharedEntityType sharedEntityType)
      Add shared entity type
      java.lang.String getSchema()
      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.SharedEntityType getSharedEntityType​(java.lang.Class entityType)
      Get the shared entity definition for the entity type
      java.util.Map<java.lang.Class,​MultiTenant.SharedEntityType> getSharedEntityTypes()
      Get the shared entityTypes.
      MultiTenant.Type getType()
      Get type
      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.
      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.
      boolean isSharedTable()
      Whether multiTenant type is shared table or separated schema?
      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.
      boolean isUserEntityShared()
      Are users shared by all instances in case of shared table multitenancy? If shared, User entity is not multitenant enabled, i.e.
      void setSchema​(java.lang.String schema)
      Set the database schema name for the associated instanceType.
      void setType​(MultiTenant.Type type)
      Set type
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 id
         
        For 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. see getSchema()
        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 type
        instanceType - 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.