protected T RunQueryScalarResult <T>(IStoredProcQuery query, string connectionString) { object result = null; using (var connection = new SqlConnection(connectionString)) { using (var command = connection.CreateCommand()) { try { QueryHandlerFactory.Create(query).Assign(command, query); connection.Open(); result = command.ExecuteScalar(); } catch (Exception ex) { ErrorHandler.PopulateExceptionWithCommandParameterData(ex, command); throw; } } } return((T)result); }
public DocumentSchema(StoreOptions options, IConnectionFactory factory, IMartenLogger logger) { _factory = factory; _logger = logger; StoreOptions = options; options.AllDocumentMappings.Each(x => _mappings[x.DocumentType] = x); _sequences = new Lazy <SequenceFactory>(() => { var sequences = new SequenceFactory(this, _factory, options, _logger); var patch = new SchemaPatch(); sequences.GenerateSchemaObjectsIfNecessary(StoreOptions.AutoCreateSchemaObjects, this, patch); apply(sequences, patch); return(sequences); }); Parser = new MartenExpressionParser(StoreOptions.Serializer(), StoreOptions); HandlerFactory = new QueryHandlerFactory(this, options.Serializer()); DbObjects = new DbObjects(_factory, this); addSystemFunction(options, "mt_immutable_timestamp"); }
// GET: SelectRequest/EmployeesFromDepartment/5 public IActionResult EmployeesFromDepartment(int id) { var query = new GetEmployeesFromDeptQuery(id); var handler = QueryHandlerFactory.Build(query); return(View(handler.Execute(_session))); }
// GET: SelectRequest/Employees public IActionResult Employees() { var query = new GetEmployeesQuery(); var handler = QueryHandlerFactory.Build(query); return(View(handler.Execute(_session))); }
// GET: SelectRequest public IActionResult Index() { var query = new GetDepartmentsQuery(); var handler = QueryHandlerFactory.Build(query); return(View(handler.Execute(_session))); }
protected Tuple <List <T1>, List <T2> > RunQueryDoubleResult <T1, T2>(IStoredProcQuery query, string connectionString) { var result1 = new List <T1>(); var result2 = new List <T2>(); using (var connection = new SqlConnection(connectionString)) { using (var command = connection.CreateCommand()) { try { QueryHandlerFactory.Create(query).Assign(command, query); connection.Open(); using (var dataReader = command.ExecuteReader()) { result1 = dataReader.FillCollection <T1>(false); dataReader.NextResult(); result2 = dataReader.FillCollection <T2>(); } } catch (Exception ex) { ErrorHandler.PopulateExceptionWithCommandParameterData(ex, command); throw; } } } return(new Tuple <List <T1>, List <T2> >(result1, result2)); }
protected List <T> RunQuerySingleResult <T>(IStoredProcQuery query, string connectionString) { var results = new List <T>(); using (var connection = new SqlConnection(connectionString)) { using (var command = connection.CreateCommand()) { try { QueryHandlerFactory.Create(query).Assign(command, query); connection.Open(); using (var dataReader = command.ExecuteReader()) { results = dataReader.FillCollection <T>(); } } catch (Exception ex) { ErrorHandler.PopulateExceptionWithCommandParameterData(ex, command); throw; } } } return(results); }
public object SearchByName(string name) { IQueryHandler <GetProductsQuery, IEnumerable <Product> > queryHandler = QueryHandlerFactory.Create <GetProductsQuery, IEnumerable <Product> >(); return(new { Items = queryHandler.Handle(new GetProductsQuery() { Name = name }) }); }
public void RunTest(IEnumerable <ICommand> commands) { Setup(); var repository = new FakeEventRepository(); repository.InitialEvents = Given(); var queryDataStore = new FakeQueryDataStore(); var queryService = new QueryHandlerFactory(queryDataStore); var commandRepository = new Mock <ICommandRepository>(); HandleEvents(repository.InitialEvents, queryDataStore); Exception caughtException = null; var commandHandlerFactory = new CommandHandlerFactory(repository, queryService, commandRepository.Object); var generatedEvents = new List <IEvent>(); foreach (var command in commands) { try { commandHandlerFactory.ExecuteCommand(command); } catch (Exception e) { if (ExpectedException() == null) { throw; } caughtException = e; } HandleEvents(repository.EventList, queryDataStore); generatedEvents.AddRange(repository.EventList); repository.InitialEvents = new List <IEvent>(repository.InitialEvents).Concat(repository.EventList).ToList(); repository.EventList.Clear(); } if (caughtException != null || ExpectedException() != null) { if (caughtException != null && ExpectedException() != null) { Assert.AreEqual(ExpectedException().GetType(), caughtException.GetType()); } else { Assert.Fail("There was an Expected Exception but none was thrown."); } } ValidateExpectedEvents(ExpectedEvents(), generatedEvents); }
// GET: SelectRequest/EmployeeDetails/5 public IActionResult EmployeeDetails(int id) { var query = new OneEmployeeQuery(id); var handler = QueryHandlerFactory.Build(query); var employee = handler.Execute(_session); if (employee == null) { return(NotFound()); } return(View(employee)); }
public object GetOption(Guid productId, Guid id) { IQueryHandler <GetProductOptionQuery, ProductOption> queryHandler = QueryHandlerFactory.Create <GetProductOptionQuery, ProductOption>(); ProductOption productOption = queryHandler.Handle(new GetProductOptionQuery { ProductId = productId, Id = id }); if (productOption == null) { return(NotFound()); } return(productOption); }
public object GetProduct(Guid id) { IQueryHandler <GetProductQuery, Product> queryHandler = QueryHandlerFactory.Create <GetProductQuery, Product>(); Product product = queryHandler.Handle(new GetProductQuery { Id = id }); if (product == null) { return(NotFound()); } return(product); }
/// <summary> /// Creates a new DocumentStore with the supplied StoreOptions /// </summary> /// <param name="options"></param> public DocumentStore(StoreOptions options) { options.ApplyConfiguration(); options.CreatePatching(); options.Validate(); Options = options; _logger = options.Logger(); Tenancy = options.Tenancy; if (options.CreateDatabases != null) { IDatabaseGenerator databaseGenerator = new DatabaseGenerator(); databaseGenerator.CreateDatabases(Tenancy, options.CreateDatabases); } Tenancy.Initialize(); Schema = Tenancy.Schema; Storage = options.Storage; Storage.PostProcessConfiguration(); Serializer = options.Serializer(); if (options.UseCharBufferPooling) { _writerPool = new CharArrayTextWriter.Pool(); } Advanced = new AdvancedOptions(this); Diagnostics = new Diagnostics(this); Transform = new DocumentTransforms(this, Tenancy.Default); options.InitialData.Each(x => x.Populate(this)); Parser = new MartenExpressionParser(Serializer, options); HandlerFactory = new QueryHandlerFactory(this); Events = options.Events; }
public DocumentSchema(StoreOptions options, IConnectionFactory factory, IMartenLogger logger) { _factory = factory; _logger = logger; StoreOptions = options; options.AllDocumentMappings.Each(x => _mappings[x.DocumentType] = x); Sequences = new SequenceFactory(this, _factory, options, _logger); Parser = new MartenExpressionParser(StoreOptions.Serializer(), StoreOptions); HandlerFactory = new QueryHandlerFactory(this, options.Serializer()); DbObjects = new DbObjects(_factory, this); }
private static void RegisterQueryProcessor(Container container) { var registry = new QueryHandlerRegistry(); registry.Register <GetWorksheetByIdQuery, Worksheet, GetWorksheetByIdQueryHandler>(); var decoratorRegistry = new QueryHandlerDecoratorRegistry(container); var queryHandlerFactory = new QueryHandlerFactory(container); var queryHandlerDecoratorFactory = new QueryHandlerDecoratorFactory(container); IQueryProcessor queryProcessor = QueryProcessorBuilder.With() .Handlers(registry, queryHandlerFactory, decoratorRegistry, queryHandlerDecoratorFactory) .InMemoryQueryContextFactory() .Build(); container.Register <IQueryProcessor>(() => { return(queryProcessor); }); }
public void RunTest(ICommand command) { Setup(); var repository = new FakeEventRepository(); repository.InitialEvents = Given(); var queryDataStore = new FakeQueryDataStore(); var queryService = new QueryHandlerFactory(queryDataStore); var commandRepository = new Mock <ICommandRepository>(); HandleEvents(repository.InitialEvents, queryDataStore); Exception caughtException = null; var commandHandlerFactory = new CommandHandlerFactory(repository, queryService, commandRepository.Object); try { commandHandlerFactory.ExecuteCommand(command); } catch (Exception e) { if (ExpectedException() == null) { throw; } caughtException = e; } if (caughtException != null || ExpectedException() != null) { if (caughtException != null && ExpectedException() != null) { Assert.AreEqual(ExpectedException().GetType(), caughtException.GetType()); } else { Assert.Fail("There was an Expected Exception but none was thrown."); } } ValidateExpectedEvents(ExpectedEvents(), repository.EventList); }
static void Main(string[] args) { Config config; try { config = Config.Create(args); } catch (ConnectionConfigException re) { var fg = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(re.Message); Console.ForegroundColor = fg; return; } if (config.Help) { PrintUsage(config); return; } try { using (var queryHandler = new QueryHandlerFactory(config).Create()) { if (!string.IsNullOrEmpty(config.Query)) { queryHandler.Execute(config.Query); } else { new Repl(queryHandler).Enter(); } } } catch (Exception e) { Console.WriteLine(e); Console.WriteLine(); config.PrintUsage(); } }
protected void RunQueryNonResult(IStoredProcQuery query, string connectionString) { using (var connection = new SqlConnection(connectionString)) { using (var command = connection.CreateCommand()) { try { QueryHandlerFactory.Create(query).Assign(command, query); connection.Open(); command.ExecuteNonQuery(); } catch (Exception ex) { ErrorHandler.PopulateExceptionWithCommandParameterData(ex, command); throw; } } } }
/// <summary> /// Creates a new DocumentStore with the supplied StoreOptions /// </summary> /// <param name="options"></param> public DocumentStore(StoreOptions options) { options.Validate(); options.CreatePatching(); Options = options; _logger = options.Logger(); Tenancy = options.Tenancy; Tenancy.Initialize(); Schema = Tenancy.Schema; Storage = options.Storage; Storage.CompileSubClasses(); Serializer = options.Serializer(); if (options.UseCharBufferPooling) { _writerPool = new CharArrayTextWriter.Pool(); } Advanced = new AdvancedOptions(this); Diagnostics = new Diagnostics(this); Transform = new DocumentTransforms(this, Tenancy.Default); options.InitialData.Each(x => x.Populate(this)); Parser = new MartenExpressionParser(Serializer, options); HandlerFactory = new QueryHandlerFactory(this); Events = options.Events; }
/// <summary> /// The Send. /// </summary> /// <typeparam name="TQuery">.</typeparam> /// <typeparam name="TQueryResult">.</typeparam> /// <param name="query">The query <see cref="TQuery"/>.</param> /// <returns>The <see cref="TQueryResult"/>.</returns> public SimpleResponse <TQueryResult> Send <TQuery, TQueryResult>(TQuery query) where TQueryResult : class, IQueryResult where TQuery : class, IQuery <TQueryResult> { var handler = QueryHandlerFactory.GetQueryHandler <TQuery, TQueryResult>(); var authorize = handler.Authorize(query); if (authorize.ResponseCode < 0) { return(new SimpleResponse <TQueryResult> { ResponseCode = authorize.ResponseCode, ResponseMessage = authorize.ResponseMessage, RCode = authorize.RCode }); } var queryResult = handler.Handle(query); return(queryResult); }
public static object Query(HandlerConfig handlerConfig, object complexData, IDictionary <string, object> queryParams = null) { IQueryHandler queryHandler = QueryHandlerFactory.GetQueryHandler(handlerConfig.QueryType); if (handlerConfig.Configs == null || handlerConfig.Configs.Any() == false) { throw new ArgumentNullException("handlerConfig.Configs"); } var context = new Context { HandlerConfig = handlerConfig, Configs = handlerConfig.Configs, Params = queryParams, ComplexData = complexData, }; ParamConvertUtil.DoConvert(context); var returnData = queryHandler.Query(context); //执行完查询后回调 return(handlerConfig.OnQueryEnd(returnData, queryParams)); }
/// <summary> /// Creates a new DocumentStore with the supplied StoreOptions /// </summary> /// <param name="options"></param> public DocumentStore(StoreOptions options) { options.ApplyConfiguration(); options.CreatePatching(); options.Validate(); Options = options; _logger = options.Logger(); Serializer = options.Serializer(); _retryPolicy = options.RetryPolicy(); if (options.CreateDatabases != null) { IDatabaseGenerator databaseGenerator = new DatabaseGenerator(); databaseGenerator.CreateDatabases(Tenancy, options.CreateDatabases); } Tenancy.Initialize(); Schema = Tenancy.Schema; Storage.PostProcessConfiguration(); _writerPool = options.UseCharBufferPooling ? MemoryPool <char> .Shared : new AllocatingMemoryPool <char>(); Advanced = new AdvancedOptions(this); Diagnostics = new Diagnostics(this); Transform = new DocumentTransforms(this, Tenancy.Default); Parser = new MartenExpressionParser(Serializer, options); HandlerFactory = new QueryHandlerFactory(this); options.InitialData.Each(x => x.Populate(this)); }
public object GetOptions(Guid productId) { IQueryHandler <GetProductOptionsQuery, IEnumerable <ProductOption> > queryHandler = QueryHandlerFactory.Create <GetProductOptionsQuery, IEnumerable <ProductOption> >(); return(new { Items = queryHandler.Handle(new GetProductOptionsQuery { ProductId = productId }) }); }
public object GetAll() { IQueryHandler <GetProductsQuery, IEnumerable <Product> > queryHandler = QueryHandlerFactory.Create <GetProductsQuery, IEnumerable <Product> >(); return(new { Items = queryHandler.Handle(new GetProductsQuery()) }); }