Пример #1
0
        private void AddExtraJoins(JoinFragment joinFragment, string alias, IJoinable joinable, bool innerJoin)
        {
            bool include = IsIncluded(alias);

            joinFragment.AddJoins(joinable.FromJoinFragment(alias, innerJoin, include),
                                  joinable.WhereJoinFragment(alias, innerJoin, include));
        }
Пример #2
0
        private void AddSubclassJoins(JoinFragment joinFragment, String alias, IJoinable joinable, bool innerJoin, bool includeSubclassJoins)
        {
            bool include = includeSubclassJoins && IsIncluded(alias);

            joinFragment.AddJoins(joinable.FromJoinFragment(alias, innerJoin, include),
                                  joinable.WhereJoinFragment(alias, innerJoin, include));
        }
Пример #3
0
        private void AddJoin(JoinFragment ojf, QueryTranslator q)
        {
            JoinFragment fromClause = q.CreateJoinFragment(true);

            fromClause.AddJoins(ojf.ToFromFragmentString, new SqlString(String.Empty));
            q.AddJoin(pathExpressionParser.Name, fromClause);
            //TODO: HACK with ToString()
            AddToCurrentJoin(ojf.ToWhereFragmentString.ToString());
        }
Пример #4
0
        public void AddManyToManyJoin(JoinFragment outerjoin, IQueryableCollection collection)
        {
            string manyToManyFilter = collection.GetManyToManyFilterFragment(rhsAlias, enabledFilters);
            string condition        = string.Empty.Equals(manyToManyFilter)
                                                ? on
                                                : string.Empty.Equals(on) ? manyToManyFilter : on + " and " + manyToManyFilter;

            outerjoin.AddJoin(joinable.TableName, rhsAlias, lhsColumns, rhsColumns, joinType, condition);
            outerjoin.AddJoins(joinable.FromJoinFragment(rhsAlias, false, true),
                               joinable.WhereJoinFragment(rhsAlias, false, true));
        }
Пример #5
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));
        }
        private void PrepareForIndex(QueryTranslator q)
        {
            IQueryableCollection collPersister = q.GetCollectionPersister(collectionRole);

            if (!collPersister.HasIndex)
            {
                throw new QueryException("unindexed collection before []");
            }
            string[] indexCols = collPersister.IndexColumnNames;
            if (indexCols.Length != 1)
            {
                throw new QueryException("composite-index appears in []: " + path);
            }
            string[] keyCols = collPersister.KeyColumnNames;

            JoinFragment ojf = q.CreateJoinFragment(useThetaStyleJoin);

            ojf.AddCrossJoin(collPersister.TableName, collectionName);
            ojf.AddFromFragmentString(join.ToFromFragmentString);
            if (collPersister.IsOneToMany)
            {
                IQueryable persister = (IQueryable)collPersister.ElementPersister;
                ojf.AddJoins(
                    ((IJoinable)persister).FromJoinFragment(collectionName, true, false),
                    ((IJoinable)persister).WhereJoinFragment(collectionName, true, false)
                    );
            }

            if (!continuation)
            {
                AddJoin(collPersister.TableName, collectionName, keyCols);
            }
            join.AddCondition(collectionName, indexCols, " = ");

            string[] eltCols = collPersister.ElementColumnNames;

            CollectionElement elem = new CollectionElement();

            elem.ElementColumns = StringHelper.Qualify(collectionName, eltCols);
            elem.Type           = collPersister.ElementType;
            elem.IsOneToMany    = collPersister.IsOneToMany;
            elem.Alias          = collectionName;
            elem.Join           = join;
            collectionElements.Add(elem);               //addlast
            SetExpectingCollectionIndex();

            q.AddCollection(collectionName, collectionRole);
            q.AddJoin(collectionName, ojf);
        }
Пример #7
0
        /// <summary>
        /// Generate a sequence of <c>LEFT OUTER JOIN</c> clauses for the given associations.
        /// </summary>
        /// <param name="associations"></param>
        /// <returns></returns>
        protected JoinFragment MergeOuterJoins(IList associations)
        {
            JoinFragment outerjoin = dialect.CreateOuterJoinFragment();

            foreach (OuterJoinLoader.OuterJoinableAssociation oj in associations)
            {
                outerjoin.AddJoin(oj.TableName, oj.Subalias, oj.ForeignKeyColumns, oj.PrimaryKeyColumns, oj.JoinType);
                outerjoin.AddJoins(
                    oj.Joinable.FromJoinFragment(oj.Subalias, false, true),
                    oj.Joinable.WhereJoinFragment(oj.Subalias, false, true)
                    );
            }

            return(outerjoin);
        }
Пример #8
0
        internal static bool ProcessAsTableGroupJoin(IReadOnlyList <IJoin> tableGroupJoinables, SqlString[] withClauseFragments, bool includeAllSubclassJoins, JoinFragment joinFragment, Func <string, bool> isSubclassIncluded, ISessionFactoryImplementor sessionFactoryImplementor)
        {
            if (!NeedsTableGroupJoin(tableGroupJoinables, withClauseFragments, includeAllSubclassJoins))
            {
                return(false);
            }

            var    first      = tableGroupJoinables[0];
            string joinString = ANSIJoinFragment.GetJoinString(first.JoinType);

            joinFragment.AddFromFragmentString(
                new SqlString(
                    joinString,
                    " (",
                    first.Joinable.TableName,
                    " ",
                    first.Alias
                    ));

            foreach (var join in tableGroupJoinables)
            {
                if (join != first)
                {
                    joinFragment.AddJoin(
                        join.Joinable.TableName,
                        join.Alias,
                        join.LHSColumns,
                        JoinHelper.GetRHSColumnNames(join.AssociationType, sessionFactoryImplementor),
                        join.JoinType,
                        SqlString.Empty);
                }

                bool include = includeAllSubclassJoins && isSubclassIncluded(join.Alias);
                // TODO (from hibernate): Think about if this could be made always true
                // NH Specific: made always true (original check: join.JoinType == JoinType.InnerJoin)
                const bool innerJoin = true;
                joinFragment.AddJoins(
                    join.Joinable.FromJoinFragment(join.Alias, innerJoin, include),
                    join.Joinable.WhereJoinFragment(join.Alias, innerJoin, include));
            }

            var withClause = GetTableGroupJoinWithClause(withClauseFragments, first, sessionFactoryImplementor);

            joinFragment.AddFromFragmentString(withClause);
            return(true);
        }
Пример #9
0
 public void AddJoins(JoinFragment outerjoin)
 {
     outerjoin.AddJoin(joinable.TableName, rhsAlias, lhsColumns, rhsColumns, joinType, on);
     outerjoin.AddJoins(joinable.FromJoinFragment(rhsAlias, false, true),
                        joinable.WhereJoinFragment(rhsAlias, false, true));
 }