Exemple #1
0
 private void SetupRequestContext(RequestContext context, DataSourceChoice sourceChoice)
 {
     context.Setup(SmartSqlOptions);
     InitDataSource(context, sourceChoice);
 }
Exemple #2
0
        public async Task <T> ExecuteWrapAsync <T>(Func <IDbConnectionSession, Task <T> > execute, RequestContext context, DataSourceChoice sourceChoice = DataSourceChoice.Write)
        {
            SetupRequestContext(context, sourceChoice);
            if (CacheManager.TryGet <T>(context, out T cachedResult))
            {
                return(cachedResult);
            }

            return(await WrapWithTransactionAsync <T>(context, async (dbSession) =>
            {
                if (dbSession == null)
                {
                    var dataSource = DataSourceFilter.Elect(context);
                    dbSession = SessionStore.GetOrAddDbSession(dataSource);
                }
                try
                {
                    var result = await execute(dbSession).ConfigureAwait(false);
                    CacheManager.RequestExecuted(dbSession, context);
                    CacheManager.TryAdd <T>(context, result);
                    return result;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.HelpLink, ex, ex.Message);
                    throw ex;
                }
                finally
                {
                    if (dbSession.LifeCycle == DbSessionLifeCycle.Transient)
                    {
                        SessionStore.Dispose();
                    }
                }
            }));
        }
Exemple #3
0
 public IDbConnectionSession BeginTransaction(RequestContext context)
 {
     InitDataSource(context, DataSourceChoice.Write);
     return(BeginTransaction(context, IsolationLevel.Unspecified));
 }
Exemple #4
0
 public int Execute(RequestContext context)
 {
     return(ExecuteWrap((dbSession) => CommandExecuter.ExecuteNonQuery(dbSession, context), context));
 }