main
1using System;
2using System.Collections.Generic;
3using gorilla.commons.utility;
4
5namespace momoney.database.transactions
6{
7 public class IdentityMapProxy<Key, Value> : IIdentityMap<Key, Value> where Value : Identifiable<Guid>
8 {
9 readonly IIdentityMap<Key, Value> real_map;
10 readonly IChangeTracker<Value> change_tracker;
11
12 public IdentityMapProxy(IChangeTracker<Value> change_tracker, IIdentityMap<Key, Value> real_map)
13 {
14 this.change_tracker = change_tracker;
15 this.real_map = real_map;
16 }
17
18 public IEnumerable<Value> all()
19 {
20 return real_map.all();
21 }
22
23 public void add(Key key, Value value)
24 {
25 change_tracker.register(value);
26 real_map.add(key, value);
27 }
28
29 public void update_the_item_for(Key key, Value new_value)
30 {
31 real_map.update_the_item_for(key, new_value);
32 }
33
34 public bool contains_an_item_for(Key key)
35 {
36 return real_map.contains_an_item_for(key);
37 }
38
39 public Value item_that_belongs_to(Key key)
40 {
41 return real_map.item_that_belongs_to(key);
42 }
43
44 public void evict(Key key)
45 {
46 change_tracker.delete(real_map.item_that_belongs_to(key));
47 real_map.evict(key);
48 }
49 }
50}