Ejemplo n.º 1
0
        private void UpdatePetRecords(ISession session, PlayerItem item, Dictionary <string, List <DBStatRow> > stats)
        {
            var records = GetRecordsForItem(item);

            var table = nameof(PlayerItemRecord);
            var id    = nameof(PlayerItemRecord.PlayerItemId);
            var rec   = nameof(PlayerItemRecord.Record);

            foreach (var record in GetPetBonusRecords(stats, records))
            {
                session.CreateSQLQuery(SqlUtils.EnsureDialect(Dialect, $"INSERT OR IGNORE INTO {table} ({id}, {rec}) VALUES (:id, :record)"))
                .SetParameter("id", item.Id)
                .SetParameter("record", record)
                .ExecuteUpdate();
            }
        }
Ejemplo n.º 2
0
        private void UpdatePetRecords(ISession session, BuddyItem item, Dictionary <string, List <DBStatRow> > stats)
        {
            var records = PlayerItemDaoImpl.GetRecordsForItem(item);

            var table = BuddyItemRecordTable.Table;
            var id    = BuddyItemRecordTable.Item;
            var rec   = BuddyItemRecordTable.Record;

            foreach (var record in PlayerItemDaoImpl.GetPetBonusRecords(stats, records))
            {
                Logger.Debug($"INSERT OR IGNORE INTO {table} ({id}, {rec}) VALUES ({item.RemoteItemId}, {record})");
                session.CreateSQLQuery(SqlUtils.EnsureDialect(Dialect, $"INSERT OR IGNORE INTO {table} ({id}, {rec}) VALUES (:id, :record)"))
                .SetParameter("id", item.RemoteItemId)
                .SetParameter("record", record)
                .ExecuteUpdate();
            }
        }
Ejemplo n.º 3
0
        private void UpdateRecords(ISession session, PlayerItem item)
        {
            var table = nameof(PlayerItemRecord);
            var id    = nameof(PlayerItemRecord.PlayerItemId);
            var rec   = nameof(PlayerItemRecord.Record);

            // INSERT INTO PlayerItemRecord (PlayerItemId, Record) VALUES (0, 'b') ON CONFLICT DO NOTHING;;
            var records = GetRecordsForItem(item);

            foreach (var record in records)
            {
                session.CreateSQLQuery(SqlUtils.EnsureDialect(Dialect, $"INSERT OR IGNORE INTO {table} ({id}, {rec}) VALUES (:id, :record)"))
                .SetParameter("id", item.Id)
                .SetParameter("record", record)
                .ExecuteUpdate();
            }
        }
Ejemplo n.º 4
0
        public void Update(IList <PlayerItem> items, bool clearOnlineId)
        {
            const string table = nameof(PlayerItem);
            const string stack = nameof(PlayerItem.StackCount);
            var          id    = nameof(PlayerItem.Id);

            using (var session = SessionCreator.OpenSession()) {
                using (var transaction = session.BeginTransaction()) {
                    foreach (var item in items)
                    {
                        // This is if an item has been deleted due to a transfer to stash
                        session.CreateQuery($"UPDATE {table} SET {stack} = :count, {PlayerItemTable.CloudId} = :uuid WHERE {id} = :id")
                        .SetParameter("count", item.StackCount)
                        .SetParameter("id", item.Id)
                        .SetParameter("uuid", item.CloudId)
                        .ExecuteUpdate();
                    }

                    // insert into DeletedPlayerItem(oid) select onlineid from playeritem where onlineid is not null and stackcount <= 0 and id in (1,2,3)
                    session.CreateSQLQuery(SqlUtils.EnsureDialect(Dialect,
                                                                  $" INSERT OR IGNORE INTO {DeletedPlayerItemTable.Table} ({DeletedPlayerItemTable.Id}) " +
                                                                  $" SELECT {PlayerItemTable.CloudId} FROM {PlayerItemTable.Table} " +
                                                                  $" WHERE {PlayerItemTable.CloudId} IS NOT NULL " +
                                                                  $" AND {PlayerItemTable.Stackcount} <= 0 " +
                                                                  $" AND {PlayerItemTable.Id} IN ( :ids )"))
                    .SetParameterList("ids", items.Select(m => m.Id).ToList())
                    .ExecuteUpdate();

                    // Delete any items with stacksize 0 (but only newly transferred ones, ignore any older items in case of errors)
                    session.CreateQuery($"DELETE FROM {table} WHERE {stack} <= 0 AND {id} IN ( :ids )")
                    .SetParameterList("ids", items.Select(m => m.Id).ToList())
                    .ExecuteUpdate();

                    transaction.Commit();
                }
            }
        }