コード例 #1
0
        private EntityJoinFromElement CreateEntityJoin(
            IQueryable entityPersister,
            IASTNode aliasNode,
            int joinType,
            IASTNode with)
        {
            if (log.IsDebugEnabled())
            {
                log.Debug($"Creating entity-join FromElement [{aliasNode?.Text} -> {entityPersister.Name}]");
            }

            EntityJoinFromElement join = new EntityJoinFromElement(
                CurrentFromClause,
                entityPersister,
                JoinProcessor.ToHibernateJoinType(joinType),
                aliasNode?.Text
                );

            if (with != null)
            {
                HandleWithFragment(join, with);
            }

            return(join);
        }
コード例 #2
0
        private void PrepareGroupFetchingProcessSimple(FilterInterpritationResult filterCriteriaProcessingResult,
                                                       SortInfoInterpritationResult groupSortInfoProcessingResult,
                                                       PropertiesCollectionProcessingResult groupPropertiesProcessingResult,
                                                       SummaryInterpritationResult groupSummaryProcessingResult)
        {
            var groupQueryJOINSection = JoinProcessor.PrepareSimpleJoinSection(
                filterCriteriaProcessingResult.UsedJOINS,
                groupSortInfoProcessingResult.UsedJOINS,
                groupPropertiesProcessingResult.UsedJOINS,
                groupSummaryProcessingResult.UsedJOINS
                );
            var queryWHERESection        = filterCriteriaProcessingResult.ResultString.IsNotEmpty() ? "WHERE " + filterCriteriaProcessingResult.ResultString : string.Empty;
            var groupQueryORDERBYSection = groupSortInfoProcessingResult.ResultString.IsNotEmpty() ? "ORDER BY " + groupSortInfoProcessingResult.ResultString : string.Empty;


            SetGROUPQueryInfo(
                FillTemplatePlaceholders(
                    ("SELECT [PROPERTIES], [SUMMARIES] FROM [SOURCETYPE] [BASEALIAS] " +
                     "[QUERY JOIN SECTION]" +
                     "[QUERY WHERE SECTION]" +
                     "GROUP BY [PROPERTIES] " +
                     "[QUERY ORDERBY SECTION]")
                    .Replace("[QUERY JOIN SECTION]", groupQueryJOINSection.Add(" "))
                    .Replace("[QUERY WHERE SECTION]", queryWHERESection.Add(" "))
                    .Replace("[QUERY ORDERBY SECTION]", groupQueryORDERBYSection.Add(" "))
                    .Replace("[PROPERTIES]", groupPropertiesProcessingResult.ResultString)
                    .Replace("[SUMMARIES]", groupSummaryProcessingResult.ResultString)
                    ),
                string.Empty,
                groupPropertiesProcessingResult.PropertyExpressions,
                groupSummaryProcessingResult.SummaryDescriptors
                );
        }
コード例 #3
0
        private void PostProcessDML(IRestrictableStatement statement)
        {
            statement.FromClause.Resolve();

            var        fromElement = statement.FromClause.GetFromElementsTyped()[0];
            IQueryable persister   = fromElement.Queryable;

            // Make #@%$^#^&# sure no alias is applied to the table name
            fromElement.Text = persister.TableName;

            // Use the same logic as query does in order to support session filters
            var joinProcessor = new JoinProcessor(this);

            joinProcessor.ProcessJoins(statement);
        }
コード例 #4
0
 void SetImpliedJoinType(int joinType)
 {
     _impliedJoinType = JoinProcessor.ToHibernateJoinType(joinType);
 }
コード例 #5
0
        void ProcessQuery(IASTNode select, IASTNode query)
        {
            if (log.IsDebugEnabled())
            {
                log.Debug("processQuery() : {0}", query.ToStringTree());
            }

            try {
                QueryNode qn = ( QueryNode )query;

                // Was there an explicit select expression?
                bool explicitSelect = select != null && select.ChildCount > 0;

                if (!explicitSelect)
                {
                    // No explicit select expression; render the id and properties
                    // projection lists for every persister in the from clause into
                    // a single 'token node'.
                    //TODO: the only reason we need this stuff now is collection filters,
                    //      we should get rid of derived select clause completely!
                    CreateSelectClauseFromFromClause(qn);
                }
                else
                {
                    // Use the explicitly declared select expression; determine the
                    // return types indicated by each select token
                    UseSelectClause(select);
                }

                // After that, process the JOINs.
                // Invoke a delegate to do the work, as this is farily complex.
                JoinProcessor joinProcessor = new JoinProcessor(this);
                joinProcessor.ProcessJoins(qn);

                // Attach any mapping-defined "ORDER BY" fragments
                foreach (FromElement fromElement in qn.FromClause.GetProjectionList())
                {
                    if (fromElement.IsFetch && fromElement.QueryableCollection != null)
                    {
                        // Does the collection referenced by this FromElement
                        // specify an order-by attribute?  If so, attach it to
                        // the query's order-by
                        if (fromElement.QueryableCollection.HasOrdering)
                        {
                            string orderByFragment = fromElement
                                                     .QueryableCollection
                                                     .GetSQLOrderByString(fromElement.TableAlias);
                            qn.GetOrderByClause().AddOrderFragment(orderByFragment);
                        }
                        if (fromElement.QueryableCollection.HasManyToManyOrdering)
                        {
                            string orderByFragment = fromElement.QueryableCollection
                                                     .GetManyToManyOrderByString(fromElement.TableAlias);
                            qn.GetOrderByClause().AddOrderFragment(orderByFragment);
                        }
                    }
                }
            }
            finally
            {
                PopFromClause();
            }
        }
