/// <summary> /// Deletes all AnimeGroup records. /// </summary> /// <remarks> /// This method also makes sure that the cache is cleared. /// </remarks> /// <param name="session">The NHibernate session.</param> /// <param name="excludeGroupId">The ID of the AnimeGroup to exclude from deletion.</param> /// <exception cref="ArgumentNullException"><paramref name="session"/> is <c>null</c>.</exception> public void DeleteAll(ISessionWrapper session, int?excludeGroupId = null) { if (session == null) { throw new ArgumentNullException(nameof(session)); } // First, get all of the current groups so that we can inform the change tracker that they have been removed later var allGrps = GetAll(); lock (globalDBLock) { // Then, actually delete the AnimeGroups if (excludeGroupId != null) { session.CreateQuery("delete SVR_AnimeGroup ag where ag.id <> :excludeId") .SetInt32("excludeId", excludeGroupId.Value) .ExecuteUpdate(); lock (Changes) { Changes.RemoveRange(allGrps.Select(g => g.AnimeGroupID) .Where(id => id != excludeGroupId.Value)); } } else { session.CreateQuery("delete SVR_AnimeGroup ag") .ExecuteUpdate(); lock (Changes) { Changes.RemoveRange(allGrps.Select(g => g.AnimeGroupID)); } } } // Finally, we need to clear the cache so that it is in sync with the database ClearCache(); // If we're exlcuding a group from deletion, and it was in the cache originally, then re-add it back in if (excludeGroupId != null) { SVR_AnimeGroup excludedGroup = allGrps.FirstOrDefault(g => g.AnimeGroupID == excludeGroupId.Value); if (excludedGroup != null) { lock (Cache) { Cache.Update(excludedGroup); } } } }
/// <summary> /// Deletes all AnimeGroup_User records. /// </summary> /// <remarks> /// This method also makes sure that the cache is cleared. /// </remarks> /// <param name="session">The NHibernate session.</param> /// <exception cref="ArgumentNullException"><paramref name="session"/> is <c>null</c>.</exception> public void DeleteAll(ISessionWrapper session) { if (session == null) { throw new ArgumentNullException(nameof(session)); } // First, get all of the current user/groups so that we can inform the change tracker that they have been removed later var usrGrpMap = GetAll() .GroupBy(g => g.JMMUserID, g => g.AnimeGroupID); // Then, actually delete the AnimeGroup_Users session.CreateQuery("delete AnimeGroup_User agu") .ExecuteUpdate(); // Now, update the change trackers with all removed records foreach (var grp in usrGrpMap) { int jmmUserId = grp.Key; ChangeTracker <int> changeTracker; if (!Changes.TryGetValue(jmmUserId, out changeTracker)) { changeTracker = new ChangeTracker <int>(); Changes[jmmUserId] = changeTracker; } changeTracker.RemoveRange(grp); } // Finally, we need to clear the cache so that it is in sync with the database ClearCache(); }
public ILookup <int, AniDB_Tag> GetByAnimeIDs(ISessionWrapper session, int[] ids) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (ids == null) { throw new ArgumentNullException(nameof(ids)); } if (ids.Length == 0) { return(EmptyLookup <int, AniDB_Tag> .Instance); } var tags = session .CreateQuery( "Select xref.AnimeID, tag FROM AniDB_Tag as tag, AniDB_Anime_Tag as xref WHERE tag.TagID = xref.TagID AND xref.AnimeID IN (:animeIDs)") .SetParameterList("animeIDs", ids) .List <object[]>() .ToLookup(t => (int)t[0], t => (AniDB_Tag)t[1]); return(tags); }
private void DropAllTagFilters(ISessionWrapper session) { lock (globalDBLock) { lock (Cache) { ClearCache(); } using (ITransaction trans = session.BeginTransaction()) { session.CreateQuery("DELETE FROM " + nameof(SVR_GroupFilter) + " WHERE FilterType = " + (int)GroupFilterType.Tag + ";") .ExecuteUpdate(); trans.Commit(); } } }
public List <string> GetAllTagNames(ISessionWrapper session) { return(session.CreateQuery("SELECT DISTINCT TagName FROM AniDB_Tag").List <string>().ToList()); }