コード例 #1
0
ファイル: SqlQueryGenerator.cs プロジェクト: mirkomaty/NDO
        void CreateSubQueries(QueryContextsEntry queryContextsEntry,
                              OqlExpression expressionTree,
                              bool hollow,
                              bool hasSubclassResultsets,
                              List <QueryOrder> orderings,
                              int skip,
                              int take)
        {
            Type t             = queryContextsEntry.Type;
            var  queryContexts = queryContextsEntry.QueryContexts;

            if (queryContexts.Count == 0)
            {
                this.subQueries.Add(new QueryInfo(t, ConstructQueryString(t, new Dictionary <Relation, Class>(), expressionTree, hollow, hasSubclassResultsets, orderings, skip, take)));
            }
            else
            {
                string queryString = string.Empty;
                int    added       = 0;
                foreach (var queryContext in queryContexts)
                {
                    if (!queryContext.Any(kvp => kvp.Value.SystemType == t))
                    {
                        if (added > 0)
                        {
                            queryString += " UNION \r\n";
                        }
                        queryString += ConstructQueryString(t, queryContext, expressionTree, hollow, hasSubclassResultsets, orderings, skip, take);
                        added++;
                    }
                }
                this.subQueries.Add(new QueryInfo(t, queryString));
            }
        }
コード例 #2
0
ファイル: SqlQueryGenerator.cs プロジェクト: mirkomaty/NDO
        public string GenerateAggregateQueryString(string field, QueryContextsEntry queryContextsEntry, OqlExpression expressionTree, bool hasSubclassResultsets, AggregateType aggregateType)
        {
            this.selectPartCreator        = CreateAggregateSelectPart;
            this.additionalSelectPartData = new Tuple <string, AggregateType>(field, aggregateType);

            var query = InnerGenerateQueryString(queryContextsEntry, expressionTree, true, hasSubclassResultsets, new List <QueryOrder>(), 0, 0, null);

            return(query);
        }
コード例 #3
0
ファイル: SqlQueryGenerator.cs プロジェクト: mirkomaty/NDO
        /// <summary>
        /// Creates a SQL query string, which can be passed to the IPersistenceHandler to fetch the results for a given concrete type.
        /// </summary>
        /// <param name="queryContextsEntry">All contexts which define possible mutations of concrete classes in results and relations.</param>
        /// <param name="expressionTree">The syntax tree of the NDOql query expression.</param>
        /// <param name="hollow">Determines, if the query results should be hollow objects.</param>
        /// <param name="hasSubclassResultsets">Determines, if this query is part of a composed query which spans over several tables.</param>
        /// <param name="orderings">List of orderings for the resultset.</param>
        /// <param name="skip">Determines how many records of the resultset should be skipped. The resultset must be ordered.</param>
        /// <param name="take">Determines how many records of the resultset should be returned by the query. The resultset must be ordered.</param>
        /// <param name="prefetch">Query for the given prefetch relation.</param>
        /// <returns>A Query string.</returns>
        public string GenerateQueryString(
            QueryContextsEntry queryContextsEntry,
            OqlExpression expressionTree,
            bool hollow,
            bool hasSubclassResultsets,
            List <QueryOrder> orderings,
            int skip,
            int take,
            string prefetch)
        {
            this.selectPartCreator = CreateQuerySelectPart;

            return(InnerGenerateQueryString(queryContextsEntry, expressionTree, hollow, hasSubclassResultsets, orderings, skip, take, prefetch));
        }
コード例 #4
0
ファイル: SqlQueryGenerator.cs プロジェクト: mirkomaty/NDO
        private string InnerGenerateQueryString(QueryContextsEntry queryContextsEntry, OqlExpression expressionTree, bool hollow, bool hasSubclassResultsets, List <QueryOrder> orderings, int skip, int take, string prefetch)
        {
            CreateSubQueries(queryContextsEntry, expressionTree, hollow, hasSubclassResultsets, orderings, skip, take);
            StringBuilder generatedQuery = new StringBuilder();

            foreach (QueryInfo qi in subQueries)
            {
                generatedQuery.Append(qi.QueryString);
                generatedQuery.Append(";\n");
            }

            generatedQuery.Length--;             // the trailing \n

            if (subQueries.Count == 1)
            {
                generatedQuery.Length--;                 // the semicolon
            }
            return(generatedQuery.ToString());
        }