コード例 #1
0
ファイル: BuddyItemDaoImpl.cs プロジェクト: 211847750/iagd
        public void Save(BuddySubscription subscription, List <BuddyItem> items)
        {
            using (ISession session = SessionCreator.OpenSession()) {
                using (ITransaction transaction = session.BeginTransaction()) {
                    foreach (var item in items)
                    {
                        item.BuddyId = subscription.Id;
                        session.Save(item);
                    }


                    // Update / Insert records into lookup table
                    foreach (var item in items)
                    {
                        foreach (var record in new[] { item.BaseRecord, item.PrefixRecord, item.SuffixRecord, item.MateriaRecord })
                        {
                            if (!string.IsNullOrEmpty(record))
                            {
                                session.CreateSQLQuery(
                                    $@"INSERT OR IGNORE INTO {BuddyItemRecordTable.Table} ({BuddyItemRecordTable.Item}, {BuddyItemRecordTable.Record}) 
                                                VALUES (:id, :record)")
                                .SetParameter("id", item.RemoteItemId)
                                .SetParameter("record", record)
                                .ExecuteUpdate();
                            }
                        }
                    }

                    transaction.Commit();
                }

                UpdatePetRecords(session, items);
            }
        }
コード例 #2
0
ファイル: BuddyItemDaoImpl.cs プロジェクト: 211847750/iagd
 public IList <string> GetOnlineIds(BuddySubscription subscription)
 {
     using (ISession session = SessionCreator.OpenSession()) {
         using (session.BeginTransaction()) {
             return(session.CreateCriteria <BuddyItem>()
                    .Add(Restrictions.Eq(nameof(BuddyItem.BuddyId), subscription.Id))
                    .SetProjection(Projections.Property(nameof(BuddyItem.RemoteItemId)))
                    .List <string>());
         }
     }
 }
コード例 #3
0
ファイル: BuddyItemDaoImpl.cs プロジェクト: 211847750/iagd
        public void Delete(BuddySubscription subscription, List <DeleteItemDto> items)
        {
            using (ISession session = SessionCreator.OpenSession()) {
                using (ITransaction transaction = session.BeginTransaction()) {
                    foreach (var item in items)
                    {
                        session.CreateSQLQuery($@"DELETE FROM {BuddyItemsTable.Table} 
                                WHERE {BuddyItemsTable.RemoteItemId} = :cloudId
                                AND {BuddyItemsTable.SubscriptionId} = :subscriptionId")
                        .SetParameter("cloudId", item.Id)
                        .SetParameter("subscriptionId", subscription.Id)
                        .ExecuteUpdate();
                    }

                    // Remove record from records table (lookup table)
                    session.CreateSQLQuery($"DELETE FROM {BuddyItemRecordTable.Table} WHERE NOT {BuddyItemRecordTable.Item} IN (SELECT {BuddyItemsTable.RemoteItemId} FROM {BuddyItemsTable.Table})")
                    .ExecuteUpdate();

                    transaction.Commit();
                }
            }
        }