/// <summary> /// Called before a remove database command execute /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="removeByQueryContext">Remove by query context</param> /// <returns>Return policy result</returns> public virtual StartingResult OnRemoveByQueryStarting <T>(RemoveByQueryContext <T> removeByQueryContext) where T : BaseEntity <T>, new() { if (removeByQueryContext == null) { return(StartingResult.Success($"Parameter:{nameof(removeByQueryContext)} is null")); } try { RemoveCacheData(removeByQueryContext.Datas); } catch (Exception ex) { return(DataCacheBehavior.GetStartingResult(DataCacheOperation.RemoveData, ex)); } return(StartingResult.Success()); }
/// <summary> /// Called before a update database command execute /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="updateAllContext">Update all context</param> /// <returns>Return policy result</returns> public virtual StartingResult OnUpdateAllStarting <T>(UpdateAllContext <T> updateAllContext) where T : BaseEntity <T>, new() { if (updateAllContext == null) { return(StartingResult.Success($"Parameter:{nameof(updateAllContext)} is null")); } var entityType = typeof(T); try { RemoveCacheDataByType(entityType); } catch (Exception ex) { return(DataCacheBehavior.GetStartingResult(DataCacheOperation.RemoveData, ex)); } return(StartingResult.Success()); }
/// <summary> /// Called before a query command execute /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="queryDataContext">Query data context</param> /// <returns>Return query result</returns> public virtual QueryDataResult <T> OnQueryStarting <T>(QueryDataContext <T> queryDataContext) where T : BaseEntity <T>, new() { if (queryDataContext == null) { return(QueryDataResult <T> .Default($"Parameter:{nameof(queryDataContext)} is null")); } IQuery query = queryDataContext.Query; int size = query?.QuerySize ?? 0; try { return(GetCacheDatas <T>(query, size)); } catch (Exception ex) { return(DataCacheBehavior.GetQueryResult <T>(ex)); } }
/// <summary> /// Called before a database command execute /// </summary> /// <param name="addDataContext">Add data context</param> /// <returns>Return the policy result</returns> public virtual StartingResult OnAddStarting <T>(AddDataContext <T> addDataContext) where T : BaseEntity <T>, new() { if (addDataContext == null) { return(StartingResult.Success($"Parameter:{nameof(addDataContext)} is null")); } try { AddCacheData(new QueryDataCallbackContext <T>() { Datas = addDataContext.Datas, Query = addDataContext.DatabaseCommand?.Query }); } catch (Exception ex) { return(DataCacheBehavior.GetStartingResult(DataCacheOperation.AddData, ex)); } return(StartingResult.Success()); }
/// <summary> /// Called before a update database command execute /// </summary> /// <typeparam name="T">Data type</typeparam> /// <param name="updateByQueryContext">Update by query context</param> /// <returns>Return policy result</returns> public virtual StartingResult OnUpdateByQueryStarting <T>(UpdateByQueryContext <T> updateByQueryContext) where T : BaseEntity <T>, new() { if (updateByQueryContext == null) { return(StartingResult.Success($"Parameter:{nameof(updateByQueryContext)} is null")); } if (updateByQueryContext.GetDatasProxy == null) { return(StartingResult.Success($"Parameter:{nameof(UpdateByQueryContext<T>.GetDatasProxy)} is null")); } var datas = updateByQueryContext.GetDatasProxy(updateByQueryContext.Query); try { RemoveCacheData(datas); } catch (Exception ex) { return(DataCacheBehavior.GetStartingResult(DataCacheOperation.RemoveData, ex)); } return(StartingResult.Success()); }