public IEnumerable <T> Query <T>(RequestContext context, DataSourceChoice sourceChoice) { var cache = CacheManager[context, typeof(IEnumerable <T>)]; if (cache != null) { return((IEnumerable <T>)cache); } IDbConnectionSession session = SessionStore.LocalSession; if (session == null) { session = CreateDbSession(sourceChoice); } string sqlStr = SqlBuilder.BuildSql(context); try { var result = session.Connection.Query <T>(sqlStr, context.DapperParameters, session.Transaction); CacheManager[context, typeof(IEnumerable <T>)] = result; return(result); } catch (Exception ex) { throw ex; } finally { if (session.LifeCycle == DbSessionLifeCycle.Transient) { session.CloseConnection(); } } }
private void InitDataSource(RequestContext context, DataSourceChoice sourceChoice) { if (context.DataSourceChoice == DataSourceChoice.Unknow) { context.DataSourceChoice = sourceChoice; } }
public async Task <T> RunAsync <T>(RequestContext context, DataSourceChoice sourceChoice, Func <String, IDbConnectionSession, Task <T> > runSql) { IDbConnectionSession session = SmartSqlMapper.SessionStore.LocalSession; if (session == null) { session = SmartSqlMapper.CreateDbSession(sourceChoice); } string sqlStr = SqlBuilder.BuildSql(context); try { T result = await runSql(sqlStr, session); return(result); } catch (Exception ex) { throw ex; } finally { if (session.LifeCycle == DbSessionLifeCycle.Transient) { session.CloseConnection(); } } }
public DataSourceChoice DataSourceChoiceFromDisplayMenu() { ConsoleKey choiceKey; DataSourceChoice endChoice = DataSourceChoice.Unassigned; do { Console.WriteLine("Choose desired option from the following :"); Console.WriteLine("1. Exit"); Console.WriteLine("2. Enter raw prices data line at the command prompt"); Console.WriteLine("3. Enter full path to file containing prices data"); Console.Write("Choice: "); choiceKey = Console.ReadKey().Key; switch (choiceKey) { case ConsoleKey.Escape: case ConsoleKey.NumPad1: choiceKey = ConsoleKey.D1; break; case ConsoleKey.NumPad2: choiceKey = ConsoleKey.D2; break; case ConsoleKey.NumPad3: choiceKey = ConsoleKey.D3; break; } Console.WriteLine("\n"); }while ( choiceKey != ConsoleKey.D1 && choiceKey != ConsoleKey.D2 && choiceKey != ConsoleKey.D3 ); switch (choiceKey) { case ConsoleKey.D1: endChoice = DataSourceChoice.Exit; break; case ConsoleKey.D2: endChoice = DataSourceChoice.Text; break; case ConsoleKey.D3: endChoice = DataSourceChoice.File; break; } return(endChoice); }
public virtual bool IsExist(object paramObj, string sqlId = DefaultSqlId.IsExist, DataSourceChoice sourceChoice = DataSourceChoice.Read) { return(SqlMapper.QuerySingle <int>(new RequestContext { DataSourceChoice = sourceChoice, Scope = Scope, SqlId = sqlId, Request = paramObj }) > 0); }
public virtual TEntity GetEntity(object paramObj, string sqlId = DefaultSqlId.GetEntity, DataSourceChoice sourceChoice = DataSourceChoice.Read) { return(SqlMapper.QuerySingle <TEntity>(new RequestContext { DataSourceChoice = sourceChoice, Scope = Scope, SqlId = sqlId, Request = paramObj })); }
public MainWindowViewModel(List <IDataClient> dataClients) { this.selectedPerson = null; this.People.CollectionChanged += People_CollectionChanged; this.People.CollectionChanged += SomePeople_CollectionChanged; this.PeopleToAddWhenSaving.CollectionChanged += SomePeople_CollectionChanged; this.PeopleToRemoveWhenSaving.CollectionChanged += SomePeople_CollectionChanged; this.dataSourceChoices = new List <DataSourceChoice>(dataClients.Select(p => { var dataSourceChoice = new DataSourceChoice(p); dataSourceChoice.PropertyChanged += DataSourceChoice_PropertyChanged; return(dataSourceChoice); })); }
public async Task <T> QuerySingleAsync <T>(RequestContext context, DataSourceChoice sourceChoice) { var cache = CacheManager[context, typeof(IEnumerable <T>)]; if (cache != null) { return((T)cache); } var result = await _sqlRuner.RunAsync <T>(context, sourceChoice, (sqlStr, _session) => { return(_session.Connection.QuerySingleOrDefaultAsync <T>(sqlStr, context.DapperParameters, _session.Transaction)); }); CacheManager[context, typeof(T)] = result; return(result); }
public T QuerySingle <T>(RequestContext context, DataSourceChoice sourceChoice) { var cache = CacheManager[context, typeof(T)]; if (cache != null) { return((T)cache); } var result = _sqlRuner.Run <T>(context, sourceChoice, (sqlStr, session) => { return(session.Connection.QuerySingleOrDefault <T>(sqlStr, context.DapperParameters, session.Transaction)); }); CacheManager[context, typeof(T)] = result; return(result); }
private IDataSource GetDataSource(DataSourceChoice sourceChoice) { IDataSource choiceDataSource = _smartSqlContext.Database.WriteDataSource; var readDataSources = _smartSqlContext.Database.ReadDataSources; if (sourceChoice == DataSourceChoice.Read && readDataSources.Count > 0 ) { var seekList = readDataSources.Select(readDataSource => new WeightFilter <IReadDataSource> .WeightSource { Source = readDataSource, Weight = readDataSource.Weight }); choiceDataSource = _weightFilter.Elect(seekList).Source; } if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug($"DataSourceManager GetDataSource Choice: {choiceDataSource.Name} ."); } return(choiceDataSource); }
public T QuerySingle <T>(RequestContext context, DataSourceChoice sourceChoice) { return(SqlMapper.QuerySingle <T>(context, sourceChoice)); }
public IEnumerable <T> Query <T>(RequestContext context, DataSourceChoice sourceChoice) { return(SqlMapper.Query <T>(context, sourceChoice)); }
private void SetupRequestContext(RequestContext context, DataSourceChoice sourceChoice) { context.Setup(SmartSqlOptions.SmartSqlContext); InitDataSource(context, sourceChoice); SqlBuilder.BuildSql(context); }
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); } var dataSource = DataSourceFilter.Elect(context); var 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 static Task <T> QuerySingleAsync <T>(this ISmartSqlMapper sqlMapper, string fullSqlId, dynamic @params, DataSourceChoice sourceChoice) { EnsurePoint(ref fullSqlId); return(sqlMapper.QuerySingleAsync <T>(new RequestContext() { Scope = fullSqlId.Split('.')[0], SqlId = fullSqlId.Split('.')[1], Request = @params }, sourceChoice)); }