internal void RemoveCompositeRole(IRoleType roleType, Strategy role) { CompositesRole compositesRole; if (this.ModifiedRolesByRoleType == null || !this.ModifiedRolesByRoleType.TryGetValue(roleType, out compositesRole)) { compositesRole = new CompositesRole(this.GetCompositesRole(roleType)); this.ModifiedRolesByRoleType[roleType] = compositesRole; } if (compositesRole.Contains(role.ObjectId)) { this.ChangeSet.OnChangingCompositesRole(this, roleType, role); compositesRole.Remove(role.ObjectId); if (roleType.AssociationType.IsOne) { this.Reference.Session.SetAssociation(null, role, roleType.AssociationType); } else { this.Reference.Session.RemoveAssociation(this.Reference, role.Reference, roleType.AssociationType); this.Reference.Session.TriggerFlush(role.ObjectId, roleType.AssociationType); } this.AddRequiresFlushRoleType(roleType); this.Reference.Session.RequireFlush(this.Reference, this); } }
internal void SetCompositeRole(IRoleType roleType, Strategy newRoleStrategy) { var previousRole = this.GetCompositeRole(roleType); var newRole = newRoleStrategy == null ? null : newRoleStrategy.Reference.ObjectId; this.ChangeSet.OnChangingCompositeRole(this, roleType, previousRole, newRole); if (newRole != null && !newRole.Equals(previousRole)) { if (roleType.AssociationType.IsOne) { if (previousRole != null) { var previousRoleStrategy = this.Reference.Session.GetOrCreateReferenceForExistingObject(previousRole).Strategy; var previousAssociation = previousRoleStrategy.GetCompositeAssociation(roleType.AssociationType); if (previousAssociation != null) { previousAssociation.Strategy.RemoveCompositeRole(roleType); } } var newRoleAssociation = newRoleStrategy.GetCompositeAssociation(roleType.AssociationType); if (newRoleAssociation != null && !newRoleAssociation.Id.Equals(this.Reference.ObjectId)) { newRoleAssociation.Strategy.RemoveCompositeRole(roleType); } this.Reference.Session.SetAssociation(this.Reference, newRoleStrategy, roleType.AssociationType); } else { if (previousRole != null) { var previousRoleReference = this.Reference.Session.GetOrCreateReferenceForExistingObject(previousRole); this.Reference.Session.RemoveAssociation(this.Reference, previousRoleReference, roleType.AssociationType); } } } if (previousRole != null && !previousRole.Equals(newRole)) { this.Reference.Session.TriggerFlush(previousRole, roleType.AssociationType); } if ((newRole == null && previousRole != null) || (newRole != null && !newRole.Equals(previousRole))) { this.SetOriginal(roleType, newRole); this.ModifiedRoleByRoleType[roleType] = newRole; this.AddRequiresFlushRoleType(roleType); this.Reference.Session.RequireFlush(this.Reference, this); if (newRole != null) { if (roleType.AssociationType.IsMany) { this.Reference.Session.AddAssociation(this.Reference, newRoleStrategy.Reference, roleType.AssociationType); this.Reference.Session.TriggerFlush(newRole, roleType.AssociationType); } } } }
internal ExtentAssociations(Strategy strategy, IAssociationType associationType) { this.strategy = strategy; this.associationType = associationType; }
internal void AddCompositeRole(IRoleType roleType, Strategy role) { CompositesRole compositesRole; if (this.ModifiedRolesByRoleType == null || !this.ModifiedRolesByRoleType.TryGetValue(roleType, out compositesRole)) { compositesRole = new CompositesRole(this.GetCompositesRole(roleType)); this.ModifiedRolesByRoleType[roleType] = compositesRole; } this.ChangeSet.OnChangingCompositesRole(this, roleType, role); if (!compositesRole.Contains(role.ObjectId)) { compositesRole.Add(role.ObjectId); if (roleType.AssociationType.IsOne) { var previousAssociationObject = role.GetCompositeAssociation(roleType.AssociationType); var previousAssociation = previousAssociationObject != null ? (Strategy)previousAssociationObject.Strategy : null; if (previousAssociation != null && !previousAssociation.ObjectId.Equals(this.Reference.ObjectId)) { previousAssociation.RemoveCompositeRole(roleType, role.GetObject()); } this.Reference.Session.SetAssociation(this.Reference, role, roleType.AssociationType); } else { this.Reference.Session.AddAssociation(this.Reference, role.Reference, roleType.AssociationType); this.Reference.Session.TriggerFlush(role.ObjectId, roleType.AssociationType); } this.AddRequiresFlushRoleType(roleType); this.Reference.Session.RequireFlush(this.Reference, this); } }
internal ExtentFiltered(Session session, Strategy strategy, IAssociationType associationType) : this(session, associationType.ObjectType) { this.Strategy = strategy; this.AssociationType = associationType; }
internal ExtentFiltered(Session session, Strategy strategy, IRoleType roleType) : this(session, (IComposite)roleType.ObjectType) { this.Strategy = strategy; this.RoleType = roleType; }
/// <summary> /// Lazy loads the filter. /// Should also be used to upgrade from a strategy extent to a full extent /// </summary> protected override void LazyLoadFilter() { if (this.filter == null) { this.filter = new AndPredicate(this); this.Strategy = null; this.AssociationType = null; this.RoleType = null; this.FlushCache(); } }
internal void OnChangingCompositesRole(Roles association, IRoleType roleType, Strategy changedRole) { this.associations.Add(association.Reference.ObjectId); if (changedRole != null) { this.roles.Add(changedRole.ObjectId); } this.RoleTypes(association.Reference.ObjectId).Add(roleType); }
internal ExtentRoles(Strategy strategy, IRoleType roleType) { this.strategy = strategy; this.roleType = roleType; }