Esempio n. 1
0
        private static void AppendWithClause(SqlStringBuilder fromFragment, bool hasConditions, SqlString[] withClauseFragments)
        {
            for (var i = 0; i < withClauseFragments.Length; i++)
            {
                var withClause = withClauseFragments[i];
                if (SqlStringHelper.IsEmpty(withClause))
                {
                    continue;
                }

                if (withClause.StartsWithCaseInsensitive(" and "))
                {
                    if (!hasConditions)
                    {
                        withClause = withClause.Substring(4);
                    }
                }
                else if (hasConditions)
                {
                    fromFragment.Add(" and ");
                }

                fromFragment.Add(withClause);
                hasConditions = true;
            }
        }
Esempio n. 2
0
        public void AddManyToManyJoin(JoinFragment outerjoin, IQueryableCollection collection)
        {
            string    manyToManyFilter = collection.GetManyToManyFilterFragment(rhsAlias, enabledFilters);
            SqlString condition        = string.Empty.Equals(manyToManyFilter)
                                                                ? on
                                                                : SqlStringHelper.IsEmpty(on) ? new SqlString(manyToManyFilter) :
                                         on.Append(" and ").Append(manyToManyFilter);

            outerjoin.AddJoin(joinable.TableName, rhsAlias, lhsColumns, rhsColumns, joinType, condition);
            outerjoin.AddJoins(joinable.FromJoinFragment(rhsAlias, false, true),
                               joinable.WhereJoinFragment(rhsAlias, false, true));
        }
Esempio n. 3
0
        private SqlString GetTableGroupJoinWithClause(SqlString[] withClauseFragments, Join first)
        {
            SqlStringBuilder fromFragment = new SqlStringBuilder();

            fromFragment.Add(")").Add(" on ");

            String[] lhsColumns        = first.LHSColumns;
            var      isAssociationJoin = lhsColumns.Length > 0;

            if (isAssociationJoin)
            {
                String   rhsAlias   = first.Alias;
                String[] rhsColumns = JoinHelper.GetRHSColumnNames(first.AssociationType, factory);
                for (int j = 0; j < lhsColumns.Length; j++)
                {
                    fromFragment.Add(lhsColumns[j]);
                    fromFragment.Add("=");
                    fromFragment.Add(rhsAlias);
                    fromFragment.Add(".");
                    fromFragment.Add(rhsColumns[j]);
                    if (j < lhsColumns.Length - 1)
                    {
                        fromFragment.Add(" and ");
                    }
                }
            }

            for (var i = 0; i < withClauseFragments.Length; i++)
            {
                var withClause = withClauseFragments[i];
                if (SqlStringHelper.IsEmpty(withClause))
                {
                    continue;
                }

                if (withClause.StartsWithCaseInsensitive(" and "))
                {
                    if (!isAssociationJoin)
                    {
                        withClause = withClause.Substring(4);
                    }
                }
                else if (isAssociationJoin)
                {
                    fromFragment.Add(" and ");
                }

                fromFragment.Add(withClause);
            }

            return(fromFragment.ToSqlString());
        }
Esempio n. 4
0
        private bool NeedsTableGroupJoin(List <Join> joins, SqlString[] withClauseFragments, bool includeSubclasses)
        {
            // If the rewrite is disabled or we don't have a with clause, we don't need a table group join
            if (/*!collectionJoinSubquery ||*/ withClauseFragments.All(x => SqlStringHelper.IsEmpty(x)))
            {
                return(false);
            }
            // If we only have one join, a table group join is only necessary if subclass columns are used in the with clause
            if (joins.Count == 1)
            {
                return(joins[0].Joinable is AbstractEntityPersister persister && persister.HasSubclassJoins(includeSubclasses));
                //NH Specific: No alias processing
                //return isSubclassAliasDereferenced( joins[ 0], withClauseFragment );
            }

            //NH Specific: No alias processing (see hibernate JoinSequence.NeedsTableGroupJoin)
            return(true);
        }
Esempio n. 5
0
        private static HashSet <string> GetDependsOn(OuterJoinableAssociation association)
        {
            if (SqlStringHelper.IsEmpty(association.On))
            {
                return(null);
            }

            var dependencies = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (Match match in aliasRegex.Matches(association.On.ToString()))
            {
                string alias = match.Value;
                if (string.Equals(alias, association.RHSAlias, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                dependencies.Add(alias);
            }

            return(dependencies);
        }