/// <summary> /// Gets the stored data. /// This method should not alter the database in any way. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="query">The query.</param> /// <returns></returns> /// <exception cref="System.Exception"></exception> public Task<JArray> GetStoredData(string tableName, IQueryOptions query) { Debug.WriteLine("Retrieving data for table {0}, query: {1}", tableName, query.ToString()); EnsureDatabaseThread(); try { //check if database exists if (!db.DoesTableExist(tableName)) { Debug.WriteLine("Table doesn't exist: {0}", tableName); return Task.FromResult(new JArray()); } Debug.WriteLine("Table exists: {0}", tableName); Debug.WriteLine("Querying table structure for table: {0}", tableName); IDictionary<string, Column> columns = db.GetColumnsForTable(tableName); Debug.WriteLine("Table {0} has columns: {1}", tableName, string.Join<Column>("\n", columns.Values)); SQLiteExpressionVisitor visitor = new SQLiteExpressionVisitor(); visitor.VisitQueryOptions(query); var sqlStatement = string.Format(visitor.SqlStatement, tableName); Debug.WriteLine("Executing sql: {0}", sqlStatement); return Task.FromResult(db.Query(sqlStatement, columns)); } catch (SQLiteException ex) { throw new Exception(string.Format("Error occurred during interaction with the local database: {0}", ex.Message)); } }
protected virtual string FindCacheKey <TResult>(ISpecification <T> criteria, IQueryOptions <T> queryOptions, Expression <Func <T, TResult> > selector) { return(String.Format("{0}/{1}/{2}/{3}", FullCachePrefix, TypeFullName, "Find", Md5Helper.CalculateMd5(criteria + "::" + (queryOptions != null ? queryOptions.ToString() : "null") + "::" + (selector != null ? selector.ToString() : "null")))); }
protected virtual string GetAllCacheKey <TResult>(IQueryOptions <T> queryOptions, Expression <Func <T, TResult> > selector) { return(String.Format("{0}/{1}/{2}", FullCachePrefix, TypeFullName, Md5Helper.CalculateMd5("All::" + (queryOptions != null ? queryOptions.ToString() : "null") + "::" + (selector != null ? selector.ToString() : "null")))); }
private static string FormatQueryOptions <T>([CanBeNull] IQueryOptions <T> options) { return(options != null?options.ToString() : $"QueryOptions<{Name<T>()}>: [ null ]"); }
protected override string FindCacheKey <TResult>(ISpecification <T> criteria, IQueryOptions <T> queryOptions, Expression <Func <T, TResult> > selector) { if (TryPartitionValue(criteria, out TPartition partition)) { return ($"{FullCachePrefix}/{TypeFullName}/p:{partition}/{GetPartitionGeneration(partition)}/Find/{Md5Helper.CalculateMd5(criteria + "::" + (queryOptions != null ? queryOptions.ToString() : "null") + "::" + (selector != null ? selector.ToString() : "null"))}"); } return ($"{FullCachePrefix}/{TypeFullName}/{GetGeneration()}/Find/{Md5Helper.CalculateMd5(criteria + "::" + (queryOptions != null ? queryOptions.ToString() : "null") + "::" + (selector != null ? selector.ToString() : "null"))}"); }
protected override string GetAllCacheKey <TResult>(IQueryOptions <T> queryOptions, Expression <Func <T, TResult> > selector) { return ($"{FullCachePrefix}/{TypeFullName}/{GetGeneration()}/{Md5Helper.CalculateMd5("All::" + (queryOptions != null ? queryOptions.ToString() : "null") + "::" + (selector != null ? selector.ToString() : "null"))}"); }
protected override string FindCacheKey <TResult>(ISpecification <T> criteria, IQueryOptions <T> queryOptions, Expression <Func <T, TResult> > selector) { if (TryPartitionValue(criteria, out TPartition partition)) { return(String.Format("{0}/{1}/p:{2}/{3}/{4}/{5}", FullCachePrefix, TypeFullName, partition, GetPartitionGeneration(partition), "Find", Md5Helper.CalculateMd5(criteria + "::" + (queryOptions != null ? queryOptions.ToString() : "null") + "::" + (selector != null ? selector.ToString() : "null")))); } return(String.Format("{0}/{1}/{2}/{3}/{4}", FullCachePrefix, TypeFullName, GetGeneration(), "Find", Md5Helper.CalculateMd5(criteria + "::" + (queryOptions != null ? queryOptions.ToString() : "null") + "::" + (selector != null ? selector.ToString() : "null")))); }