Ejemplo n.º 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();
             }
         }
     }));
 }
Ejemplo n.º 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();
                }
            }
        }
Ejemplo n.º 3
0
 public void Dispose()
 {
     ConfigLoader?.Dispose();
     if (SessionStore != null)
     {
         SessionStore.LocalSession?.Dispose();
         SessionStore.Dispose();
     }
 }
Ejemplo n.º 4
0
 public void Dispose()
 {
     ConfigLoader.Dispose();
     if (SessionStore.LocalSession != null)
     {
         SessionStore.LocalSession.Dispose();
     }
     SessionStore.Dispose();
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 6
0
 public void Dispose()
 {
     ConfigLoader.Dispose();
     SessionStore.Dispose();
     CacheManager.Dispose();
     if (_logger.IsEnabled(LogLevel.Warning))
     {
         _logger.LogWarning($"SmartSqlMapper Dispose.");
     }
 }
Ejemplo n.º 7
0
 public void Dispose()
 {
     ConfigLoader.Dispose();
     if (SessionStore.LocalSession != null)
     {
         SessionStore.LocalSession.Dispose();
     }
     SessionStore.Dispose();
     _logger.LogWarning($"SmartSqlMapper Dispose.");
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 14
0
 public void Dispose()
 {
     SessionStore.Dispose();
 }