public void updateSystemRoleListOfUser(String user, String[] deletedRoles, String[] addRoles)
      throws UserStoreException {

    String sqlStmt1 = SystemJDBCConstants.REMOVE_ROLE_FROM_USER_SQL;
    String sqlStmt2 = SystemJDBCConstants.ADD_ROLE_TO_USER_SQL;
    Connection dbConnection = null;
    try {
      dbConnection = DatabaseUtil.getDBConnection(dataSource);
      String type = null;
      if (UserCoreConstants.MSSQL_TYPE.equals(type)) {
        sqlStmt2 = SystemJDBCConstants.ADD_ROLE_TO_USER_SQL_MSSQL;
      }
      if (deletedRoles != null && deletedRoles.length > 0) {
        DatabaseUtil.udpateUserRoleMappingInBatchMode(
            dbConnection, sqlStmt1, deletedRoles, tenantId, user, tenantId);
      }
      if (addRoles != null && addRoles.length > 0) {
        if (UserCoreConstants.OPENEDGE_TYPE.equals(type)) {
          sqlStmt2 = SystemJDBCConstants.ADD_ROLE_TO_USER_SQL_OPENEDGE;
          DatabaseUtil.udpateUserRoleMappingInBatchMode(
              dbConnection, sqlStmt2, user, tenantId, addRoles, tenantId);
        } else {
          DatabaseUtil.udpateUserRoleMappingInBatchMode(
              dbConnection, sqlStmt2, addRoles, tenantId, user, tenantId);
        }
      }
      dbConnection.commit();
    } catch (SQLException e) {
      String errorMessage = "Error occurred while getting system role list of user : "******"Error occurred while getting database type from DB connection";
      //            if (log.isDebugEnabled()) {
      //                log.debug(errorMessage, e);
      //            }
      throw new UserStoreException(errorMessage, e);
    } finally {
      DatabaseUtil.closeAllConnections(dbConnection);
    }
  }
 public void addSystemRole(String roleName, String[] userList) throws UserStoreException {
   Connection dbConnection = null;
   try {
     dbConnection = DatabaseUtil.getDBConnection(dataSource);
     if (!this.isExistingRole(roleName)) {
       DatabaseUtil.updateDatabase(
           dbConnection, SystemJDBCConstants.ADD_ROLE_SQL, roleName, tenantId);
     }
     if (userList != null) {
       String sql = SystemJDBCConstants.ADD_USER_TO_ROLE_SQL;
       String type = null;
       if (UserCoreConstants.MSSQL_TYPE.equals(type)) {
         sql = SystemJDBCConstants.ADD_USER_TO_ROLE_SQL_MSSQL;
       }
       if (UserCoreConstants.OPENEDGE_TYPE.equals(type)) {
         sql = SystemJDBCConstants.ADD_USER_TO_ROLE_SQL_OPENEDGE;
         DatabaseUtil.udpateUserRoleMappingInBatchMode(
             dbConnection, sql, userList, tenantId, roleName, tenantId);
       } else {
         DatabaseUtil.udpateUserRoleMappingInBatchMode(
             dbConnection, sql, userList, roleName, tenantId, tenantId);
       }
     }
     dbConnection.commit();
   } catch (SQLException e) {
     String errorMessage = "Error occurred while adding system role : " + roleName;
     //            if (log.isDebugEnabled()) {
     //                log.debug(errorMessage, e);
     //            }
     throw new UserStoreException(errorMessage, e);
   } catch (Exception e) {
     String errorMessage = "Error occurred while getting database type from DB connection";
     //            if (log.isDebugEnabled()) {
     //                log.debug(errorMessage, e);
     //            }
     throw new UserStoreException(errorMessage, e);
   } finally {
     DatabaseUtil.closeAllConnections(dbConnection);
   }
 }