/// <summary> /// Inserts a batch of <see cref="SVR_AnimeGroup_User"/> into the database. /// </summary> /// <remarks> /// <para>This method should NOT be used for updating existing entities.</para> /// <para>It is up to the caller of this method to manage transactions, etc.</para> /// <para>Group Filters, etc. will not be updated by this method.</para> /// </remarks> /// <param name="session">The NHibernate session.</param> /// <param name="groupUsers">The batch of <see cref="SVR_AnimeGroup_User"/> to insert into the database.</param> /// <exception cref="ArgumentNullException"><paramref name="session"/> or <paramref name="groupUsers"/> is <c>null</c>.</exception> public void InsertBatch(ISessionWrapper session, IEnumerable <SVR_AnimeGroup_User> groupUsers) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (groupUsers == null) { throw new ArgumentNullException(nameof(groupUsers)); } foreach (SVR_AnimeGroup_User groupUser in groupUsers) { session.Insert(groupUser); ChangeTracker <int> changeTracker; if (!Changes.TryGetValue(groupUser.JMMUserID, out changeTracker)) { changeTracker = new ChangeTracker <int>(); Changes[groupUser.JMMUserID] = changeTracker; } changeTracker.AddOrUpdate(groupUser.AnimeGroupID); } }
/// <summary> /// Inserts a batch of <see cref="SVR_GroupFilter"/>s. /// </summary> /// <remarks> /// This method ONLY updates existing <see cref="SVR_GroupFilter"/>s. It will not insert any that don't already exist. /// </remarks> /// <param name="session">The NHibernate session.</param> /// <param name="groupFilters">The batch of <see cref="SVR_GroupFilter"/>s to update.</param> /// <exception cref="ArgumentNullException"><paramref name="session"/> or <paramref name="groupFilters"/> is <c>null</c>.</exception> public void BatchInsert(ISessionWrapper session, IEnumerable <SVR_GroupFilter> groupFilters) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (groupFilters == null) { throw new ArgumentNullException(nameof(groupFilters)); } lock (globalDBLock) { lock (Cache) { foreach (SVR_GroupFilter groupFilter in groupFilters) { lock (groupFilter) { session.Insert(groupFilter); Cache.Update(groupFilter); } } } } }
public void InsertBatch(ISessionWrapper session, IReadOnlyCollection <SVR_AnimeGroup> groups) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (groups == null) { throw new ArgumentNullException(nameof(groups)); } foreach (SVR_AnimeGroup group in groups) { lock (globalDBLock) { lock (group) { session.Insert(group); lock (Cache) { Cache.Update(group); } } } } Changes.AddOrUpdateRange(groups.Select(g => g.AnimeGroupID)); }
//This function do not run the BeginDeleteCallback and the EndDeleteCallback public virtual void SaveWithOpenTransaction(ISessionWrapper session, T obj) { if (Equals(SelectKey(obj), default(S))) { session.Insert(obj); } else { session.Update(obj); } SaveWithOpenTransactionCallback?.Invoke(session, obj); Cache.Update(obj); }
/// <summary> /// Creates a new group that series will be put in during group re-calculation. /// </summary> /// <param name="session">The NHibernate session.</param> /// <returns>The temporary <see cref="SVR_AnimeGroup"/>.</returns> private SVR_AnimeGroup CreateTempAnimeGroup(ISessionWrapper session) { DateTime now = DateTime.Now; var tempGroup = new SVR_AnimeGroup { GroupName = TempGroupName, Description = TempGroupName, SortName = TempGroupName, DateTimeUpdated = now, DateTimeCreated = now }; // We won't use AnimeGroupRepository.Save because we don't need to perform all the extra stuff since this is for temporary use only session.Insert(tempGroup); return(tempGroup); }
public void InsertBatch(ISessionWrapper session, IReadOnlyCollection <AnimeGroup> groups) { if (session == null) { throw new ArgumentNullException(nameof(session)); } if (groups == null) { throw new ArgumentNullException(nameof(groups)); } foreach (AnimeGroup group in groups) { session.Insert(group); } Changes.AddOrUpdateRange(groups.Select(g => g.AnimeGroupID)); }
private void CreateAllTagFilters(ISessionWrapper session, SVR_GroupFilter tagsdirec, Dictionary <int, ILookup <string, int> > lookup) { if (tagsdirec == null) { return; } HashSet <string> alltags = new HashSet <string>( RepoFactory.AniDB_Tag.GetAllForLocalSeries().Select(a => a.TagName.Replace('`', '\'')), StringComparer.InvariantCultureIgnoreCase); List <SVR_GroupFilter> toAdd = new List <SVR_GroupFilter>(alltags.Count); var users = RepoFactory.JMMUser.GetAll().ToList(); //AniDB Tags are in english so we use en-us culture TextInfo tinfo = new CultureInfo("en-US", false).TextInfo; foreach (string s in alltags) { SVR_GroupFilter yf = new SVR_GroupFilter { ParentGroupFilterID = tagsdirec.GroupFilterID, InvisibleInClients = 0, ApplyToSeries = 1, GroupFilterName = tinfo.ToTitleCase(s), BaseCondition = 1, Locked = 1, SortingCriteria = "5;1", FilterType = (int)GroupFilterType.Tag, }; yf.SeriesIds[0] = lookup[0][s.ToLowerInvariant()].ToHashSet(); yf.GroupsIds[0] = yf.SeriesIds[0] .Select(id => RepoFactory.AnimeSeries.GetByID(id).TopLevelAnimeGroup?.AnimeGroupID ?? -1) .Where(id => id != -1).ToHashSet(); foreach (var user in users) { yf.SeriesIds[user.JMMUserID] = lookup[user.JMMUserID][s.ToLowerInvariant()].ToHashSet(); yf.GroupsIds[user.JMMUserID] = yf.SeriesIds[user.JMMUserID] .Select(id => RepoFactory.AnimeSeries.GetByID(id).TopLevelAnimeGroup?.AnimeGroupID ?? -1) .Where(id => id != -1).ToHashSet(); } using (var trans = session.BeginTransaction()) { // get an ID session.Insert(yf); trans.Commit(); } GroupFilterCondition gfc = new GroupFilterCondition { ConditionType = (int)GroupFilterConditionType.Tag, ConditionOperator = (int)GroupFilterOperator.In, ConditionParameter = s, GroupFilterID = yf.GroupFilterID }; yf.Conditions.Add(gfc); yf.UpdateEntityReferenceStrings(); yf.GroupConditions = Newtonsoft.Json.JsonConvert.SerializeObject(yf._conditions); yf.GroupConditionsVersion = SVR_GroupFilter.GROUPCONDITIONS_VERSION; toAdd.Add(yf); } lock (Cache) { Populate(session, false); lock (globalDBLock) { foreach (var filters in toAdd.Batch(50)) { using (ITransaction trans = session.BeginTransaction()) { BatchUpdate(session, filters); trans.Commit(); } } } } }
/// <summary> /// Creates a new group that series will be put in during group re-calculation. /// </summary> /// <param name="session">The NHibernate session.</param> /// <returns>The temporary <see cref="AnimeGroup"/>.</returns> private AnimeGroup CreateTempAnimeGroup(ISessionWrapper session) { DateTime now = DateTime.Now; var tempGroup = new AnimeGroup { GroupName = TempGroupName, Description = TempGroupName, SortName = TempGroupName, DateTimeUpdated = now, DateTimeCreated = now }; // We won't use AnimeGroupRepository.Save because we don't need to perform all the extra stuff since this is for temporary use only session.Insert(tempGroup); return tempGroup; }