/// <summary> /// Returns List of user tables starting from specified mask. /// If mask is String.Empty returns all user tables /// </summary> /// <param name="mask"></param> /// <returns></returns> public List <string> GetUserTableNamesStartingWith(string mask) { List <string> ret = new List <string>(); //No lock here, while IterateForwardStartsWith of the LTrie is safe (new root is created), and we don't acquire value from the key (which could be delete). //_sync_openTablesHolder.EnterReadLock(); //try //{ byte[] btKeyName = Encoding.UTF8.GetBytes("@ut" + mask); foreach (var row in LTrie.IterateForwardStartsWith(btKeyName, true, false)) { //try //try-catch could be necessary in case if we acquire value, which was deleted by other thread. Here we don't acquire value. //{ ret.Add(System.Text.Encoding.UTF8.GetString(row.Key).Substring(3)); //} //catch //{} } //} //finally //{ // _sync_openTablesHolder.ExitReadLock(); //} return(ret); }
/// <summary> /// SelectStartsWith. /// Value instance, when byte[], must stay immutable, please use Dbreeze.Utils.CloneArray /// </summary> /// <typeparam name="TValue"></typeparam> /// <param name="resourceNameStartsWith"></param> /// <param name="resourceSettings"></param> /// <returns></returns> public IEnumerable <KeyValuePair <string, TValue> > SelectStartsWith <TValue>(string resourceNameStartsWith, Settings resourceSettings = null) { if (!String.IsNullOrEmpty(resourceNameStartsWith)) { if (resourceSettings == null) { resourceSettings = _defaultSetting; } byte[] val = null; string rn = String.Empty; byte[] btKey = null; _sync.EnterUpgradeableReadLock(); btKey = DataTypesConvertor.ConvertKey <string>(_urp + resourceNameStartsWith); var q = LTrie.IterateForwardStartsWith(btKey, true, false); if (!resourceSettings.SortingAscending) { q = LTrie.IterateBackwardStartsWith(btKey, true, false); } foreach (var el in q) { rn = el.Key.UTF8_GetString(); if (!_d.TryGetValue(rn, out val)) { val = el.GetFullValue(false); if (resourceSettings.HoldInMemory) { _sync.EnterWriteLock(); try { _d[rn] = val; } catch (Exception) { } finally { _sync.ExitWriteLock(); } } } //no try..catch for yield return yield return(new KeyValuePair <string, TValue>(rn.Substring(1), val == null ? default(TValue) : DataTypesConvertor.ConvertBack <TValue>(val))); } _sync.ExitUpgradeableReadLock(); }//if is null or }