private void CreateConstraintsForForeignKeyAssociationsAffectingThisWrapper( FragmentQueryKB rightKB, MemberDomainMap rightDomainMap) { foreach (AssociationSet assocSet in new ViewgenContext.OneToOneFkAssociationsForEntitiesFilter().Filter((IList <EntityType>) this.m_cellWrappers.Select <LeftCellWrapper, EntitySetBase>((Func <LeftCellWrapper, EntitySetBase>)(it => it.RightExtent)).OfType <EntitySet>().Select <EntitySet, EntityType>((Func <EntitySet, EntityType>)(it => it.ElementType)).ToList <EntityType>(), this.m_entityContainerMapping.EdmEntityContainer.BaseEntitySets.OfType <AssociationSet>())) { rightKB.CreateEquivalenceConstraintForOneToOneForeignKeyAssociation(assocSet, rightDomainMap); } }
/// <summary> /// Find the Foreign Key Associations that relate EntitySets used in these left cell wrappers and /// add any equivalence facts between sets implied by 1:1 associations. /// We can collect other implication facts but we don't have a scenario that needs them( yet ). /// </summary> private void CreateConstraintsForForeignKeyAssociationsAffectingThisWrapper( FragmentQueryKB rightKB, MemberDomainMap rightDomainMap) { var oneToOneForeignKeyAssociationSetsForThisWrapper = new OneToOneFkAssociationsForEntitiesFilter() .Filter( m_cellWrappers.Select(it => it.RightExtent).OfType <EntitySet>().Select(it => it.ElementType).ToList(), m_entityContainerMapping.EdmEntityContainer.BaseEntitySets.OfType <AssociationSet>()); // Collect the facts for the foreign key association sets that are 1:1 and affecting this wrapper foreach (var assocSet in oneToOneForeignKeyAssociationSetsForThisWrapper) { rightKB.CreateEquivalenceConstraintForOneToOneForeignKeyAssociation(assocSet, rightDomainMap); } }
/// <summary> /// Find the Foreign Key Associations that relate EntitySets used in these left cell wrappers and /// add any equivalence facts between sets implied by 1:1 associations. /// We can collect other implication facts but we don't have a scenario that needs them( yet ). /// </summary> /// <param name="rightKB"></param> /// <param name="rightDomainMap"></param> private void CreateConstraintsForForeignKeyAssociationsAffectingThisWarapper(FragmentQueryKB rightKB, MemberDomainMap rightDomainMap) { //First find the entity types of the sets in these cell wrappers. var entityTypes = m_cellWrappers.Select(it => it.RightExtent).OfType <EntitySet>().Select(it => it.ElementType); //Get all the foreign key association sets in these entity sets var allForeignKeyAssociationSets = this.m_entityContainerMapping.EdmEntityContainer.BaseEntitySets.OfType <AssociationSet>().Where(it => it.ElementType.IsForeignKey); //Find all the foreign key associations that have corresponding sets var oneToOneForeignKeyAssociationsForThisWrapper = allForeignKeyAssociationSets.Select(it => it.ElementType); //Find all the 1:1 associations from the above list oneToOneForeignKeyAssociationsForThisWrapper = oneToOneForeignKeyAssociationsForThisWrapper.Where(it => (it.AssociationEndMembers.All(endMember => endMember.RelationshipMultiplicity == RelationshipMultiplicity.One))); //Filter the 1:1 foreign key associations to the ones relating the sets used in these cell wrappers. oneToOneForeignKeyAssociationsForThisWrapper = oneToOneForeignKeyAssociationsForThisWrapper.Where(it => (it.AssociationEndMembers.All(endMember => entityTypes.Contains(endMember.GetEntityType())))); //filter foreign key association sets to the sets that are 1:1 and affecting this wrapper. var oneToOneForeignKeyAssociationSetsForThisWrapper = allForeignKeyAssociationSets.Where(it => oneToOneForeignKeyAssociationsForThisWrapper.Contains(it.ElementType)); //Collect the facts for the foreign key association sets that are 1:1 and affecting this wrapper foreach (var assocSet in oneToOneForeignKeyAssociationSetsForThisWrapper) { rightKB.CreateEquivalenceConstraintForOneToOneForeignKeyAssociation(assocSet, rightDomainMap, m_edmItemCollection); } }
// <summary> // Find the Foreign Key Associations that relate EntitySets used in these left cell wrappers and // add any equivalence facts between sets implied by 1:1 associations. // We can collect other implication facts but we don't have a scenario that needs them( yet ). // </summary> private void CreateConstraintsForForeignKeyAssociationsAffectingThisWrapper( FragmentQueryKB rightKB, MemberDomainMap rightDomainMap) { var oneToOneForeignKeyAssociationSetsForThisWrapper = new OneToOneFkAssociationsForEntitiesFilter() .Filter( m_cellWrappers.Select(it => it.RightExtent).OfType<EntitySet>().Select(it => it.ElementType).ToList(), m_entityContainerMapping.EdmEntityContainer.BaseEntitySets.OfType<AssociationSet>()); // Collect the facts for the foreign key association sets that are 1:1 and affecting this wrapper foreach (var assocSet in oneToOneForeignKeyAssociationSetsForThisWrapper) { rightKB.CreateEquivalenceConstraintForOneToOneForeignKeyAssociation(assocSet, rightDomainMap); } }
internal ViewgenContext(ViewTarget viewTarget, EntitySetBase extent, IEnumerable<Cell> extentCells, CqlIdentifiers identifiers, ConfigViewGenerator config, MemberDomainMap queryDomainMap, MemberDomainMap updateDomainMap, StorageEntityContainerMapping entityContainerMapping) { foreach (Cell cell in extentCells) { Debug.Assert(extent.Equals(cell.GetLeftQuery(viewTarget).Extent)); Debug.Assert(cell.CQuery.NumProjectedSlots == cell.SQuery.NumProjectedSlots); } m_extent = extent; m_viewTarget = viewTarget; m_config = config; m_edmItemCollection = entityContainerMapping.StorageMappingItemCollection.EdmItemCollection; m_entityContainerMapping = entityContainerMapping; m_identifiers = identifiers; // create a copy of updateDomainMap so generation of query views later on is not affected // it is modified in QueryRewriter.AdjustMemberDomainsForUpdateViews updateDomainMap = updateDomainMap.MakeCopy(); // Create a signature generator that handles all the // multiconstant work and generating the signatures MemberDomainMap domainMap = viewTarget == ViewTarget.QueryView ? queryDomainMap : updateDomainMap; m_memberMaps = new MemberMaps(viewTarget, MemberProjectionIndex.Create(extent, m_edmItemCollection), queryDomainMap, updateDomainMap); // Create left fragment KB: includes constraints for the extent to be constructed FragmentQueryKB leftKB = new FragmentQueryKB(); leftKB.CreateVariableConstraints(extent, domainMap, m_edmItemCollection); m_leftFragmentQP = new FragmentQueryProcessor(leftKB); m_rewritingCache = new Dictionary<FragmentQuery, Tile<FragmentQuery>>( FragmentQuery.GetEqualityComparer(m_leftFragmentQP)); // Now using the signatures, create new cells such that // "extent's" query (C or S) is described in terms of multiconstants if (!CreateLeftCellWrappers(extentCells, viewTarget)) { return; } // Create right fragment KB: includes constraints for all extents and association roles of right queries FragmentQueryKB rightKB = new FragmentQueryKB(); MemberDomainMap rightDomainMap = viewTarget == ViewTarget.QueryView ? updateDomainMap : queryDomainMap; foreach (LeftCellWrapper leftCellWrapper in m_cellWrappers) { EntitySetBase rightExtent = leftCellWrapper.RightExtent; rightKB.CreateVariableConstraints(rightExtent, rightDomainMap, m_edmItemCollection); rightKB.CreateAssociationConstraints(rightExtent, rightDomainMap, m_edmItemCollection); } if (m_viewTarget == ViewTarget.UpdateView) { CreateConstraintsForForeignKeyAssociationsAffectingThisWarapper(rightKB, rightDomainMap); } m_rightFragmentQP = new FragmentQueryProcessor(rightKB); // Check for concurrency control tokens if (m_viewTarget == ViewTarget.QueryView) { CheckConcurrencyControlTokens(); } // For backward compatibility - // order wrappers by increasing domain size, decreasing number of attributes m_cellWrappers.Sort(LeftCellWrapper.Comparer); }
/// <summary> /// Find the Foreign Key Associations that relate EntitySets used in these left cell wrappers and /// add any equivalence facts between sets implied by 1:1 associations. /// We can collect other implication facts but we don't have a scenario that needs them( yet ). /// </summary> /// <param name="rightKB"></param> /// <param name="rightDomainMap"></param> private void CreateConstraintsForForeignKeyAssociationsAffectingThisWarapper(FragmentQueryKB rightKB, MemberDomainMap rightDomainMap) { //First find the entity types of the sets in these cell wrappers. var entityTypes = m_cellWrappers.Select(it => it.RightExtent).OfType<EntitySet>().Select(it => it.ElementType); //Get all the foreign key association sets in these entity sets var allForeignKeyAssociationSets = this.m_entityContainerMapping.EdmEntityContainer.BaseEntitySets.OfType<AssociationSet>().Where(it => it.ElementType.IsForeignKey); //Find all the foreign key associations that have corresponding sets var oneToOneForeignKeyAssociationsForThisWrapper = allForeignKeyAssociationSets.Select(it => it.ElementType); //Find all the 1:1 associations from the above list oneToOneForeignKeyAssociationsForThisWrapper = oneToOneForeignKeyAssociationsForThisWrapper.Where(it => (it.AssociationEndMembers.All(endMember => endMember.RelationshipMultiplicity == RelationshipMultiplicity.One))); //Filter the 1:1 foreign key associations to the ones relating the sets used in these cell wrappers. oneToOneForeignKeyAssociationsForThisWrapper = oneToOneForeignKeyAssociationsForThisWrapper.Where(it => (it.AssociationEndMembers.All(endMember => entityTypes.Contains(endMember.GetEntityType())))); //filter foreign key association sets to the sets that are 1:1 and affecting this wrapper. var oneToOneForeignKeyAssociationSetsForThisWrapper = allForeignKeyAssociationSets.Where(it => oneToOneForeignKeyAssociationsForThisWrapper.Contains(it.ElementType)); //Collect the facts for the foreign key association sets that are 1:1 and affecting this wrapper foreach (var assocSet in oneToOneForeignKeyAssociationSetsForThisWrapper) { rightKB.CreateEquivalenceConstraintForOneToOneForeignKeyAssociation(assocSet, rightDomainMap, m_edmItemCollection); } }
internal ViewgenContext(ViewTarget viewTarget, EntitySetBase extent, IEnumerable <Cell> extentCells, CqlIdentifiers identifiers, ConfigViewGenerator config, MemberDomainMap queryDomainMap, MemberDomainMap updateDomainMap, StorageEntityContainerMapping entityContainerMapping) { foreach (Cell cell in extentCells) { Debug.Assert(extent.Equals(cell.GetLeftQuery(viewTarget).Extent)); Debug.Assert(cell.CQuery.NumProjectedSlots == cell.SQuery.NumProjectedSlots); } m_extent = extent; m_viewTarget = viewTarget; m_config = config; m_edmItemCollection = entityContainerMapping.StorageMappingItemCollection.EdmItemCollection; m_entityContainerMapping = entityContainerMapping; m_identifiers = identifiers; // create a copy of updateDomainMap so generation of query views later on is not affected // it is modified in QueryRewriter.AdjustMemberDomainsForUpdateViews updateDomainMap = updateDomainMap.MakeCopy(); // Create a signature generator that handles all the // multiconstant work and generating the signatures MemberDomainMap domainMap = viewTarget == ViewTarget.QueryView ? queryDomainMap : updateDomainMap; m_memberMaps = new MemberMaps(viewTarget, MemberProjectionIndex.Create(extent, m_edmItemCollection), queryDomainMap, updateDomainMap); // Create left fragment KB: includes constraints for the extent to be constructed FragmentQueryKB leftKB = new FragmentQueryKB(); leftKB.CreateVariableConstraints(extent, domainMap, m_edmItemCollection); m_leftFragmentQP = new FragmentQueryProcessor(leftKB); m_rewritingCache = new Dictionary <FragmentQuery, Tile <FragmentQuery> >( FragmentQuery.GetEqualityComparer(m_leftFragmentQP)); // Now using the signatures, create new cells such that // "extent's" query (C or S) is described in terms of multiconstants if (!CreateLeftCellWrappers(extentCells, viewTarget)) { return; } // Create right fragment KB: includes constraints for all extents and association roles of right queries FragmentQueryKB rightKB = new FragmentQueryKB(); MemberDomainMap rightDomainMap = viewTarget == ViewTarget.QueryView ? updateDomainMap : queryDomainMap; foreach (LeftCellWrapper leftCellWrapper in m_cellWrappers) { EntitySetBase rightExtent = leftCellWrapper.RightExtent; rightKB.CreateVariableConstraints(rightExtent, rightDomainMap, m_edmItemCollection); rightKB.CreateAssociationConstraints(rightExtent, rightDomainMap, m_edmItemCollection); } if (m_viewTarget == ViewTarget.UpdateView) { CreateConstraintsForForeignKeyAssociationsAffectingThisWarapper(rightKB, rightDomainMap); } m_rightFragmentQP = new FragmentQueryProcessor(rightKB); // Check for concurrency control tokens if (m_viewTarget == ViewTarget.QueryView) { CheckConcurrencyControlTokens(); } // For backward compatibility - // order wrappers by increasing domain size, decreasing number of attributes m_cellWrappers.Sort(LeftCellWrapper.Comparer); }