/// <see cref="IFeatureStore.Get{T}(VersionedDataKind{T}, string)"/> public T Get <T>(VersionedDataKind <T> kind, string key) where T : class, IVersionedData { try { RwLock.TryEnterReadLock(RwLockMaxWaitMillis); IDictionary <string, IVersionedData> itemsOfKind; IVersionedData item; if (!Items.TryGetValue(kind, out itemsOfKind)) { Log.DebugFormat("Key {0} not found in '{1}'; returning null", key, kind.GetNamespace()); return(null); } if (!itemsOfKind.TryGetValue(key, out item)) { Log.DebugFormat("Key {0} not found in '{1}'; returning null", key, kind.GetNamespace()); return(null); } if (item.Deleted) { Log.WarnFormat("Attempted to get deleted item with key {0} in '{1}'; returning null.", key, kind.GetNamespace()); return(null); } return((T)item); } finally { RwLock.ExitReadLock(); } }
/// <inheritdoc/> public void Delete <T>(VersionedDataKind <T> kind, string key, int version) where T : IVersionedData { lock (WriterLock) { ImmutableDictionary <string, IVersionedData> itemsOfKind; if (Items.TryGetValue(kind, out itemsOfKind)) { IVersionedData item; if (!itemsOfKind.TryGetValue(key, out item) || item.Version < version) { ImmutableDictionary <string, IVersionedData> newItemsOfKind = itemsOfKind.SetItem(key, kind.MakeDeletedItem(key, version)); Items = Items.SetItem(kind, newItemsOfKind); } } } }
/// <inheritdoc/> public void Upsert <T>(VersionedDataKind <T> kind, T item) where T : IVersionedData { lock (WriterLock) { ImmutableDictionary <string, IVersionedData> itemsOfKind; if (!Items.TryGetValue(kind, out itemsOfKind)) { itemsOfKind = ImmutableDictionary <string, IVersionedData> .Empty; } IVersionedData old; if (!itemsOfKind.TryGetValue(item.Key, out old) || old.Version < item.Version) { ImmutableDictionary <string, IVersionedData> newItemsOfKind = itemsOfKind.SetItem(item.Key, item); Items = Items.SetItem(kind, newItemsOfKind); } } }
/// <inheritdoc/> public IDictionary <string, T> All <T>(VersionedDataKind <T> kind) where T : class, IVersionedData { IDictionary <string, T> ret = new Dictionary <string, T>(); ImmutableDictionary <string, IVersionedData> itemsOfKind; if (Items.TryGetValue(kind, out itemsOfKind)) { foreach (var entry in itemsOfKind) { if (!entry.Value.Deleted) { ret[entry.Key] = (T)entry.Value; } } } return(ret); }
/// <see cref="IFeatureStore.Delete{T}(VersionedDataKind{T}, string, int)"/> public void Delete <T>(VersionedDataKind <T> kind, string key, int version) where T : IVersionedData { try { RwLock.TryEnterWriteLock(RwLockMaxWaitMillis); IDictionary <string, IVersionedData> itemsOfKind; if (Items.TryGetValue(kind, out itemsOfKind)) { IVersionedData item; if (!itemsOfKind.TryGetValue(key, out item) || item.Version < version) { itemsOfKind[key] = kind.MakeDeletedItem(key, version); } } } finally { RwLock.ExitWriteLock(); } }
/// <see cref="IFeatureStore.Upsert{T}(VersionedDataKind{T}, T)"/> public void Upsert <T>(VersionedDataKind <T> kind, T item) where T : IVersionedData { try { RwLock.TryEnterWriteLock(RwLockMaxWaitMillis); IDictionary <string, IVersionedData> itemsOfKind; if (!Items.TryGetValue(kind, out itemsOfKind)) { itemsOfKind = new Dictionary <string, IVersionedData>(); Items[kind] = itemsOfKind; } IVersionedData old; if (!itemsOfKind.TryGetValue(item.Key, out old) || old.Version < item.Version) { itemsOfKind[item.Key] = item; } } finally { RwLock.ExitWriteLock(); } }
/// <inheritdoc/> public T Get <T>(VersionedDataKind <T> kind, string key) where T : class, IVersionedData { ImmutableDictionary <string, IVersionedData> itemsOfKind; IVersionedData item; if (!Items.TryGetValue(kind, out itemsOfKind)) { Log.DebugFormat("Key {0} not found in '{1}'; returning null", key, kind.GetNamespace()); return(null); } if (!itemsOfKind.TryGetValue(key, out item)) { Log.DebugFormat("Key {0} not found in '{1}'; returning null", key, kind.GetNamespace()); return(null); } if (item.Deleted) { Log.WarnFormat("Attempted to get deleted item with key {0} in '{1}'; returning null.", key, kind.GetNamespace()); return(null); } return((T)item); }
/// <see cref="IFeatureStore.All{T}(VersionedDataKind{T})"/> public IDictionary <string, T> All <T>(VersionedDataKind <T> kind) where T : class, IVersionedData { try { RwLock.TryEnterReadLock(RwLockMaxWaitMillis); IDictionary <string, T> ret = new Dictionary <string, T>(); IDictionary <string, IVersionedData> itemsOfKind; if (Items.TryGetValue(kind, out itemsOfKind)) { foreach (var entry in itemsOfKind) { if (!entry.Value.Deleted) { ret[entry.Key] = (T)entry.Value; } } } return(ret); } finally { RwLock.ExitReadLock(); } }
public void Delete <T>(VersionedDataKind <T> kind, string key, int version) where T : IVersionedData { _store.Delete(kind, key, version); }
public void Upsert <T>(VersionedDataKind <T> kind, T item) where T : IVersionedData { _store.Upsert(kind, item); }
public IDictionary <string, T> All <T>(VersionedDataKind <T> kind) where T : class, IVersionedData { return(_store.All(kind)); }
public T Get <T>(VersionedDataKind <T> kind, string key) where T : class, IVersionedData { return(_store.Get(kind, key)); }