public override SqlString FromJoinFragment(string alias, bool innerJoin, bool includeSubclasses) { var elementJoinFragment = ((IJoinable)ElementPersister).FromJoinFragment(alias, innerJoin, includeSubclasses); if (CollectionType.UseLHSPrimaryKey) { return(elementJoinFragment); } JoinFragment join = Factory.Dialect.CreateOuterJoinFragment(); var lhsKeyColumnNames = new string[JoinColumnNames.Length]; int k = 0; foreach (string columnName in JoinColumnNames) { lhsKeyColumnNames[k] = alias + StringHelper.Dot + columnName; k++; } var ownerPersister = (IOuterJoinLoadable)OwnerEntityPersister; join.AddJoin(ownerPersister.TableName, GenerateTableAliasForKeyColumns(alias), lhsKeyColumnNames, ownerPersister.GetPropertyColumnNames(CollectionType.LHSPropertyName), innerJoin ? JoinType.InnerJoin : JoinType.LeftOuterJoin); return(join.ToFromFragmentString + elementJoinFragment); }
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)); }
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)); }
/// <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); }
private bool ProcessAsTableGroupJoin(bool includeAllSubclassJoins, SqlString[] withClauseFragments, JoinFragment joinFragment) { if (!NeedsTableGroupJoin(joins, withClauseFragments, includeAllSubclassJoins)) { return(false); } var first = joins[0]; string joinString = ANSIJoinFragment.GetJoinString(first.JoinType); joinFragment.AddFromFragmentString( new SqlString( joinString, " (", first.Joinable.TableName, " ", first.Alias )); foreach (var join in joins) { if (join != first) { joinFragment.AddJoin( join.Joinable.TableName, join.Alias, join.LHSColumns, JoinHelper.GetRHSColumnNames(join.AssociationType, factory), join.JoinType, SqlString.Empty); } AddSubclassJoins( joinFragment, join.Alias, join.Joinable, // TODO (from hibernate): Think about if this could be made always true // NH Specific: made always true (original check: join.JoinType == JoinType.InnerJoin) true, includeAllSubclassJoins ); } var tableGroupWithClause = GetTableGroupJoinWithClause(withClauseFragments, first); joinFragment.AddFromFragmentString(tableGroupWithClause); return(true); }
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); }
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)); }