示例#1
0
        /// <summary>
        /// Put match entity into the cache. <br/>
        /// Referential integrity check is done on: <br/>
        /// Match.WishID - ClientWish.key <br/>
        /// Match.ObjectID - Object.key <br/>
        /// </summary>
        /// <param name="value">Match to put into the cache.</param>
        public static void PutMatch (Match value)
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Error if ClientWish with key = value.WishID is not found.
                if (!(ClientWishCache.ContainsKey(value.WishID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Match cache.")
                    {
                        Operation = "put",
                        TableName = "Match",
                        FieldName = "WishID",
                        ReadableMessage = $"Can not put new entry into Match cache because ClientWish with key {value.WishID} does not exist."
                    };
                }

                // Error if EstateObject with key = value.ObjectID is not found.
                if (!(ObjectCache.ContainsKey(value.ObjectID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Match cache.")
                    {
                        Operation = "put",
                        TableName = "Match",
                        FieldName = "ObjectID",
                        ReadableMessage = $"Can not put new entry into Match cache because EstateObject with key {value.ObjectID} does not exist."
                    };
                }
                
                // Normal operation
                long key = (((long)value.WishID)<<32) + value.ObjectID;
                MatchCache.Put (key, value);
                tx.Commit();
            }
        }