Esempio n. 1
0
        /// <summary>
        /// Put bookmark entity into the cache. <br/>
        /// Referential integrity check is done on: <br/>
        /// Bookmark.PersonID - Person.key <br/>
        /// Bookmark.ObjectID - Object.key <br/>
        /// </summary>
        /// <param name="value">Bookmark to put into the cache.</param>
        public static void PutBookmark (Bookmark value)
        {
            using (var tx = Client.GetTransactions().TxStart())
            {
                // Error if Person with key = value.ClientID is not found.
                if (!(PersonCache.ContainsKey(value.PersonID)))
                {
                    tx.Commit();
                    throw new ReferentialException ("Can not put new entry into Bookmark cache.")
                    {
                        Operation = "put",
                        TableName = "Bookmark",
                        FieldName = "PersonID",
                        ReadableMessage = $"Can not put new entry into Bookmark cache because Person with key {value.PersonID} 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 Bookmark cache.")
                    {
                        Operation = "put",
                        TableName = "Bookmark",
                        FieldName = "ObjectID",
                        ReadableMessage = $"Can not put new entry into Bookmark cache because EstateObject with key {value.ObjectID} does not exist."
                    };
                }

                // Normal operation
                long key = (((long)value.PersonID)<<32) + value.ObjectID;
                BookmarkCache.Put (key, value);
                tx.Commit();
            }
        }