Пример #1
0
 public T ExecuteWrap <T>(Func <IDbConnectionSession, T> execute, RequestContext context, DataSourceChoice sourceChoice = DataSourceChoice.Write)
 {
     SetupRequestContext(context, sourceChoice);
     if (CacheManager.TryGet <T>(context, out T cachedResult))
     {
         return(cachedResult);
     }
     return(WrapWithTransaction <T>(context, (dbSession) =>
     {
         if (dbSession == null)
         {
             var dataSource = DataSourceFilter.Elect(context);
             dbSession = SessionStore.GetOrAddDbSession(dataSource);
         }
         try
         {
             var result = execute(dbSession);
             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();
             }
         }
     }));
 }
Пример #2
0
        public async Task <T> ExecuteWrapAsync <T>(Func <IDbConnectionSession, Task <T> > execute, RequestContext context)
        {
            SetupRequestContext(context);
            if (CacheManager.TryGet <T>(context, out T cachedResult))
            {
                return(cachedResult);
            }
            var dataSource = DataSourceFilter.Elect(context);
            var 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();
                }
            }
        }
Пример #3
0
 public void Dispose()
 {
     ConfigLoader?.Dispose();
     if (SessionStore != null)
     {
         SessionStore.LocalSession?.Dispose();
         SessionStore.Dispose();
     }
 }
Пример #4
0
 public void Dispose()
 {
     ConfigLoader.Dispose();
     if (SessionStore.LocalSession != null)
     {
         SessionStore.LocalSession.Dispose();
     }
     SessionStore.Dispose();
 }
Пример #5
0
        public void TestSessionStoreConstructor01()
        {
            SessionStore    sessionStore = new SessionStore();
            DatabaseSession session      = new DatabaseSession(TestDBInit.localConnectionString2);

            sessionStore.Store(TestDBInit.localConnectionString2, session);
            sessionStore.Dispose("");
            DBConnectionStrings.ReleaseInstance();
            SimpleDatabase.ReleaseInstance();
        }
Пример #6
0
 public void Dispose()
 {
     ConfigLoader.Dispose();
     SessionStore.Dispose();
     CacheManager.Dispose();
     if (_logger.IsEnabled(LogLevel.Warning))
     {
         _logger.LogWarning($"SmartSqlMapper Dispose.");
     }
 }
Пример #7
0
 public void Dispose()
 {
     ConfigLoader.Dispose();
     if (SessionStore.LocalSession != null)
     {
         SessionStore.LocalSession.Dispose();
     }
     SessionStore.Dispose();
     _logger.LogWarning($"SmartSqlMapper Dispose.");
 }
Пример #8
0
        public void EndSession()
        {
            var dbSession = SessionStore.LocalSession;

            if (dbSession == null)
            {
                throw new SmartSqlException("SmartSqlMapper could not invoke EndSession(). No LocalSession was existed. ");
            }
            dbSession.End();
            SessionStore.Dispose();
        }
Пример #9
0
        public void EndSession()
        {
            var session = SessionStore.LocalSession;

            if (session == null)
            {
                throw new SmartSqlException("SmartSqlMapper could not invoke EndSession(). No LocalSession was existed. ");
            }
            session.LifeCycle = DbSessionLifeCycle.Transient;
            session.CloseConnection();
            SessionStore.Dispose();
        }
Пример #10
0
        public void RollbackTransaction()
        {
            var session = SessionStore.LocalSession;

            if (session == null)
            {
                throw new SmartSqlException("SmartSqlMapper could not invoke RollBackTransaction(). No Transaction was started. Call BeginTransaction() first.");
            }
            try
            {
                _logger.Debug($"SmartSqlMapper.RollbackTransaction DbSession.Id:{session.Id}");
                session.RollbackTransaction();
            }
            finally
            {
                SessionStore.Dispose();
            }
        }
Пример #11
0
        public void CommitTransaction()
        {
            var session = SessionStore.LocalSession;

            if (session == null)
            {
                throw new BaraException("BaraMapper could not invoke CommitTransaction(). No Transaction was started. Call BeginTransaction() first.");
            }
            try
            {
                _logger.LogDebug($"CommitTransaction DbSession.Id:{session.Id}");
                session.CommitTransaction();
                CacheManager.FlushQueue();
            }
            finally
            {
                SessionStore.Dispose();
            }
        }
Пример #12
0
        public void CommitTransaction()
        {
            var session = SessionStore.LocalSession;

            if (session == null)
            {
                throw new SmartSqlException("SmartSqlMapper could not invoke CommitTransaction(). No Transaction was started. Call BeginTransaction() first.");
            }
            try
            {
                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug($"CommitTransaction DbSession.Id:{session.Id}");
                }
                session.CommitTransaction();
                CacheManager.RequestCommitted(session);
            }
            finally
            {
                SessionStore.Dispose();
            }
        }
Пример #13
0
        public void RollbackTransaction()
        {
            var session = SessionStore.LocalSession;

            if (session == null)
            {
                throw new BaraException("BaraMapper can't invoke RollBackTransaction(),No Transaction Started.Invoke BegainTransaction first.");
            }
            try
            {
                _logger.LogDebug($"RollbackTransaction DbSession.Id:{session.Id}");
                session.RollbackTransaction();
                CacheManager.ClearQueue();
            }
            catch (Exception ex)
            {
                throw new BaraException($"BaraMapper invoke RollBackTransaction() throw error:{ex.Message}");
            }
            finally
            {
                SessionStore.Dispose();
            }
        }
Пример #14
0
 public void Dispose()
 {
     SessionStore.Dispose();
 }