Advertisement
Inverness

IKeyValueStore.cs

May 9th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Text;
  5.  
  6. namespace Ramp.Data
  7. {
  8.     /// <summary>
  9.     ///     Represents a key value store that stores values as strings.
  10.     /// </summary>
  11.     public interface IKeyValueStore
  12.     {
  13.         /// <summary>
  14.         ///     Gets the name of the default bucket used if null is specified for a bucket argument.
  15.         /// </summary>
  16.         string DefaultBucketName { get; }
  17.  
  18.         /// <summary>
  19.         ///     Gets the name of the bucket used for storing metadata.
  20.         /// </summary>
  21.         string MetadataBucketName { get; }
  22.  
  23.         /// <summary>
  24.         ///     Gets the encoding used for strings.
  25.         /// </summary>
  26.         Encoding Encoding { get; }
  27.  
  28.         /// <summary>
  29.         ///     Get a string from the store. Returns defaultValue if no key is found.
  30.         /// </summary>
  31.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  32.         /// <param name="key"> The key. </param>
  33.         /// <param name="defaultValue"> The default value. </param>
  34.         /// <returns> The matching string, or defaultValue if not found. </returns>
  35.         /// <exception cref="ArgumentNullException"> Bucket or key is null. </exception>
  36.         string GetStringOrDefault(string bucket, string key, string defaultValue = null);
  37.  
  38.         /// <summary>
  39.         ///     Tries getting a string from the store.
  40.         /// </summary>
  41.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  42.         /// <param name="key"> The key. </param>
  43.         /// <param name="value"> The resulting value. </param>
  44.         /// <returns> True if the value was found. </returns>
  45.         /// <exception cref="ArgumentNullException"> Bucket or key is null. </exception>
  46.         bool TryGetString(string bucket, string key, out string value);
  47.  
  48.         /// <summary>
  49.         ///     Get a byte array from the store. Returns defaultValue if no key is found.
  50.         /// </summary>
  51.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  52.         /// <param name="key"> The key. </param>
  53.         /// <param name="defaultValue"> The default value. </param>
  54.         /// <returns> The matching byte array, or null if not found. </returns>
  55.         /// <exception cref="ArgumentNullException"> Bucket or key is null. </exception>
  56.         byte[] GetBytesOrDefault(string bucket, string key, byte[] defaultValue = null);
  57.  
  58.         /// <summary>
  59.         ///     Tries getting a byte array from the store.
  60.         /// </summary>
  61.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  62.         /// <param name="key"> The key. </param>
  63.         /// <param name="value"> The resulting value. </param>
  64.         /// <returns> True if the value was found. </returns>
  65.         /// <exception cref="ArgumentNullException"> Bucket or key is null. </exception>
  66.         bool TryGetBytes(string bucket, string key, out byte[] value);
  67.  
  68.         /// <summary>
  69.         ///     Get a generic value from the store using a TypeConverter. Returns defaultValue if no key is found or
  70.         ///     converting the value to T fails.
  71.         /// </summary>
  72.         /// <typeparam name="T"> A type convertible from a string. </typeparam>
  73.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  74.         /// <param name="key"> The key. </param>
  75.         /// <param name="defaultValue"> The default value. </param>
  76.         /// <returns> The value. </returns>
  77.         /// <exception cref="ArgumentNullException"> Key is null. </exception>
  78.         T GetValueOrDefault<T>(string bucket, string key, T defaultValue = default(T));
  79.  
  80.         /// <summary>
  81.         ///     Tries getting a value from the store.
  82.         /// </summary>
  83.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  84.         /// <param name="key"> The key. </param>
  85.         /// <param name="value"> The resulting value. </param>
  86.         /// <returns> True if the value was found and converted. </returns>
  87.         /// <exception cref="ArgumentNullException"> Bucket or key is null. </exception>
  88.         bool TryGetValue<T>(string bucket, string key, out T value);
  89.  
  90.         /// <summary>
  91.         ///     Set a string value in the store. Will add a new entry or overwrite an existing entry in the store.
  92.         ///     The string will be UTF8 encoded.
  93.         /// </summary>
  94.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  95.         /// <param name="key"> The key. </param>
  96.         /// <param name="value"> The value. </param>
  97.         /// <exception cref="ArgumentNullException"> Key is null. </exception>
  98.         void Set(string bucket, string key, string value);
  99.  
  100.         /// <summary>
  101.         ///     Set a byte array value in the store. Will add a new entry or overwrite an existing entry in the store.
  102.         /// </summary>
  103.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  104.         /// <param name="key"> The key. </param>
  105.         /// <param name="value"> The value. </param>
  106.         /// <exception cref="ArgumentNullException"> Key is null. </exception>
  107.         void Set(string bucket, string key, byte[] value);
  108.  
  109.         /// <summary>
  110.         ///     Set a generic value in the store. The type must be convertible to a string. Will add a new entry or
  111.         ///     overwrite an existing entry in the store.
  112.         /// </summary>
  113.         /// <typeparam name="T"> A type convertible to a string. </typeparam>
  114.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  115.         /// <param name="key"> The key. </param>
  116.         /// <param name="value"> The value. </param>
  117.         /// <exception cref="ArgumentNullException"> Key is null. </exception>
  118.         void Set<T>(string bucket, string key, T value);
  119.  
  120.         /// <summary>
  121.         ///     Delete an entry from the store.
  122.         /// </summary>
  123.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  124.         /// <param name="key"> The key. </param>
  125.         /// <returns> True if a matching entry was found and deleted. </returns>
  126.         /// <exception cref="ArgumentNullException"> Key is null. </exception>
  127.         bool Delete(string bucket, string key);
  128.  
  129.         /// <summary>
  130.         ///     Check if an entry exists in the store.
  131.         /// </summary>
  132.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  133.         /// <param name="key"> The key. </param>
  134.         /// <returns> True if the entry exists. </returns>
  135.         /// <exception cref="ArgumentNullException"> Key is null. </exception>
  136.         bool Exists(string bucket, string key);
  137.  
  138.         /// <summary>
  139.         ///     Get all keys and values within a bucket as byte arrays.
  140.         /// </summary>
  141.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  142.         /// <returns></returns>
  143.         IEnumerable<KeyValuePair<string, byte[]>> GetItemBytes(string bucket);
  144.  
  145.         /// <summary>
  146.         ///     Get all keys and values within a bucket as strings.
  147.         /// </summary>
  148.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  149.         /// <returns></returns>
  150.         IEnumerable<KeyValuePair<string, string>> GetItemStrings(string bucket);
  151.  
  152.         /// <summary>
  153.         ///     Get all key names within a bucket.
  154.         /// </summary>
  155.         /// <param name="bucket"> The bucket, or null to use the default bucket. </param>
  156.         /// <returns></returns>
  157.         IEnumerable<string> GetKeys(string bucket);
  158.  
  159.         /// <summary>
  160.         ///     Begin a transaction with the underlying database.
  161.         /// </summary>
  162.         /// <returns> A database transaction object. </returns>
  163.         IDbTransaction BeginTransaction();
  164.  
  165.         /// <summary>
  166.         ///     Begin a transaction with the underlying database.
  167.         /// </summary>
  168.         /// <param name="isolationLevel"> The transaction isolation level. </param>
  169.         /// <returns> A database transaction object. </returns>
  170.         IDbTransaction BeginTransaction(IsolationLevel isolationLevel);
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement