public static IQuery GetGetRevisionQuery(IRevisionKey revisionKey) { ArgumentUtility.CheckNotNull("revisionKey", revisionKey); var storageProviderDefinition = GetStorageProviderDefinition(); var sqlDialect = storageProviderDefinition.Factory.CreateSqlDialect(storageProviderDefinition); var parameters = new QueryParameterCollection(); var statement = new StringBuilder(); statement.Append("SELECT "); statement.Append(GetRevisionValueColumnIdentifier(sqlDialect)); statement.Append(" FROM "); statement.Append(GetRevisionTableIdentifier(sqlDialect)); statement.Append(" WHERE ("); AppendKeyClause(statement, parameters, revisionKey, sqlDialect); statement.Append(")"); statement.Append(sqlDialect.StatementDelimiter); return(QueryFactory.CreateQuery( new QueryDefinition( typeof(Revision) + "." + MethodBase.GetCurrentMethod().Name, storageProviderDefinition, statement.ToString(), QueryType.Scalar), parameters)); }
public IEnumerable <Manufacturer> All() { var query = QueryFactory.CreateQuery <GetAllQuery>(); var model = query.GetResult(); return(model); }
public IQueryable <InventoryItem> GetFilteredCarInventory(string searchParam, string sortColumn, int?sortOrder, int?pageParam) { BoxXDataReader dataReader = BoxXDataReader.Instance; IInventoryCollection dataCollection = ModelFactory.CreateInventoryCollection(dataReader.SchemaPropertyNames); IInventoryQuery query = QueryFactory.CreateQuery(); SortOrder? parsedSortOrder = ParseSortOrder(sortOrder); if (parsedSortOrder.HasValue) { var propertyName = BoxXDataReader.GetPropertyNameFromColumnName(sortColumn); if (propertyName.HasValue) { query.SortWith(propertyName.Value, parsedSortOrder.Value); } } if (pageParam.HasValue) { query.PagingWith(pageParam.Value, DataNumPerPage); } foreach (var propertyName in dataReader.SchemaPropertyNames) { query.FilterWith(propertyName.ValueLikes(searchParam)); } dataReader.GetData(dataCollection, query); return(dataCollection.Items.Cast <InventoryItem>().AsQueryable()); }
public IBusinessObject[] Search(IBusinessObject referencingObject, IBusinessObjectReferenceProperty property, ISearchAvailableObjectsArguments searchArguments) { var defaultSearchArguments = searchArguments as DefaultSearchArguments; if (defaultSearchArguments == null || string.IsNullOrEmpty(defaultSearchArguments.SearchStatement)) { return(new IBusinessObject[0]); } QueryDefinition definition = DomainObjectsConfiguration.Current.Query.QueryDefinitions.GetMandatory(defaultSearchArguments.SearchStatement); if (definition.QueryType != QueryType.Collection) { throw new ArgumentException(string.Format("The query '{0}' is not a collection query.", defaultSearchArguments.SearchStatement)); } var referencingDomainObject = referencingObject as DomainObject; var clientTransaction = referencingDomainObject != null ? referencingDomainObject.DefaultTransactionContext.ClientTransaction : ClientTransaction.Current; if (clientTransaction == null) { throw new InvalidOperationException("No ClientTransaction has been associated with the current thread or the referencing object."); } var result = clientTransaction.QueryManager.GetCollection(QueryFactory.CreateQuery(definition)); var availableObjects = new IBusinessObjectWithIdentity[result.Count]; if (availableObjects.Length > 0) { result.ToArray().CopyTo(availableObjects, 0); } return(availableObjects); }
public ActionResult Details(string id) { var model = _queryFactory.CreateQuery <GetAssetDetailsQuery>() .For(id) .Load(); return(View("display", model)); }
//----------------------------------------------------------------// public async Task ReinitNotificationList(ISession session) { IEnumerable <Case> cases = await QueryFactory.CreateQuery <ICaseQuery>(session).GetDailyActiveCasesAsync(); IEnumerable <NotificationModel> notifications = cases.Select(c => new NotificationModel(c.ChatId, c.NextUserId.Value, c.Id, c.NextUser?.UserName, c.CaseName, c.TimeOfDay)); _notifications = new ConcurrentBag <NotificationModel>(notifications); _notifyMessageUpdatedAt = DateTime.Now; }
public ActionResult Find(string searchCriteria) { var query = _queryFactory.CreateQuery <FindAssetQuery>(); var result = query.For(searchCriteria) .Load(); return(View("Results", result)); }
public Manufacturer GetBy(int id) { var query = QueryFactory.CreateQuery <GetByIdQuery>(); query.Id = id; var model = query.GetResult(); return(model); }
public void DifferentStorageProviderID() { QueryDefinition definition = new QueryDefinition( "QueryWithDifferentStorageProviderID", UnitTestStorageProviderDefinition, "select 42", QueryType.Scalar); Provider.ExecuteScalarQuery(QueryFactory.CreateQuery(definition)); }
public IQueryable <InventoryItem> GetAllCarInventory() { BoxXDataReader dataReader = BoxXDataReader.Instance; IInventoryCollection dataCollection = ModelFactory.CreateInventoryCollection(dataReader.SchemaPropertyNames); IInventoryQuery query = QueryFactory.CreateQuery(); dataReader.GetData(dataCollection, query); return(dataCollection.Items.Cast <InventoryItem>().AsQueryable()); }
public bool GenerateAndExecuteQueryDBOnly() { var query = _queryGenerator(); var restoreQuery = QueryFactory.CreateQuery <T> ("perftest", query); using (var manager = new StorageProviderManager(NullPersistenceExtension.Instance)) { return(manager.GetMandatory("PerformanceTestDomain").ExecuteCollectionQuery(restoreQuery).ToArray().Length > 100); } }
public void Fulltext_Spike() { ClassDefinition orderClassDefinition = MappingConfiguration.Current.GetTypeDefinition(typeof(Order)); var queryDefinition = new QueryDefinition("bla", orderClassDefinition.StorageEntityDefinition.StorageProviderDefinition, "SELECT * FROM CeoView WHERE Contains ([CeoView].[Name], 'Fischer')", QueryType.Collection); var query = QueryFactory.CreateQuery(queryDefinition); var orders = TestableClientTransaction.QueryManager.GetCollection <Ceo> (query).AsEnumerable(); CheckQueryResult(orders, DomainObjectIDs.Ceo4); }
public void CreateQuery_FromLinqQuery_WithEagerFetching() { var queryable = (from o in QueryFactory.CreateLinqQuery <Order>() where o.OrderNumber > 1 select o).FetchMany(o => o.OrderItems); IQuery query = QueryFactory.CreateQuery <Order> ("<dynamico queryo>", queryable); Assert.That(query.EagerFetchQueries.Count, Is.EqualTo(1)); Assert.That(query.EagerFetchQueries.Single().Key.PropertyName, Is.EqualTo(typeof(Order).FullName + ".OrderItems")); }
//----------------------------------------------------------------// public async Task <String> CreateDailyCaseAsync(TimeSpan time, String name, Int64 chatId) { Case @case = new Case(name, time, chatId); using (ISession session = SessionFactory.CreateSession()) { ICaseQuery caseQuery = QueryFactory.CreateQuery <ICaseQuery>(session); ICommand <Case, Int32> caseCommand = CommandFactory.CreateCommand <ICommand <Case, Int32> >(session); return(_caseExist(await caseCommand.SaveIfNotExist(caseQuery, @case))); } }
public FileResult Get(string channel, string id) { var query = _queryFactory.CreateQuery <GetAssetFileQuery>(); var result = query.For(channel, id) .Load(); if (result != null) { return(new FileStreamResult(result.FileStream, result.ContentType)); } //TODO: Should be part of the demo. _messageClient.SendMessage(new ChannelAssetError { AssetName = id, ChannelName = channel, Reason = "Not found" }); throw new HttpException(404, $"Could not find {id}"); }
public void CreateQuery_FromDefinition() { var definition = new QueryDefinition("Test", TestDomainStorageProviderDefinition, "y", QueryType.Collection, typeof(OrderCollection)); IQuery query = QueryFactory.CreateQuery(definition); Assert.That(query.CollectionType, Is.EqualTo(definition.CollectionType)); Assert.That(query.ID, Is.EqualTo(definition.ID)); Assert.That(query.Parameters, Is.Empty); Assert.That(query.QueryType, Is.EqualTo(definition.QueryType)); Assert.That(query.Statement, Is.EqualTo(definition.Statement)); Assert.That(query.StorageProviderDefinition, Is.SameAs(definition.StorageProviderDefinition)); }
public SearchResultPage <TContract> CreateDirectSearch(Search search, IEntitySearchCommand <TEntity> searchCommand) { if (search.AsOf == null) { search.AsOf = SystemTime.UtcNow(); } var queryFactory = new QueryFactory(); var query = queryFactory.CreateQuery(search); var results = searchCommand.Execute(this.repository, query == string.Empty ? "true" : query, search.AsOf, search.SearchOptions.ResultsPerPage, search.SearchOptions.OrderBy, search); var searchResultPage = new SearchResultPage <TContract>(results.Select(entity => this.ConstructContract(entity, search.AsOf.Value)).ToList(), search.AsOf.Value); return(searchResultPage); }
public override void SetUp() { base.SetUp(); _query1 = QueryFactory.CreateQuery(TestQueryFactory.CreateOrderSumQueryDefinition()); _query2 = QueryFactory.CreateQuery(TestQueryFactory.CreateOrderQueryWithCustomCollectionType()); _endPointDefinition1 = DomainObjectIDs.Order1.ClassDefinition.GetMandatoryRelationEndPointDefinition(typeof(Order).FullName + ".OrderItems"); _endPointDefinition2 = DomainObjectIDs.Customer1.ClassDefinition.GetMandatoryRelationEndPointDefinition(typeof(Customer).FullName + ".Orders"); _objectEndPointDefinition = DomainObjectIDs.Order1.ClassDefinition.GetMandatoryRelationEndPointDefinition(typeof(Order).FullName + ".OrderTicket"); _collection = new EagerFetchQueryCollection(); }
public void CreateQuery_FromLinqQuery() { var queryable = from o in QueryFactory.CreateLinqQuery <Order>() where o.OrderNumber > 1 select o; IQuery query = QueryFactory.CreateQuery <Order> ("<dynamico queryo>", queryable); Assert.That(query.Statement, Is.EqualTo( "SELECT [t0].[ID],[t0].[ClassID],[t0].[Timestamp],[t0].[OrderNo],[t0].[DeliveryDate],[t0].[OfficialID],[t0].[CustomerID],[t0].[CustomerIDClassID] " + "FROM [OrderView] AS [t0] WHERE ([t0].[OrderNo] > @1)")); Assert.That(query.Parameters.Count, Is.EqualTo(1)); Assert.That(query.ID, Is.EqualTo("<dynamico queryo>")); Assert.That(query.QueryType, Is.EqualTo(QueryType.Collection)); Assert.That(query.StorageProviderDefinition, Is.EqualTo(TestDomainStorageProviderDefinition)); }
private static void TestSimpleQueryAsString() { using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { using (StopwatchScope.CreateScope("Simple query from string took {elapsed:ms} ms")) { var query = QueryFactory.CreateQuery( new QueryDefinition( "id", DomainObjectsConfiguration.Current.Storage.StorageProviderDefinitions["SecurityManager"], "select * from PositionView", QueryType.Collection)); ClientTransaction.Current.QueryManager.GetCollection <Position> (query); } } }
//----------------------------------------------------------------// public override async Task <Message> ExecuteAsync(Message message) { User sender = message.From; Boolean isAdded = false; ControlUser user = new ControlUser(sender.Id, sender.FirstName, sender.LastName, sender.Username); using (ISession session = SessionFactory.CreateSession()) { ICommand <ControlUser, Int32> userCommand = CommandFactory.CreateCommand <ICommand <ControlUser, Int32> >(session); IUserQuery userQuery = QueryFactory.CreateQuery <IUserQuery>(session); isAdded = await QueryHelper.SaveIfNotExist(userCommand, userQuery, user); } String resultMessage = isAdded ? ControlUserMessage.UserAdded(sender.Id) : ControlUserMessage.UserExist(sender.Id); return(await BotClient.SendTextMessageAsync(message.Chat.Id, resultMessage, replyToMessageId : message.MessageId)); }
public void Sample() { string error; factory = new QueryFactory(); query = factory.CreateQuery(QueryClass.PositionUtilisationRiskEntityQuery); filter = query.CreateFilter(); filter.AddFilterCriteria("EntityLevel", "Client", out error); query.MaxCount = 25; query.QueryResponse += query_QueryResponse; query.Start(filter); }
public void FilterQueryResult() { var queryStub = QueryFactory.CreateQuery(TestQueryFactory.CreateOrderQueryWithCustomCollectionType()); var originalResult = new QueryResult <Order> (queryStub, new Order[0]); var newResult1 = new QueryResult <Order> (queryStub, new[] { DomainObjectIDs.Order1.GetObject <Order> () }); var newResult2 = new QueryResult <Order> (queryStub, new[] { DomainObjectIDs.Order2.GetObject <Order> () }); _extension1.Expect(mock => mock.FilterQueryResult(TestableClientTransaction, originalResult)).Return(newResult1); _extension2.Expect(mock => mock.FilterQueryResult(TestableClientTransaction, newResult1)).Return(newResult2); var finalResult = _collectionWithExtensions.FilterQueryResult(TestableClientTransaction, originalResult); Assert.That(finalResult, Is.SameAs(newResult2)); _extension1.VerifyAllExpectations(); _extension2.VerifyAllExpectations(); }
//----------------------------------------------------------------// public async Task <String> CreateConcretyDateCaseAsync(DateTime dateTime, TimeSpan timeSpan, String name, Int64 chatId) { ConcretyDateCase concretyDate = new ConcretyDateCase(name, timeSpan, chatId); Boolean isAdded = false; using (ISession session = SessionFactory.CreateSession()) { ICaseQuery caseQuery = QueryFactory.CreateQuery <ICaseQuery>(session); IQuery <CaseDate, CaseDateId> caseDateQuery = QueryFactory.CreateQuery <IQuery <CaseDate, CaseDateId> >(session); ICommand <Case, Int32> caseCommand = CommandFactory.CreateCommand <ICommand <Case, Int32> >(session); ICommand <CaseDate, CaseDateId> caseDateCommand = CommandFactory.CreateCommand <ICommand <CaseDate, CaseDateId> >(session); isAdded = await caseCommand.SaveIfNotExist(caseQuery, concretyDate) && await caseDateCommand.SaveIfNotExist(caseDateQuery, new CaseDate(concretyDate, dateTime)); } return(_caseExist(isAdded)); }
//----------------------------------------------------------------// public async Task <String> CreateWeeklyCaseAsync(List <DayOfWeek> dayOfWeeks, TimeSpan time, String name, Int64 chatId) { WeeklyCase weeklyCase = new WeeklyCase(name, time, chatId, dayOfWeeks); Boolean isAdded = false; using (ISession session = SessionFactory.CreateSession()) { ICaseQuery caseQuery = QueryFactory.CreateQuery <ICaseQuery>(session); ICommand <Case, Int32> caseCommand = CommandFactory.CreateCommand <ICommand <Case, Int32> >(session); IQuery <CaseDayOfWeek, CaseDayOfWeekId> caseDayOfWeekQuery = QueryFactory.CreateQuery <IQuery <CaseDayOfWeek, CaseDayOfWeekId> >(session); ICommand <CaseDayOfWeek, CaseDayOfWeekId> caseDayOfWeekCommand = CommandFactory.CreateCommand <ICommand <CaseDayOfWeek, CaseDayOfWeekId> >(session); isAdded = await caseCommand.SaveIfNotExist(caseQuery, weeklyCase); IEnumerable <CaseDayOfWeek> caseDayOfWeeks = dayOfWeeks.Select(c => new CaseDayOfWeek(weeklyCase, c)); await caseDayOfWeekCommand.SaveIfNotExistCollection(caseDayOfWeekQuery, caseDayOfWeeks); } return(_caseExist(isAdded)); }
//----------------------------------------------------------------// public async Task <ProcessResult> TryGenerateOrUpdateSequence(ISession session, String nameCase, String[] userNames) { String result = null; IEnumerable <UserCaseSequencer> sequencers = null; ICaseQuery caseQuery = QueryFactory.CreateQuery <ICaseQuery>(session); Case @case = await caseQuery.GetCaseByNameAsync(nameCase); if (@case != null) { IUserQuery userQuery = QueryFactory.CreateQuery <IUserQuery>(session); IEnumerable <ControlUser> users = await userQuery.GetItemsAsync(userNames); if (users.Count() == userNames.Length) { ICommand <UserCaseSequencer, UserCaseSequencerId> sequencerCommand = CommandFactory.CreateCommand <ICommand <UserCaseSequencer, UserCaseSequencerId> >(session); ICommand <Case, Int32> caseCommand = CommandFactory.CreateCommand <ICommand <Case, Int32> >(session); IQuery <UserCaseSequencer, UserCaseSequencerId> sequencerQuery = QueryFactory.CreateQuery <IQuery <UserCaseSequencer, UserCaseSequencerId> >(session); sequencers = users.Select((u, i) => new UserCaseSequencer(@case, u, i)); sequencers = await sequencerCommand.SaveOrUpdateCollectionAsync(sequencerQuery, sequencers); @case.NextUserId = sequencers.OrderBy(i => i.Sequence).First().Id.UserId; await caseCommand.UpdateAsync(@case); } else { result = UserMessages.UsersNotExist(GetNotExistUsers(users, userNames)); } } else { result = CaseMessages.CaseNotExist(nameCase); } return(String.IsNullOrEmpty(result) ? new ProcessResult(SequeceMessages.CaseSequenceGenerated(nameCase, sequencers), true) : new ProcessResult(result, false)); }
private IEnumerable <string> LoadUserNames(IDbConnection connection, IDbTransaction transaction, ICollection <IDomainObjectHandle <User> > users) { if (!users.Any()) { yield break; } //TODO RM-5702: Support for more than 2000 parameters var userIDs = users.Select(u => (Guid)u.ObjectID.Value).ToList(); var query = QueryFactory.CreateQuery <string> ( "load usernames", QueryFactory.CreateLinqQuery <User>() .Where(u => userIDs.Contains((Guid)u.ID.Value)) .Select(u => u.UserName)); using (var command = CreateCommandFromQuery(connection, transaction, query)) using (var dataReader = command.ExecuteReader()) { while (dataReader.Read()) { yield return(dataReader.GetString(0)); } } }
public bool GenerateQueryModelAndSQLAndIQuery() { var query = _queryGenerator(); return(QueryFactory.CreateQuery <T> ("perftest", query) != null); }
public void CreateQuery_FromLinqQuery_InvalidQueryable() { var queryable = new int[0].AsQueryable(); QueryFactory.CreateQuery <int> ("<dynamic query>", queryable); }
public void CreateQueryTest_PersistentTripleStore() { TripleStore ts = CreatePersistentTripleStore(); IRdfContext context = new RdfDataContext(ts); QueryFactory<Track> factory = new QueryFactory<Track>(ts.QueryType, context); Assert.AreEqual(factory.QueryType, ts.QueryType); IRdfQuery<Track> query = factory.CreateQuery<Track>(); Assert.IsNotNull(query); Assert.IsTrue(query is RdfN3Query<Track>); }
public void InvalidScalarQuery() { QueryDefinition definition = new QueryDefinition("InvalidQuery", TestDomainStorageProviderDefinition, "This is not T-SQL", QueryType.Scalar); Provider.ExecuteScalarQuery(QueryFactory.CreateQuery(definition)); }
public void CreateQueryTest_InMemoryTripleStore() { LinqTripleStore ts = CreateLinqTripleStore(); IRdfContext context = new RdfDataContext(ts); QueryFactory<Track> factory = new QueryFactory<Track>(ts.QueryMethod, context); Assert.AreEqual(factory.QueryType, ts.QueryMethod); IRdfQuery<Track> query = factory.CreateQuery<Track>(); Assert.IsNotNull(query); Assert.IsTrue(query is LinqToSparqlQuery<Track>); }