public class TenantManager
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
TenantManager.Tenant
Inner class responsible with storing information about a tenant.
|
private static class |
TenantManager.TenantSQL
Inner class responsible with storing SQLs that will be further used to manage tenants.
|
| Modifier and Type | Field and Description |
|---|---|
private static java.sql.PreparedStatement |
addTenantDatabasesStmt
PreparedStatement for adding a database to a tenant.
|
private static java.sql.PreparedStatement |
addTenantStmt
PreparedStatement for adding a tenant.
|
private static java.sql.Connection |
conn
Active JDBC connection of the landlord database.
|
private static java.lang.String |
DEFAULT_TENANT_NAME
The name of the default tenant.
|
private static java.sql.PreparedStatement |
deleteTenantDatabasesStmt
PreparedStatement for deleting all the databases of a certain tenant.
|
private static java.sql.PreparedStatement |
deleteTenantDatabaseStmt
PreparedStatement for deleting a database of a certain tenant.
|
private static java.sql.PreparedStatement |
deleteTenantStmt
PreparedStatement for deleting a tenant.
|
private static java.sql.PreparedStatement |
enableTenantStmt
PreparedStatement for enabling/disabling a tenant.
|
private static boolean |
init
Flag for determining if this class has been initialized or not.
|
private static java.sql.PreparedStatement |
isTenantEnabledStmt
PreparedStatement for checking if a tenant is enabled or not.
|
private static java.lang.Object |
lock
The lock used to synchronize calls.
|
private static CentralLogger |
LOG
Logger
|
private static java.sql.PreparedStatement |
selectTenantDatabasesStmt
PreparedStatement for selecting all the databases of a certain tenant.
|
private static java.sql.PreparedStatement |
selectTenantDatabaseStmt
PreparedStatement for selecting a database of a certain tenant.
|
private static java.util.Map<java.lang.String,TenantManager.Tenant> |
tenants
Map for retrieving a tenant based on its id.
|
private static java.util.Map<java.lang.String,java.sql.PreparedStatement> |
updateStmts
Map of update statements for the master table based on the column name given.
|
| Constructor and Description |
|---|
TenantManager()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
addDatabaseToDefaultTenant(TenantDatabaseDescriptor db)
Add a database to the default tenant.
|
static boolean |
addDatabaseToTenant(java.lang.String tenantName,
TenantDatabaseDescriptor db)
Function for adding a database instance to a tenant.
|
private static void |
addDefaultTenant()
Method used for initializing the default tenant.
|
static boolean |
addTenant(java.lang.String tenantName,
java.util.List<TenantDatabaseDescriptor> databases)
Insert a tenant into the master table.
|
static boolean |
changeTenantStatus(java.lang.String tenantName,
boolean enable)
Enable/Disable a specific tenant.
|
private static void |
connectAll()
Method for logically connecting the tenants to their databases.
|
private static void |
connectTenantImpl(TenantManager.Tenant tenant)
Logically connect the tenant to its respective databases.
|
private static void |
createTables()
Method used for executing SQLs in order to create the required tables in the landlord database.
|
static boolean |
deleteDatabaseFromTenant(java.lang.String tenantName,
java.lang.String pdbName)
Delete a database instance that is assigned to a tenant.
|
static boolean |
deleteTenant(java.lang.String tenantName)
Function for deleting a tenant from the master table.
|
static void |
enable()
Enable the support for multi-tenancy.
|
static Database |
getDatabase(java.lang.String tenantName,
java.lang.String dbName,
boolean physical)
Get the database instance of a tenant based on the tenant name and the database physical name.
|
static java.util.List<java.lang.String> |
getDatabaseSettings(java.lang.String tenantName,
java.lang.String pdbName)
Get the database settings of a specific database of a specific tenant.
|
static java.lang.String |
getDefaultTenantName()
Get the name of the default tenant.
|
static TenantManager.Tenant |
getTenant(java.lang.String tenantName)
Get a tenant from the tenants map.
|
static java.lang.String |
getTenantName(java.lang.String domainName,
java.lang.String ldbName)
Retrieve the tenant name from the given domain.
|
static void |
initialize(java.lang.String landlordURL)
Initialize multi-tenancy.
|
private static void |
initializeStatements()
Initialize the tenant managing statements.
|
static boolean |
isTenantEnabled(java.lang.String tenantName)
Check if a specific tenant is enabled or not.
|
static java.util.List<TenantManager.Tenant> |
listTenants()
Get a list with all the tenants.
|
static void |
readDomains(java.lang.String ldbName,
SecurityOps.WorkArea wa)
Method that reads the domains from the authentication tables and adds them into the given context.
|
static boolean |
updateTenant(java.lang.String tenantName,
java.lang.String pdbName,
java.util.Map<java.lang.String,java.lang.String> values)
Update a tenant from the master table.
|
private static boolean |
updateTenantImpl(java.lang.String tenantName,
java.lang.String pdbName,
java.lang.String column,
java.lang.String newValue)
Update a tenant from the master table.
|
private static final CentralLogger LOG
private static final java.lang.String DEFAULT_TENANT_NAME
private static final java.lang.Object lock
private static java.sql.Connection conn
private static java.util.Map<java.lang.String,TenantManager.Tenant> tenants
private static java.util.Map<java.lang.String,java.sql.PreparedStatement> updateStmts
private static java.sql.PreparedStatement addTenantStmt
private static java.sql.PreparedStatement addTenantDatabasesStmt
private static java.sql.PreparedStatement selectTenantDatabaseStmt
private static java.sql.PreparedStatement selectTenantDatabasesStmt
private static java.sql.PreparedStatement enableTenantStmt
private static java.sql.PreparedStatement isTenantEnabledStmt
private static java.sql.PreparedStatement deleteTenantStmt
private static java.sql.PreparedStatement deleteTenantDatabaseStmt
private static java.sql.PreparedStatement deleteTenantDatabasesStmt
private static volatile boolean init
public static void enable()
public static void initialize(java.lang.String landlordURL)
landlordURL - The URL of the landlord database.public static java.util.List<TenantManager.Tenant> listTenants()
public static boolean addTenant(java.lang.String tenantName,
java.util.List<TenantDatabaseDescriptor> databases)
tenantName - The name of the tenant.databases - A list of the databases that will be used by the tenant.true if the operation is performed successfully, false otherwise.public static boolean addDatabaseToTenant(java.lang.String tenantName,
TenantDatabaseDescriptor db)
tenantName - The tenant for which to add the database instance.db - The database information to be added.true if the operation is performed successfully, false otherwise.public static void addDatabaseToDefaultTenant(TenantDatabaseDescriptor db)
db - The database descriptor which stores information about the database to be added.public static boolean updateTenant(java.lang.String tenantName,
java.lang.String pdbName,
java.util.Map<java.lang.String,java.lang.String> values)
column values/names are:
tenantName - The name of the tenant that is targeted by the update.pdbName - The physical name of the database that is targeted by the update.values - A Map with pairs (column name - new value) that are intended for the update.true if all the updates are performed successfully,
false if there is at least an update that fails.public static boolean deleteTenant(java.lang.String tenantName)
tenantName - The name of the tenant that is targeted by the delete.true if the operation was successful, false otherwise.public static boolean deleteDatabaseFromTenant(java.lang.String tenantName,
java.lang.String pdbName)
tenantName - The tenant for which to remove the database instance.pdbName - The database physical name of the database to be deleted.true if the operation was successful, false otherwise.public static boolean changeTenantStatus(java.lang.String tenantName,
boolean enable)
tenantName - The tenant to work with.enable - true if the intent is to enable the tenant, false otherwise.true if the operation is performed successfully, false otherwise.public static boolean isTenantEnabled(java.lang.String tenantName)
tenantName - The tenant to work with.true if the tenant is enabled, false otherwise.public static TenantManager.Tenant getTenant(java.lang.String tenantName)
tenantName - The name of the tenant.Tenant that holds other information.public static Database getDatabase(java.lang.String tenantName, java.lang.String dbName, boolean physical)
tenantName - The name of the tenant for which to retrieve the database.dbName - The name of the database instance to be retrieved.physical - true if the given database name is the physical one,
false if the database name is the logical one.public static java.util.List<java.lang.String> getDatabaseSettings(java.lang.String tenantName,
java.lang.String pdbName)
tenantName - The tenant to work with.pdbName - The database physical name for which to retrieve the settings.public static void readDomains(java.lang.String ldbName,
SecurityOps.WorkArea wa)
throws java.sql.SQLException
ldbName - The logical database name used when adding a domain.wa - The context in which to add the domains.java.sql.SQLExceptionpublic static java.lang.String getTenantName(java.lang.String domainName,
java.lang.String ldbName)
domainName - The name of the domain from which to retrieve the tenant name.ldbName - The logical name of the database.public static java.lang.String getDefaultTenantName()
private static void initializeStatements()
throws java.sql.SQLException
java.sql.SQLExceptionprivate static void createTables()
throws java.sql.SQLException
java.sql.SQLExceptionprivate static void addDefaultTenant()
private static void connectAll()
throws java.sql.SQLException
java.sql.SQLExceptionprivate static void connectTenantImpl(TenantManager.Tenant tenant)
tenant - The tenant to be connected to the database.private static boolean updateTenantImpl(java.lang.String tenantName,
java.lang.String pdbName,
java.lang.String column,
java.lang.String newValue)
tenantName - The name of the tenant that is targeted by the update.pdbName - The physical name of the database that is targeted by the update.column - The column that will be updated.newValue - The value that will replace the one from the table.true if the operation was successful, false otherwise.