public static Dictionary <int, ClientWish> GetWishesByPerson(int id) { Dictionary <int, ClientWish> result = new Dictionary <int, ClientWish>(); foreach (var row in ClientWishCache.Query(new SqlFieldsQuery($"select _key, _val, ClientID from ClientWishes where ClientID={id};"))) { result[(int)(row[0])] = (ClientWish)(row[1]); } return(result); }
/// <summary> /// Put ClientWish entity into the cache. <br/> /// Referential integrity check is done on: <br/> /// ClientWish.ClientID - Person.key <br/> /// ClientWish.LocationID - Location.key /// </summary> /// <param name="value">ClientWish to put into the cache.</param> public static void PutClientWish (ClientWish value) { using (var tx = Client.GetTransactions().TxStart()) { // Error if Person with key = value.ClientID is not found. if (!(PersonCache.ContainsKey(value.ClientID))) { tx.Commit(); throw new ReferentialException ("Can not put new entry into ClientWish cache.") { Operation = "put", TableName = "ClientWish", FieldName = "ClientID", ReadableMessage = $"Can not put new entry into ClientWish cache because Person with key {value.ClientID} does not exist." }; } // Error if Location not found. if (!(LocationCache.ContainsKey(value.LocationID))) { tx.Commit(); throw new ReferentialException ("Can not put new entry into ClientWish cache.") { Operation = "put", TableName = "ClientWish", FieldName = "LocationID", ReadableMessage = $"Can not put new entry into ClientWish cache because Location with key {value.LocationID} does not exist." }; } // Normal operation. int key = LastUsedKeys.Get ("clientwish"); ClientWishCache.Put (key, value); LastUsedKeys.Put ("clientwish", key+1); tx.Commit(); } }
/// <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(); } }