コード例 #6
0
        protected override void PrepareForFetchingProcess()
        {
            var filterCriteriaProcessingResult = JoinProcessor.Process(FilterCriteriaProcessor.Process(FilterCriteria));
            var baseSortInfoProcessingResult   = JoinProcessor.Process(SortInfoProcessor.Process(SortInfo));

            var selectQueryJOINSection = JoinProcessor.PrepareJoinSection(filterCriteriaProcessingResult.UsedJOINS, baseSortInfoProcessingResult.UsedJOINS);
            var queryWHERESection      = filterCriteriaProcessingResult.ResultString.IsNotEmpty() ? "WHERE " + filterCriteriaProcessingResult.ResultString : string.Empty;
            var queryORDERBYSection    = baseSortInfoProcessingResult.ResultString.IsNotEmpty() ? "ORDER BY " + baseSortInfoProcessingResult.ResultString : string.Empty;
            var queryPARAMETERS        = filterCriteriaProcessingResult.Parameters;

            SetSELECTQuery(
                FillTemplatePlaceholders(
                    ("SELECT [BASEALIAS] FROM [SOURCETYPE] [BASEALIAS] " +
                     "[QUERY JOIN SECTION]" +
                     "[QUERY WHERE SECTION]" +
                     "[QUERY ORDERBY SECTION]")
                    .Replace("[QUERY JOIN SECTION]", selectQueryJOINSection.Add(" "))
                    .Replace("[QUERY WHERE SECTION]", queryWHERESection.Add(" "))
                    .Replace("[QUERY ORDERBY SECTION]", queryORDERBYSection.Add(" "))
                    )
                );


            if (GroupCount > 0)
            {
                var groupSortInfo = SortInfo.Take(GroupCount).ToList();

                var groupSortInfoProcessingResult = JoinProcessor.Process(GroupSortInfoProcessor.Process(groupSortInfo));

                var groupExpressions = groupSortInfo.Select(x => x.SortExpression).ToList();
                var groupPropertiesProcessingResult = JoinProcessor.Process(GroupPropertiesProcessor.Process(groupExpressions));
                var groupSummaryProcessingResult    = JoinProcessor.Process(GroupSummaryProcessor.Process(GroupSummaryInfo));


                if (SortInfoProcessor.HasSpecialMappingsFor(groupSortInfo))
                {
                    PrepareGroupFetchingProcessComplicated(
                        filterCriteriaProcessingResult,
                        groupSortInfoProcessingResult,
                        groupPropertiesProcessingResult,
                        groupSummaryProcessingResult
                        );
                }
                else
                {
                    PrepareGroupFetchingProcessSimple(
                        filterCriteriaProcessingResult,
                        groupSortInfoProcessingResult,
                        groupPropertiesProcessingResult,
                        groupSummaryProcessingResult
                        );
                }
            }
            else
            {
                SetGROUPQueryInfo(null);
            }


            var totalSummaryProcessingResult = JoinProcessor.Process(TotalSummaryProcessor.Process(TotalSummaryInfo));
            var totalQueryJOINSection        = JoinProcessor.PrepareSimpleJoinSection(
                filterCriteriaProcessingResult.UsedJOINS,
                totalSummaryProcessingResult.UsedJOINS
                );

            SetTOTALQueryInfo(
                FillTemplatePlaceholders(
                    ("SELECT [SUMMARIES] FROM [SOURCETYPE] [BASEALIAS] " +
                     "[QUERY JOIN SECTION]" +
                     "[QUERY WHERE SECTION]")
                    .Replace("[QUERY JOIN SECTION]", totalQueryJOINSection.Add(" "))
                    .Replace("[QUERY WHERE SECTION]", queryWHERESection.Add(" "))
                    .Replace("[SUMMARIES]", totalSummaryProcessingResult.ResultString)
                    ),
                totalSummaryProcessingResult.SummaryDescriptors
                );


            SetQueryPARAMETERS(queryPARAMETERS);
        }