internal AllorsPredicateAssociationContainsSql(AllorsExtentFilteredSql extent, IAssociationType association, IObject allorsObject) { extent.CheckAssociation(association); PredicateAssertions.AssertAssociationContains(association, allorsObject); this.association = association; this.allorsObject = allorsObject; }
internal AssociationExists(ExtentFiltered extent, IAssociationType associationType) { extent.CheckForAssociationType(associationType); PredicateAssertions.ValidateAssociationExists(associationType); this.associationType = associationType; }
/// <summary> /// Get the columns of the owning entity which are to /// be used in the join /// </summary> public static string[] GetLHSColumnNames( IAssociationType type, int property, int begin, IOuterJoinLoadable lhsPersister, IMapping mapping ) { if (type.UseLHSPrimaryKey) { //return lhsPersister.getSubclassPropertyColumnNames(property); return lhsPersister.IdentifierColumnNames; } else { string propertyName = type.LHSPropertyName; if (propertyName == null) { //slice, to get the columns for this component //property return ArrayHelper.Slice( lhsPersister.GetSubclassPropertyColumnNames(property), begin, type.GetColumnSpan(mapping) ); } else { //property-refs for associations defined on a //component are not supported, so no need to slice return lhsPersister.GetPropertyColumnNames(propertyName); } } }
protected override JoinType GetJoinType(IAssociationType type, FetchMode config, string path, string lhsTable, string[] lhsColumns, bool nullable, int currentDepth, CascadeStyle cascadeStyle) { if (translator.IsJoin(path)) { return translator.GetJoinType(path); } else { if (translator.HasProjection) { return JoinType.None; } else { FetchMode fetchMode = translator.RootCriteria.GetFetchMode(path); if (IsDefaultFetchMode(fetchMode)) { return base.GetJoinType(type, config, path, lhsTable, lhsColumns, nullable, currentDepth, cascadeStyle); } else { if (fetchMode == FetchMode.Join) { IsDuplicateAssociation(lhsTable, lhsColumns, type); //deliberately ignore return value! return GetJoinType(nullable, currentDepth); } else { return JoinType.None; } } } } }
internal void CheckForAssociationType(IAssociationType association) { if (!this.objectType.ExistAssociationType(association)) { throw new ArgumentException("Extent does not have association " + association); } }
public AssociationContainedInEnumerable(AllorsExtentFilteredSql extent, IAssociationType association, IEnumerable<IObject> enumerable) { extent.CheckAssociation(association); PredicateAssertions.AssertAssociationContainedIn(association, this.enumerable); this.association = association; this.enumerable = enumerable; }
protected virtual JoinType GetJoinType( IAssociationType type, OuterJoinFetchStrategy config, string path, string table, string[] foreignKeyColumns, ISessionFactoryImplementor factory ) { bool mappingDefault = IsJoinedFetchEnabledByDefault( config, type, factory ); return IsJoinedFetchEnabled( type, mappingDefault, path, table, foreignKeyColumns) ? JoinType.LeftOuterJoin : JoinType.None; }
internal AllorsPredicateAssociationInstanceofSql(AllorsExtentFilteredSql extent, IAssociationType association, IObjectType instanceType, IClass[] instanceClasses) { extent.CheckAssociation(association); PredicateAssertions.ValidateAssociationInstanceof(association, instanceType); this.association = association; this.instanceClasses = instanceClasses; }
internal AllorsPredicateAssociationInExtentSql(AllorsExtentFilteredSql extent, IAssociationType association, Extent inExtent) { extent.CheckAssociation(association); PredicateAssertions.AssertAssociationContainedIn(association, inExtent); this.association = association; this.inExtent = (AllorsExtentSql) inExtent; }
internal AssociationEquals(ExtentFiltered extent, IAssociationType association, IObject allorsObject) { extent.CheckAssociation(association); PredicateAssertions.AssertAssociationEquals(association, allorsObject); this.association = association; this.allorsObject = allorsObject; }
internal AssociationContainedInExtent(ExtentFiltered extent, IAssociationType association, Allors.Extent inExtent) { extent.CheckAssociation(association); PredicateAssertions.AssertAssociationContainedIn(association, inExtent); this.association = association; this.inExtent = ((Extent)inExtent).ContainedInExtent; }
/// <summary> /// Get the aliased columns of the owning entity which are to /// be used in the join /// </summary> public static string[] GetAliasedLHSColumnNames( IAssociationType type, string alias, int property, int begin, IOuterJoinLoadable lhsPersister, IMapping mapping ) { if (type.UseLHSPrimaryKey) { return StringHelper.Qualify(alias, lhsPersister.IdentifierColumnNames); } else { string propertyName = type.LHSPropertyName; if (propertyName == null) { return ArrayHelper.Slice( lhsPersister.ToColumns(alias, property), begin, type.GetColumnSpan(mapping) ); } else { return ((IPropertyMapping) lhsPersister).ToColumns(alias, propertyName); //bad cast } } }
/// <summary> /// Disable outer join fetching if this loader obtains an /// upgrade lock mode /// </summary> protected override bool IsJoinedFetchEnabled(IAssociationType type, FetchMode config, Cascades.CascadeStyle cascadeStyle) { return lockMode.GreaterThan(LockMode.Read) ? false : base.IsJoinedFetchEnabled(type, config, cascadeStyle); }
internal AssociationContainedInEnumerable(ExtentFiltered extent, IAssociationType associationType, IEnumerable<IObject> containingEnumerable) { extent.CheckForAssociationType(associationType); PredicateAssertions.AssertAssociationContainedIn(associationType, containingEnumerable); this.associationType = associationType; this.containingEnumerable = containingEnumerable; }
internal AssociationEquals(ExtentFiltered extent, IAssociationType associationType, IObject equals) { extent.CheckForAssociationType(associationType); PredicateAssertions.AssertAssociationEquals(associationType, equals); this.associationType = associationType; this.equals = equals; }
internal AssociationContains(ExtentFiltered extent, IAssociationType associationType, IObject containedObject) { extent.CheckForAssociationType(associationType); PredicateAssertions.AssertAssociationContains(associationType, containedObject); this.associationType = associationType; this.containedObject = containedObject; }
internal AssociationInstanceOf(ExtentFiltered extent, IAssociationType associationType, IObjectType instanceObjectType) { extent.CheckForAssociationType(associationType); PredicateAssertions.ValidateAssociationInstanceof(associationType, instanceObjectType); this.associationType = associationType; this.objectType = instanceObjectType; }
internal AssociationContainedInExtent(ExtentFiltered extent, IAssociationType associationType, Allors.Extent containingExtent) { extent.CheckForAssociationType(associationType); PredicateAssertions.AssertAssociationContainedIn(associationType, containingExtent); this.associationType = associationType; this.containingExtent = containingExtent; }
public Join(ISessionFactoryImplementor factory, IAssociationType associationType, string alias, JoinType joinType, string[] lhsColumns) { this.associationType = associationType; this.joinable = associationType.GetAssociatedJoinable(factory); this.alias = alias; this.joinType = joinType; this.lhsColumns = lhsColumns; }
/// <summary> /// Get the columns of the owning entity which are to /// be used in the join /// </summary> public static string[] GetLHSColumnNames( IAssociationType type, int property, IOuterJoinLoadable lhsPersister, IMapping mapping ) { return GetLHSColumnNames(type, property, 0, lhsPersister, mapping); }
private void AddJoin(string name, IAssociationType joinableType, string[] foreignKeyColumns) { try { joinSequence.AddJoin(joinableType, name, joinType, foreignKeyColumns); } catch (MappingException me) { throw new QueryException(me); } }
/// <summary> /// We can use an inner join for first many-to-many association /// </summary> protected JoinType GetJoinType(IAssociationType type, FetchMode config, String path, ISet visitedAssociations, string lhsTable, string[] lhsColumns, bool nullable, int currentDepth) { JoinType joinType = base.GetJoinType(type, config, path, lhsTable, lhsColumns, nullable, currentDepth, null); //we can use an inner join for the many-to-many if (joinType == JoinType.LeftOuterJoin && string.Empty.Equals(path)) { joinType = JoinType.InnerJoin; } return joinType; }
internal void FlushConditionally(long roleId, IAssociationType associationType) { if (this.State.TriggersFlushRolesByAssociationType != null) { if (this.State.TriggersFlushRolesByAssociationType.TryGetValue(associationType, out var roles)) { if (roles.Contains(roleId)) { this.Flush(); } } } }
/// <summary> /// Asserts that the <see cref="AssociationType"/> and the <see cref="IObjectType"/> are compatible with /// <see cref="ICompositePredicate#AddInstanceof"/>. /// </summary> /// <param name="association">The association.</param> /// <param name="objectType">The object type.</param> public static void ValidateAssociationInstanceof(IAssociationType association, IObjectType objectType) { if (objectType is IUnit) { throw new ArgumentException("AddInstanceof() can only be used with a composite type."); } if (association.IsMany) { throw new ArgumentException( "AddInstanceof() can only be used when the association has multiplicity one."); } }
/// <summary> /// Asserts that the <see cref="AssociationType"/> and the <see cref="IObject"/> are compatible with /// <see cref="ICompositePredicate#AddContains"/>. /// </summary> /// <param name="association">The association.</param> /// <param name="allorsObject">The allors object.</param> public static void AssertAssociationContains(IAssociationType association, IObject allorsObject) { if (!association.IsMany) { throw new ArgumentException( "AddContains() can only be used when the association has multiplicity many, use AssociationEquals() instead."); } if (allorsObject == null) { throw new ArgumentException("AddContains() requires an object."); } }
internal long[] GetAssociations(Strategy roleStrategy, IAssociationType associationType) { var associationsByRole = this.State.GetAssociationsByRole(associationType); if (!associationsByRole.TryGetValue(roleStrategy.Reference, out var associations)) { this.FlushConditionally(roleStrategy.ObjectId, associationType); associations = this.Commands.GetCompositesAssociation(roleStrategy, associationType); associationsByRole[roleStrategy.Reference] = associations; } return(associations); }
/// <summary> /// Get the columns of the associated table which are to /// be used in the join /// </summary> public static string[] GetRHSColumnNames(IAssociationType type, ISessionFactoryImplementor factory) { string uniqueKeyPropertyName = type.RHSUniqueKeyPropertyName; IJoinable joinable = type.GetAssociatedJoinable(factory); if (uniqueKeyPropertyName == null) { return joinable.JoinColumnNames; } else { return ((IOuterJoinLoadable)joinable).GetPropertyColumnNames(uniqueKeyPropertyName); } }
public OuterJoinableAssociation( IAssociationType joinableType, String lhsAlias, String[] lhsColumns, String rhsAlias, JoinType joinType, SqlString withClause, ISessionFactoryImplementor factory, IDictionary <string, IFilter> enabledFilters, SelectMode selectMode) : this(joinableType, lhsAlias, lhsColumns, rhsAlias, joinType, withClause, factory, enabledFilters) { _selectMode = selectMode; }
public virtual void FlushConditionally(Strategy strategy, IAssociationType associationType) { if (this.triggersFlushRolesByAssociationType != null) { HashSet <long> roles; if (this.triggersFlushRolesByAssociationType.TryGetValue(associationType, out roles)) { if (roles.Contains(strategy.ObjectId)) { this.Flush(); } } } }
protected internal void InitPropertyPaths(string path, IType type, string[] columns, string[] formulaTemplates, IMapping factory) { if (columns.Length != type.GetColumnSpan(factory)) { throw new MappingException( string.Format("broken column mapping for: {0} of: {1}, type {2} expects {3} columns, but {4} were mapped", path, EntityName, type.Name, type.GetColumnSpan(factory), columns.Length)); } if (type.IsAssociationType) { IAssociationType actType = (IAssociationType)type; if (actType.UseLHSPrimaryKey) { columns = IdentifierColumnNames; } else { string foreignKeyProperty = actType.LHSPropertyName; if (foreignKeyProperty != null) { //TODO: this requires that the collection is defined after the // referenced property in the mapping file (ok?) if (!columnsByPropertyPath.TryGetValue(foreignKeyProperty, out columns)) { return; //get em on the second pass! } } } } if (path != null) { AddPropertyPath(path, type, columns, formulaTemplates); } if (type.IsComponentType) { IAbstractComponentType actype = (IAbstractComponentType)type; InitComponentPropertyPaths(path, actype, columns, formulaTemplates, factory); if (actype.IsEmbedded) { InitComponentPropertyPaths(path == null ? null : StringHelper.Qualifier(path), actype, columns, formulaTemplates, factory); } } else if (type.IsEntityType) { InitIdentifierPropertyPaths(path, (EntityType)type, columns, factory); } }
public OuterJoinableAssociation(IAssociationType joinableType, String lhsAlias, String[] lhsColumns, String rhsAlias, JoinType joinType, ISessionFactoryImplementor factory, IDictionary <string, IFilter> enabledFilters) { this.joinableType = joinableType; this.lhsAlias = lhsAlias; this.lhsColumns = lhsColumns; this.rhsAlias = rhsAlias; this.joinType = joinType; joinable = joinableType.GetAssociatedJoinable(factory); rhsColumns = JoinHelper.GetRHSColumnNames(joinableType, factory); on = joinableType.GetOnCondition(rhsAlias, factory, enabledFilters); this.enabledFilters = enabledFilters; // needed later for many-to-many/filter application }
/// <summary> /// Asserts that the <see cref="AssociationType"/> and the <see cref="IObject"/> are compatible with /// <see cref="ICompositePredicate#AddEquals"/>. /// </summary> /// <param name="association">The association.</param> /// <param name="allorsObject">The allors object.</param> public static void AssertAssociationEquals(IAssociationType association, IObject allorsObject) { if (!association.IsOne) { throw new ArgumentException( "AddEquals() can only be used when association has multiplicity one, use AssociationContains() instead."); } if (allorsObject == null) { throw new ArgumentException( "AddEquals() requires a non-null contained object, use AddNot().AddExists() instead."); } }
public virtual long[] GetAssociations(Strategy roleStrategy, IAssociationType associationType) { var associationsByRole = this.GetAssociationsByRole(associationType); long[] associations; if (!associationsByRole.TryGetValue(roleStrategy.Reference, out associations)) { this.FlushConditionally(roleStrategy, associationType); associations = this.SessionCommands.GetCompositeAssociationsCommand.Execute(roleStrategy, associationType); associationsByRole[roleStrategy.Reference] = associations; } return(associations); }
public override string SelectFragment(IJoinable rhs, string rhsAlias, string lhsAlias, string collectionSuffix, bool includeCollectionColumns, EntityLoadInfo entityInfo) { // we need to determine the best way to know that two joinables // represent a single many-to-many... if (rhs != null && IsManyToMany && !rhs.IsCollection) { IAssociationType elementType = (IAssociationType)ElementType; if (rhs.Equals(elementType.GetAssociatedJoinable(Factory))) { return(ManyToManySelectFragment(rhs, rhsAlias, lhsAlias, collectionSuffix, elementType)); } } return(includeCollectionColumns ? SelectFragment(lhsAlias, collectionSuffix) : string.Empty); }
/// <summary> /// Get the columns of the associated table which are to /// be used in the join /// </summary> public static string[] GetRHSColumnNames(IAssociationType type, ISessionFactoryImplementor factory) { string uniqueKeyPropertyName = type.RHSUniqueKeyPropertyName; IJoinable joinable = type.GetAssociatedJoinable(factory); if (uniqueKeyPropertyName == null) { return(joinable.JoinColumnNames); } else { return(((IOuterJoinLoadable)joinable).GetPropertyColumnNames(uniqueKeyPropertyName)); } }
public OuterJoinableAssociation(IAssociationType joinableType, String lhsAlias, String[] lhsColumns, String rhsAlias, JoinType joinType, ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) { this.joinableType = joinableType; this.lhsAlias = lhsAlias; this.lhsColumns = lhsColumns; this.rhsAlias = rhsAlias; this.joinType = joinType; joinable = joinableType.GetAssociatedJoinable(factory); rhsColumns = JoinHelper.GetRHSColumnNames(joinableType, factory); on = joinableType.GetOnCondition(rhsAlias, factory, enabledFilters); this.enabledFilters = enabledFilters; // needed later for many-to-many/filter application }
private void WalkEntityAssociationTree(IAssociationType associationType, IOuterJoinLoadable persister, int propertyNumber, string alias, string path, bool nullable, int currentDepth, ILhsAssociationTypeSqlInfo associationTypeSQLInfo) { string[] aliasedLhsColumns = associationTypeSQLInfo.GetAliasedColumnNames(associationType, 0); string[] lhsColumns = associationTypeSQLInfo.GetColumnNames(associationType, 0); string lhsTable = associationTypeSQLInfo.GetTableName(associationType); string subpath = SubPath(path, persister.GetSubclassPropertyName(propertyNumber)); JoinType joinType = GetJoinType(associationType, persister.GetFetchMode(propertyNumber), subpath, lhsTable, lhsColumns, nullable, currentDepth, persister.GetCascadeStyle(propertyNumber)); AddAssociationToJoinTreeIfNecessary(associationType, aliasedLhsColumns, alias, subpath, currentDepth, joinType); }
internal Reference GetAssociation(Strategy roleStrategy, IAssociationType associationType) { var associationByRole = this.State.GetAssociationByRole(associationType); Reference association; if (!associationByRole.TryGetValue(roleStrategy.Reference, out association)) { this.FlushConditionally(roleStrategy.ObjectId, associationType); association = this.Commands.GetCompositeAssociation(roleStrategy.Reference, associationType); associationByRole[roleStrategy.Reference] = association; } return(association); }
public virtual Reference GetAssociation(Strategy roleStrategy, IAssociationType associationType) { var associationByRole = this.GetAssociationByRole(associationType); Reference association; if (!associationByRole.TryGetValue(roleStrategy.Reference, out association)) { this.FlushConditionally(roleStrategy, associationType); association = this.SessionCommands.GetCompositeAssociationCommand.Execute(roleStrategy.Reference, associationType); associationByRole[roleStrategy.Reference] = association; } return(association); }
internal void TriggerFlush(long role, IAssociationType associationType) { if (this.State.TriggersFlushRolesByAssociationType == null) { this.State.TriggersFlushRolesByAssociationType = new Dictionary <IAssociationType, HashSet <long> >(); } if (!this.State.TriggersFlushRolesByAssociationType.TryGetValue(associationType, out var associations)) { associations = new HashSet <long>(); this.State.TriggersFlushRolesByAssociationType[associationType] = associations; } associations.Add(role); }
public OuterJoinableAssociation(IAssociationType joinableType, String lhsAlias, String[] lhsColumns, String rhsAlias, JoinType joinType, SqlString withClause, ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters) { this.joinableType = joinableType; this.lhsAlias = lhsAlias; this.lhsColumns = lhsColumns; this.rhsAlias = rhsAlias; this.joinType = joinType; joinable = joinableType.GetAssociatedJoinable(factory); rhsColumns = JoinHelper.GetRHSColumnNames(joinableType, factory); on = new SqlString(joinableType.GetOnCondition(rhsAlias, factory, enabledFilters)); if (StringHelper.IsNotEmpty(withClause)) on = on.Append(" and ( ").Append(withClause).Append(" )"); this.enabledFilters = enabledFilters; // needed later for many-to-many/filter application }
public bool ExistCompositeAssociations(IAssociationType associationType) { this.AssertNotDeleted(); switch (associationType.RelationType.Multiplicity) { case Multiplicity.ManyToOne: return(this.session.ExistCompositeAssociationsManyToOne(this.objectId, associationType)); case Multiplicity.ManyToMany: return(this.session.ExistCompositeAssociationsManyToMany(this.objectId, associationType)); default: throw new Exception("Unsupported multiplicity " + associationType.RelationType.Multiplicity); } }
public virtual object Replace(object original, object target, ISessionImplementor session, object owner, IDictionary copyCache, ForeignKeyDirection foreignKeyDirection) { bool include; if (IsAssociationType) { IAssociationType atype = (IAssociationType)this; include = atype.ForeignKeyDirection == foreignKeyDirection; } else { include = ForeignKeyDirection.ForeignKeyFromParent.Equals(foreignKeyDirection); } return(include ? Replace(original, target, session, owner, copyCache) : target); }
/// <summary> /// /// </summary> /// <param name="propertyName"></param> /// <param name="propertyType"></param> /// <param name="q"></param> /// <remarks>NOTE: we avoid joining to the next table if the named property is just the foreign key value</remarks> private void DereferenceEntity(string propertyName, EntityType propertyType, QueryTranslator q) { //if its "id" bool isIdShortcut = EntityID.Equals(propertyName) && !propertyType.IsUniqueKeyReference; //or its the id property name string idPropertyName; try { idPropertyName = propertyType.GetIdentifierOrUniqueKeyPropertyName(q.Factory); } catch (MappingException me) { throw new QueryException(me); } bool isNamedIdPropertyShortcut = idPropertyName != null && idPropertyName.Equals(propertyName); if (isIdShortcut || isNamedIdPropertyShortcut) { // special shortcut for id properties, skip the join! // this must only occur at the _end_ of a path expression DereferenceProperty(propertyName); } else { string entityClass = propertyType.GetAssociatedEntityName(); string name = q.CreateNameFor(entityClass); q.AddType(name, entityClass); //String[] keyColNames = memberPersister.getIdentifierColumnNames(); AddJoin(name, propertyType); if (propertyType.IsOneToOne) { oneToOneOwnerName = currentName; } else { oneToOneOwnerName = null; } ownerAssociationType = propertyType; currentName = name; currentProperty = propertyName; q.AddPathAliasAndJoin(path.ToString(0, path.ToString().LastIndexOf(StringHelper.Dot)), name, joinSequence.Copy()); componentPath.Length = 0; currentPropertyMapping = q.GetPersister(entityClass); } }
public static void AssociationExistHasException(IObject allorsObject, IAssociationType associationType) { bool exceptionOccured = false; try { object o = allorsObject.Strategy.GetAssociation(associationType); } catch { exceptionOccured = true; } if (!exceptionOccured) { Assert.Fail("Exist didn't threw an Exception for association " + associationType); } }
public static void AssociationGetHasException(IObject allorsObject, IAssociationType associationType) { bool exceptionOccured = false; try { object o = allorsObject.Strategy.GetAssociation(associationType); } catch { exceptionOccured = true; } if (!exceptionOccured) { Assert.Fail(); } }
/// <summary> /// Should we join this association? /// </summary> protected bool IsJoinable(JoinType joinType, ISet <AssociationKey> visitedAssociationKeys, string lhsTable, string[] lhsColumnNames, IAssociationType type, int depth) { if (joinType < JoinType.InnerJoin) { return(false); } if (joinType == JoinType.InnerJoin) { return(true); } int maxFetchDepth = Factory.Settings.MaximumFetchDepth; bool tooDeep = maxFetchDepth >= 0 && depth >= maxFetchDepth; return(!tooDeep && !IsDuplicateAssociation(lhsTable, lhsColumnNames, type)); }
private void WalkAssociationTree( IAssociationType associationType, IOuterJoinLoadable persister, int propertyNumber, string alias, IList associations, ISet visitedPersisters, string path, int currentDepth, ISessionFactoryImplementor factory) { string[] aliasedForeignKeyColumns = GetAliasedForeignKeyColumns(persister, alias, associationType, persister.ToColumns(alias, propertyNumber)); string[] foreignKeyColumns = GetForeignKeyColumns(persister, associationType, persister.GetSubclassPropertyColumnNames(propertyNumber)); if (IsJoinedFetchAlwaysDisabled(persister, associationType, propertyNumber)) { return; } string subpath = SubPath(path, persister.GetSubclassPropertyName(propertyNumber)); JoinType joinType = GetJoinType( associationType, persister.EnableJoinedFetch(propertyNumber), subpath, persister.GetSubclassPropertyTableName(propertyNumber), foreignKeyColumns, factory ); if (joinType != JoinType.None) { WalkAssociationTree( associationType, aliasedForeignKeyColumns, persister, alias, associations, visitedPersisters, subpath, currentDepth, joinType, factory ); } }
public static void AssociationExistHasException(IObject allorsObject, IAssociationType associationType) { var exceptionOccured = false; try { var o = allorsObject.Strategy.GetAssociation(associationType.RelationType); } catch { exceptionOccured = true; } if (!exceptionOccured) { Assert.True(false, "Exist didn't threw an Exception for association " + associationType); } }
protected override JoinType GetJoinType( IAssociationType type, OuterJoinFetchStrategy config, string path, string table, string[] foreignKeyColumns, ISessionFactoryImplementor factory ) { JoinType joinType = base.GetJoinType(type, config, path, table, foreignKeyColumns, factory); // We can use an inner-join for the many-to-many if (joinType == JoinType.LeftOuterJoin && string.Empty.Equals(path)) { joinType = JoinType.InnerJoin; } return(joinType); }
/// <summary> Cascade an action to the child or children</summary> private void CascadeProperty(object parent, object child, IType type, CascadeStyle style, object anything, bool isCascadeDeleteEnabled) { if (child != null) { if (type.IsAssociationType) { IAssociationType associationType = (IAssociationType)type; if (CascadeAssociationNow(associationType)) { CascadeAssociation(parent, child, type, style, anything, isCascadeDeleteEnabled); } } else if (type.IsComponentType) { CascadeComponent(parent, child, (IAbstractComponentType)type, anything); } } }
public static void AssociationGetHasException(IObject allorsObject, IAssociationType associationType) { var exceptionOccured = false; try { var o = allorsObject.Strategy.GetAssociation(associationType.RelationType); } catch { exceptionOccured = true; } if (!exceptionOccured) { Assert.True(false); // Fail } }
public static void AssociationGetHasException(IObject allorsObject, IAssociationType associationType) { bool exceptionOccured = false; try { object o = allorsObject.Strategy.GetAssociation(associationType.RelationType); } catch { exceptionOccured = true; } if (!exceptionOccured) { Assert.Fail(); } }
public OuterJoinableAssociation(IAssociationType joinableType, String lhsAlias, String[] lhsColumns, String rhsAlias, JoinType joinType, SqlString withClause, ISessionFactoryImplementor factory, IDictionary <string, IFilter> enabledFilters) { this.joinableType = joinableType; this.lhsAlias = lhsAlias; this.lhsColumns = lhsColumns; this.rhsAlias = rhsAlias; this.joinType = joinType; joinable = joinableType.GetAssociatedJoinable(factory); rhsColumns = JoinHelper.GetRHSColumnNames(joinableType, factory); on = new SqlString(joinableType.GetOnCondition(rhsAlias, factory, enabledFilters)); if (SqlStringHelper.IsNotEmpty(withClause)) { on = on.Append(" and ( ").Append(withClause).Append(" )"); } this.enabledFilters = enabledFilters; // needed later for many-to-many/filter application }
public string[] GetAliasedColumnNames(IAssociationType type, int begin) { if (type.UseLHSPrimaryKey) { return StringHelper.Qualify(Alias, Persister.IdentifierColumnNames); } else { string propertyName = type.LHSPropertyName; if (propertyName == null) { return ArrayHelper.Slice(GetAliasedColumns(), begin, type.GetColumnSpan(Mapping)); } else { return ((IPropertyMapping)Persister).ToColumns(Alias, propertyName); //bad cast } } }
public ObjectId[] ExtentGetCompositeAssociations(IAssociationType associationType) { ObjectId[] associations; switch (associationType.RelationType.Multiplicity) { case Multiplicity.ManyToOne: associations = this.session.GetCompositeAssociationsManyToOne(this.objectId, associationType); break; case Multiplicity.ManyToMany: associations = this.session.GetCompositeAssociationsManyToMany(this.objectId, associationType); break; default: throw new Exception("Unsupported multiplicity " + associationType.RelationType.Multiplicity); } return(associations); }
public string[] GetAliasedColumnNames(IAssociationType type, int begin) { if (type.UseLHSPrimaryKey) { return(StringHelper.Qualify(Alias, Persister.IdentifierColumnNames)); } else { string propertyName = type.LHSPropertyName; if (propertyName == null) { return(ArrayHelper.Slice(GetAliasedColumns(), begin, type.GetColumnSpan(Mapping))); } else { return(((IPropertyMapping)Persister).ToColumns(Alias, propertyName)); //bad cast } } }
private Persister.Entity.IJoinable GetPathJoinable(string path) { NHibernate_Persister_Entity.IJoinable last = (NHibernate_Persister_Entity.IJoinable)Factory.GetEntityPersister(rootEntityName); NHibernate_Persister_Entity.IPropertyMapping lastEntity = (NHibernate_Persister_Entity.IPropertyMapping)last; string componentPath = ""; StringTokenizer tokens = new StringTokenizer(path, ".", false); foreach (string token in tokens) { componentPath += token; IType type = lastEntity.ToType(componentPath); if (type.IsAssociationType) { if (type.IsCollectionType) { // ignore joinables for composite collections var collectionType = (CollectionType)type; var persister = Factory.GetCollectionPersister(collectionType.Role); if (persister.ElementType.IsEntityType == false) { return(null); } } IAssociationType atype = (IAssociationType)type; last = atype.GetAssociatedJoinable(Factory); lastEntity = (NHibernate_Persister_Entity.IPropertyMapping)Factory.GetEntityPersister(atype.GetAssociatedEntityName(Factory)); componentPath = ""; } else if (type.IsComponentType) { componentPath += '.'; } else { throw new QueryException("not an association: " + componentPath); } } return(last); }
/// <summary> /// Should we join this association? /// </summary> protected bool IsJoinable(JoinType joinType, ISet<AssociationKey> visitedAssociationKeys, string lhsTable, string[] lhsColumnNames, IAssociationType type, int depth) { if (joinType < JoinType.InnerJoin) return false; if (joinType == JoinType.InnerJoin) return true; int maxFetchDepth = Factory.Settings.MaximumFetchDepth; bool tooDeep = maxFetchDepth >= 0 && depth >= maxFetchDepth; return !tooDeep && !IsDuplicateAssociation(lhsTable, lhsColumnNames, type); }
/// <summary> /// Used to detect circularities in the joined graph, note that /// this method is side-effecty /// </summary> protected virtual bool IsDuplicateAssociation(string lhsTable, string[] lhsColumnNames, IAssociationType type) { string foreignKeyTable; string[] foreignKeyColumns; if (type.ForeignKeyDirection.Equals(ForeignKeyDirection.ForeignKeyFromParent)) { foreignKeyTable = lhsTable; foreignKeyColumns = lhsColumnNames; } else { foreignKeyTable = type.GetAssociatedJoinable(Factory).TableName; foreignKeyColumns = JoinHelper.GetRHSColumnNames(type, Factory); } return IsDuplicateAssociation(foreignKeyTable, foreignKeyColumns); }