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(); } } })); }
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(); } } }
public void Dispose() { ConfigLoader?.Dispose(); if (SessionStore != null) { SessionStore.LocalSession?.Dispose(); SessionStore.Dispose(); } }
public void Dispose() { ConfigLoader.Dispose(); if (SessionStore.LocalSession != null) { SessionStore.LocalSession.Dispose(); } SessionStore.Dispose(); }
public void TestSessionStoreConstructor01() { SessionStore sessionStore = new SessionStore(); DatabaseSession session = new DatabaseSession(TestDBInit.localConnectionString2); sessionStore.Store(TestDBInit.localConnectionString2, session); sessionStore.Dispose(""); DBConnectionStrings.ReleaseInstance(); SimpleDatabase.ReleaseInstance(); }
public void Dispose() { ConfigLoader.Dispose(); SessionStore.Dispose(); CacheManager.Dispose(); if (_logger.IsEnabled(LogLevel.Warning)) { _logger.LogWarning($"SmartSqlMapper Dispose."); } }
public void Dispose() { ConfigLoader.Dispose(); if (SessionStore.LocalSession != null) { SessionStore.LocalSession.Dispose(); } SessionStore.Dispose(); _logger.LogWarning($"SmartSqlMapper Dispose."); }
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(); }
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(); }
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(); } }
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(); } }
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(); } }
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(); } }
public void Dispose() { SessionStore.Dispose(); }