/**
   * Returns the fully qualified username of a particular database user. For an ordinary tenant, the
   * tenant domain will be appended to the username together with an underscore and the given
   * username will be returned as it is in the case of super tenant.
   *
   * @param username Username of the database user.
   * @return Fully qualified username of the database user.
   */
  public static String getFullyQualifiedUsername(String username) {
    String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {

      /* The maximum number of characters allowed for the username in mysql system tables is
       * 16. Thus, to adhere the aforementioned constraint as well as to give the username
       * an unique identification based on the tenant domain, we append a hash value that is
       * created based on the tenant domain */
      return username + "_" + RSSManagerHelper.getDatabaseUserPostfix();
    }
    return username;
  }
  public static DataSourceMetaInfo createDSMetaInfo(DatabaseInfo database, String username)
      throws RSSManagerException {
    DataSourceMetaInfo metaInfo = new DataSourceMetaInfo();
    RDBMSConfiguration rdbmsConfiguration = new RDBMSConfiguration();
    String url = database.getUrl();
    String driverClassName = RSSManagerHelper.getDatabaseDriver(url);
    rdbmsConfiguration.setUrl(url);
    rdbmsConfiguration.setDriverClassName(driverClassName);
    rdbmsConfiguration.setUsername(username);

    metaInfo.setDefinition(createDSXMLDefinition(rdbmsConfiguration));
    metaInfo.setName(database.getName());

    return metaInfo;
  }
 /**
  * Returns the fully qualified name of the database to be created. This will append an underscore
  * and the tenant's domain name to the database to make it unique for that particular tenant. It
  * will return the database name as it is, if it is created in Super tenant mode.
  *
  * @param databaseName Name of the database
  * @return Fully qualified name of the database
  * @throws RSSManagerException Is thrown if the functionality is interrupted
  */
 public static String getFullyQualifiedDatabaseName(String databaseName)
     throws RSSManagerException {
   String tenantDomain;
   try {
     tenantDomain =
         RSSManagerDataHolder.getInstance()
             .getTenantManager()
             .getDomain(CarbonContext.getThreadLocalCarbonContext().getTenantId());
   } catch (Exception e) {
     throw new RSSManagerException(
         "Error occurred while composing fully qualified name "
             + "of the database '"
             + databaseName
             + "'",
         e);
   }
   if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
     return databaseName + "_" + RSSManagerHelper.processDomainName(tenantDomain);
   }
   return databaseName;
 }