/// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary> /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param> /// <param name="expressionToExecute">The expression to execute. Can be null</param> /// <param name="aggregateToApply">Aggregate function to apply. </param> /// <param name="filter">The filter to apply to retrieve the scalar</param> /// <param name="relations">The relations to walk</param> /// <param name="groupByClause">The groupby clause to apply to retrieve the scalar</param> /// <returns>the scalar value requested</returns> public virtual object GetScalar(OrderAuditInfoFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IRelationCollection relations, IGroupByCollection groupByClause) { EntityFields fields = new EntityFields(1); fields[0] = EntityFieldFactory.Create(fieldIndex); if ((fields[0].ExpressionToApply == null) || (expressionToExecute != null)) { fields[0].ExpressionToApply = expressionToExecute; } if ((fields[0].AggregateFunctionToApply == AggregateFunction.None) || (aggregateToApply != AggregateFunction.None)) { fields[0].AggregateFunctionToApply = aggregateToApply; } return(DAOFactory.CreateOrderAuditInfoDAO().GetScalar(fields, this.Transaction, filter, relations, groupByClause)); }
/// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary> /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param> /// <param name="expressionToExecute">The expression to execute. Can be null</param> /// <param name="aggregateToApply">Aggregate function to apply. </param> /// <param name="filter">The filter to apply to retrieve the scalar</param> /// <param name="groupByClause">The groupby clause to apply to retrieve the scalar</param> /// <returns>the scalar value requested</returns> public object GetScalar(RegionFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IGroupByCollection groupByClause) { return(GetScalar(fieldIndex, expressionToExecute, aggregateToApply, filter, null, groupByClause)); }
/// <summary>Fills itself with data. it builds a dynamic query and loads itself with that query, using the specified filter</summary> /// <param name="maxNumberOfItemsToReturn">The maximum amount of rows to return. specifying 0 means all rows are returned</param> /// <param name="sortClauses">The order by specifications for the sorting of the resultset. When null is specified, no sorting is applied.</param> /// <param name="allowDuplicates">Flag to allow duplicate rows (true) or not (false)</param> /// <param name="selectFilter">Predicate expression to filter on the rows inserted in this TypedView object.</param> /// <param name="transactionToUse">The transaction object to use. Can be null. If specified, the connection object of the transaction is /// used to fill the TypedView, which avoids deadlocks on SqlServer.</param> /// <param name="groupByClause">GroupByCollection with fields to group by on.</param> /// <returns>true if fill succeeded, false otherwise</returns> public bool Fill(long maxNumberOfItemsToReturn, ISortExpression sortClauses, bool allowDuplicates, IPredicate selectFilter, ITransaction transactionToUse, IGroupByCollection groupByClause) { return(Fill(maxNumberOfItemsToReturn, sortClauses, allowDuplicates, selectFilter, transactionToUse, groupByClause, 0, 0)); }
/// <summary> /// Retrieves rows in the datatable provided which match the specified filter, containing the fields specified. It will always create a new connection to the database. /// </summary> /// <param name="fieldsToReturn">IEntityFields implementation which forms the definition of the resultset to return.</param> /// <param name="tableToFill">The datatable to fill with the rows retrieved</param> /// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return with this retrieval query. /// If the used Dynamic Query Engine supports it, 'TOP' is used to limit the amount of rows to return. When set to 0, no limitations are specified.</param> /// <param name="sortClauses">The order by specifications for the sorting of the resultset. When null is specified, no sorting is applied.</param> /// <param name="selectFilter">A predicate or predicate expression which should be used as filter for the entities to retrieve.</param> /// <param name="relations">The set of relations to walk to construct to total query.</param> /// <param name="allowDuplicates">Flag to allow duplicate rows or not</param> /// <param name="groupByClause">The list of fields to group by on. When not specified or an empty collection is specified, no group by clause /// is added to the query. A check is performed for each field in the selectList. If a field in the selectList is not present in the groupByClause collection, an exception is thrown.</param> /// <param name="transactionToUse">The transaction object to use. Can be null. If specified, the connection object of the transaction is used to fill the TypedView, which avoids deadlocks on SqlServer.</param> /// <param name="pageNumber">The page number to retrieve.</param> /// <param name="pageSize">The page size of the page to retrieve.</param> /// <returns>true if succeeded, false otherwise</returns> public bool GetMultiAsDataTable(IEntityFields fieldsToReturn, DataTable tableToFill, long maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, bool allowDuplicates, IGroupByCollection groupByClause, ITransaction transactionToUse, int pageNumber, int pageSize) { return base.PerformGetMultiAsDataTableAction(fieldsToReturn, tableToFill, maxNumberOfItemsToReturn, sortClauses, selectFilter, relations, allowDuplicates, groupByClause, transactionToUse, pageNumber, pageSize); }
/// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary> /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param> /// <param name="expressionToExecute">The expression to execute. Can be null</param> /// <param name="aggregateToApply">Aggregate function to apply. </param> /// <param name="filter">The filter to apply to retrieve the scalar</param> /// <param name="relations">The relations to walk</param> /// <param name="groupByClause">The groupby clause to apply to retrieve the scalar</param> /// <returns>the scalar value requested</returns> public virtual object GetScalar(SalesReasonFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IRelationCollection relations, IGroupByCollection groupByClause) { EntityFields fields = new EntityFields(1); fields[0] = EntityFieldFactory.Create(fieldIndex); if ((fields[0].ExpressionToApply == null) || (expressionToExecute != null)) { fields[0].ExpressionToApply = expressionToExecute; } if ((fields[0].AggregateFunctionToApply == AggregateFunction.None) || (aggregateToApply != AggregateFunction.None)) { fields[0].AggregateFunctionToApply = aggregateToApply; } SalesReasonDAO dao = DAOFactory.CreateSalesReasonDAO(); return(dao.GetScalar(fields, base.Transaction, filter, relations, groupByClause)); }
/// <summary> /// Creates a new Select Query which is ready to use, based on the specified select list and the specified set of relations. /// If selectFilter is set to null, all rows are selected. /// </summary> /// <param name="selectList">list of IEntityFieldCore objects to select</param> /// <param name="fieldsPersistenceInfo">Array of IFieldPersistenceInfo objects to use to build the select query</param> /// <param name="query">The query to fill.</param> /// <param name="selectFilter">A complete IPredicate implementing object which contains the filter for the rows to select. When set to null, no /// filtering is done, and all rows are returned.</param> /// <param name="maxNumberOfItemsToReturn">The maximum number of items to return with this retrieval query. /// If the used Dynamic Query Engine supports it, 'TOP' is used to limit the amount of rows to return. /// When set to 0, no limitations are specified.</param> /// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified, no sorting is applied.</param> /// <param name="relationsToWalk">list of EntityRelation objects, which will be used to formulate a FROM clause with INNER JOINs.</param> /// <param name="allowDuplicates">Flag which forces the inclusion of DISTINCT if set to true. If the resultset contains fields of type ntext, text or image, no duplicate filtering /// is done.</param> /// <param name="groupByClause">The list of fields to group by on. When not specified or an empty collection is specified, no group by clause /// is added to the query. A check is performed for each field in the selectList. If a field in the selectList is not present in the groupByClause /// collection, an exception is thrown.</param> /// <param name="relationsSpecified">flag to signal if relations are specified, this is a result of a check. This routine should /// simply assume the value of this flag is correct.</param> /// <param name="sortClausesSpecified">flag to signal if sortClauses are specified, this is a result of a check. This routine should /// simply assume the value of this flag is correct.</param> /// <exception cref="System.ArgumentNullException">When selectList is null or fieldsPersistenceInfo is null</exception> /// <exception cref="System.ArgumentException">When selectList contains no EntityFieldCore instances or fieldsPersistenceInfo is empty.</exception> protected override void CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IRetrievalQuery query, IPredicate selectFilter, long maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, bool allowDuplicates, IGroupByCollection groupByClause, bool relationsSpecified, bool sortClausesSpecified) { TraceHelper.WriteLineIf(Switch.TraceInfo, "CreateSelectDQ", "Method Enter"); QueryFragments fragments = new QueryFragments(); fragments.AddFragment("SELECT"); StringPlaceHolder distinctPlaceholder = fragments.AddPlaceHolder(); StringPlaceHolder topPlaceholder = fragments.AddPlaceHolder(); DelimitedStringList projection = fragments.AddCommaFragmentList(false); UniqueList <string> fieldNamesInSelectList; bool distinctViolatingTypesFound; bool pkFieldSeen; AppendResultsetFields(selectList, fieldsPersistenceInfo, relationsToWalk, projection, sortClausesSpecified, allowDuplicates, true, new UniqueList <string>(), query, out fieldNamesInSelectList, out distinctViolatingTypesFound, out pkFieldSeen); bool resultsCouldContainDuplicates = this.DetermineIfDuplicatesWillOccur(relationsToWalk); bool distinctEmitted = this.HandleDistinctEmit(sortClauses, allowDuplicates, sortClausesSpecified, query, distinctPlaceholder, distinctViolatingTypesFound, (pkFieldSeen && !resultsCouldContainDuplicates), fieldNamesInSelectList); bool groupByClauseSpecified = ((groupByClause != null) && (groupByClause.Count > 0)); if (maxNumberOfItemsToReturn > 0) { // row limits are emitted always, unless duplicates are required but DISTINCT wasn't emitable. If not emitable, switch to client-side row limitation if (distinctEmitted || !resultsCouldContainDuplicates || groupByClauseSpecified || allowDuplicates) { topPlaceholder.SetFormatted("TOP {0}", maxNumberOfItemsToReturn); } else { query.RequiresClientSideLimitation = true; query.ManualRowsToTake = (int)maxNumberOfItemsToReturn; } } if (relationsSpecified) { fragments.AddFormatted("FROM {0}", relationsToWalk.ToQueryText()); query.AddParameters(((RelationCollection)relationsToWalk).CustomFilterParameters); } else { var persistenceInfoToUse = fieldsPersistenceInfo.FirstOrDefault(p => p != null); if ((persistenceInfoToUse != null) && (persistenceInfoToUse.SourceObjectName.Length > 0)) { fragments.AddFormatted(" FROM {0}", this.Creator.CreateObjectName(persistenceInfoToUse)); string targetAlias = this.DetermineTargetAlias(selectList[0], relationsToWalk); if (targetAlias.Length > 0) { fragments.AddFormatted(" {0}", this.Creator.CreateValidAlias(targetAlias)); } } } AppendWhereClause(selectFilter, fragments, query); AppendGroupByClause(groupByClause, fragments, query); AppendOrderByClause(sortClauses, fragments, query); query.SetCommandText(MakeParametersAnonymous(fragments.ToString(), query.Parameters)); TraceHelper.WriteIf(Switch.TraceVerbose, query, "Generated Sql query"); TraceHelper.WriteLineIf(Switch.TraceInfo, "CreateSelectDQ", "Method Exit"); }
/// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary> /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param> /// <param name="expressionToExecute">The expression to execute. Can be null</param> /// <param name="aggregateToApply">Aggregate function to apply. </param> /// <param name="filter">The filter to apply to retrieve the scalar</param> /// <param name="groupByClause">The groupby clause to apply to retrieve the scalar</param> /// <returns>the scalar value requested</returns> public object GetScalar(AssetReclamationServiceChangeLogFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IGroupByCollection groupByClause) { return(GetScalar(fieldIndex, expressionToExecute, aggregateToApply, filter, null, groupByClause)); }
/// <summary>Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary> /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param> /// <param name="expressionToExecute">The expression to execute. Can be null</param> /// <param name="aggregateToApply">Aggregate function to apply. </param> /// <param name="filter">The filter to apply to retrieve the scalar</param> /// <param name="relations">The relations to walk</param> /// <param name="groupByClause">The groupby clause to apply to retrieve the scalar</param> /// <returns>the scalar value requested</returns> public virtual object GetScalar(CustomerDemographicFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IRelationCollection relations, IGroupByCollection groupByClause) { EntityFields fields = new EntityFields(1); fields[0] = EntityFieldFactory.Create(fieldIndex); if(expressionToExecute != null) { fields[0].ExpressionToApply = expressionToExecute; } if(aggregateToApply != AggregateFunction.None) { fields[0].AggregateFunctionToApply = aggregateToApply; } return DAOFactory.CreateCustomerDemographicDAO().GetScalar(fields, this.Transaction, filter, relations, groupByClause); }