Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Map / ViewGeneration / Validation / BasicCellRelation.cs / 1 / BasicCellRelation.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.Bharani1729
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Collections.Generic;
using System.Data.Mapping.ViewGeneration.Structures;
using System.Text;
using System.Diagnostics;
using System.Data.Common.Utils;
using System.Data.Metadata.Edm;
namespace System.Data.Mapping.ViewGeneration.Validation {
using BasicSchemaConstraints = SchemaConstraints;
// This class represents a relation signature that lists all scalar
// slots for the join tree in cell query (before projection)
internal class BasicCellRelation : CellRelation {
#region Constructor
// effects: Creates a basic cell relation for query
internal BasicCellRelation(CellQuery cellQuery, ViewCellRelation viewCellRelation,
IEnumerable slots) : base(viewCellRelation.CellNumber) {
m_cellQuery = cellQuery;
m_slots = new List(slots);
Debug.Assert(m_slots.Count > 0, "Cell relation with not even an exent?");
m_viewCellRelation = viewCellRelation;
}
#endregion
#region Fields
private CellQuery m_cellQuery;
private List m_slots;
private ViewCellRelation m_viewCellRelation; // The viewcellrelation
// corresponding to this basiccellrelation
#endregion
#region Properties
internal ViewCellRelation ViewCellRelation {
get { return m_viewCellRelation;}
}
#endregion
#region Key Constraints Methods
// effects: Modifies constraints to contain the key constraints that
// are present in this relation
internal void PopulateKeyConstraints(BasicSchemaConstraints constraints, MetadataWorkspace workspace) {
Debug.Assert(this == m_cellQuery.BasicCellRelation, "Cellquery does not point to the correct BasicCellRelation?");
Debug.Assert(m_cellQuery.Extent is EntitySet || m_cellQuery.Extent is AssociationSet,
"Top level extents handled is currently entityset or association set");
if (m_cellQuery.Extent is EntitySet) {
PopulateKeyConstraintsForEntitySet(constraints, workspace);
} else {
PopulateKeyConstraintsForRelationshipSet(constraints, workspace);
}
}
// requires: this to correspond to a cell relation for an entityset (m_cellQuery.Extent)
// effects: Adds any key constraints present in this to constraints
private void PopulateKeyConstraintsForEntitySet(BasicSchemaConstraints constraints, MetadataWorkspace workspace) {
MemberPath prefix = new MemberPath(m_cellQuery.Extent, workspace);
EntityType entityType = (EntityType) m_cellQuery.Extent.ElementType;
// Get all the keys for the entity type and create the key constraints
List keys = ExtentKey.GetKeysForEntityType(prefix, entityType);
AddKeyConstraints(keys, constraints);
}
// requires: this to correspond to a cell relation for an association set (m_cellQuery.Extent)
// effects: Adds any key constraints present in this relation in
// constraints
private void PopulateKeyConstraintsForRelationshipSet(BasicSchemaConstraints constraints, MetadataWorkspace workspace) {
AssociationSet relationshipSet = m_cellQuery.Extent as AssociationSet;
// Gather all members of all keys
// CHANGE_[....]_FEATURE_KEYS: assume that an Entity has exactly one key. Otherwise we
// have to take a cross-product of all keys
// Keep track of all the key members for the association in a set
// so that if no end corresponds to a key, we use all the members
// to form the key
Set associationKeyMembers = new Set(MemberPath.EqualityComparer);
bool hasAnEndThatFormsKey = false;
// Determine the keys of each end. If the end forms a key, add it
// as a key to the set
foreach (AssociationSetEnd end in relationshipSet.AssociationSetEnds) {
AssociationEndMember endMember = end.CorrespondingAssociationEndMember;
MemberPath prefix = new MemberPath(relationshipSet, endMember, workspace);
List keys = ExtentKey.GetKeysForEntityType(prefix, end.EntitySet.ElementType);
Debug.Assert(keys.Count > 0, "No keys for entity?");
Debug.Assert(keys.Count == 1, "Currently, we only support primary keys");
if (MetadataHelper.DoesEndFormKey(relationshipSet, endMember)) {
// This end has is a key end
AddKeyConstraints(keys, constraints);
hasAnEndThatFormsKey = true;
}
// Add the members of the (only) key to associationKey
associationKeyMembers.AddRange(keys[0].KeyFields);
}
// If an end forms a key then that key implies the full key
if (false == hasAnEndThatFormsKey) {
// No end is a key -- take all the end members and make a key
// based on that
ExtentKey key = new ExtentKey(associationKeyMembers);
ExtentKey[] keys = new ExtentKey[] { key };
AddKeyConstraints(keys, constraints);
}
}
// effects: Given keys for this relation, adds one key constraint for
// each key present in keys
private void AddKeyConstraints(IEnumerable keys, BasicSchemaConstraints constraints) {
foreach (ExtentKey key in keys) {
// If the key is being projected, only then do we add the key constraint
List keySlots = JoinTreeSlot.GetSlots(m_slots, key.KeyFields);
if (keySlots != null) {
BasicKeyConstraint keyConstraint = new BasicKeyConstraint(this, keySlots);
constraints.Add(keyConstraint);
}
}
}
#endregion
#region Comparer/String Methods
protected override int GetHash() {
// Note: Using CLR-Hashcode
return m_cellQuery.GetHashCode();
// We need not hash the slots, etc - cellQuery should give us enough
// differentiation and land the relation into the same bucket
}
internal override void ToCompactString(StringBuilder builder) {
builder.Append("BasicRel: ");
// Just print the extent name from slot 0
StringUtil.FormatStringBuilder(builder, "{0}", m_slots[0]);
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.Bharani1729
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System.Collections.Generic;
using System.Data.Mapping.ViewGeneration.Structures;
using System.Text;
using System.Diagnostics;
using System.Data.Common.Utils;
using System.Data.Metadata.Edm;
namespace System.Data.Mapping.ViewGeneration.Validation {
using BasicSchemaConstraints = SchemaConstraints;
// This class represents a relation signature that lists all scalar
// slots for the join tree in cell query (before projection)
internal class BasicCellRelation : CellRelation {
#region Constructor
// effects: Creates a basic cell relation for query
internal BasicCellRelation(CellQuery cellQuery, ViewCellRelation viewCellRelation,
IEnumerable slots) : base(viewCellRelation.CellNumber) {
m_cellQuery = cellQuery;
m_slots = new List(slots);
Debug.Assert(m_slots.Count > 0, "Cell relation with not even an exent?");
m_viewCellRelation = viewCellRelation;
}
#endregion
#region Fields
private CellQuery m_cellQuery;
private List m_slots;
private ViewCellRelation m_viewCellRelation; // The viewcellrelation
// corresponding to this basiccellrelation
#endregion
#region Properties
internal ViewCellRelation ViewCellRelation {
get { return m_viewCellRelation;}
}
#endregion
#region Key Constraints Methods
// effects: Modifies constraints to contain the key constraints that
// are present in this relation
internal void PopulateKeyConstraints(BasicSchemaConstraints constraints, MetadataWorkspace workspace) {
Debug.Assert(this == m_cellQuery.BasicCellRelation, "Cellquery does not point to the correct BasicCellRelation?");
Debug.Assert(m_cellQuery.Extent is EntitySet || m_cellQuery.Extent is AssociationSet,
"Top level extents handled is currently entityset or association set");
if (m_cellQuery.Extent is EntitySet) {
PopulateKeyConstraintsForEntitySet(constraints, workspace);
} else {
PopulateKeyConstraintsForRelationshipSet(constraints, workspace);
}
}
// requires: this to correspond to a cell relation for an entityset (m_cellQuery.Extent)
// effects: Adds any key constraints present in this to constraints
private void PopulateKeyConstraintsForEntitySet(BasicSchemaConstraints constraints, MetadataWorkspace workspace) {
MemberPath prefix = new MemberPath(m_cellQuery.Extent, workspace);
EntityType entityType = (EntityType) m_cellQuery.Extent.ElementType;
// Get all the keys for the entity type and create the key constraints
List keys = ExtentKey.GetKeysForEntityType(prefix, entityType);
AddKeyConstraints(keys, constraints);
}
// requires: this to correspond to a cell relation for an association set (m_cellQuery.Extent)
// effects: Adds any key constraints present in this relation in
// constraints
private void PopulateKeyConstraintsForRelationshipSet(BasicSchemaConstraints constraints, MetadataWorkspace workspace) {
AssociationSet relationshipSet = m_cellQuery.Extent as AssociationSet;
// Gather all members of all keys
// CHANGE_[....]_FEATURE_KEYS: assume that an Entity has exactly one key. Otherwise we
// have to take a cross-product of all keys
// Keep track of all the key members for the association in a set
// so that if no end corresponds to a key, we use all the members
// to form the key
Set associationKeyMembers = new Set(MemberPath.EqualityComparer);
bool hasAnEndThatFormsKey = false;
// Determine the keys of each end. If the end forms a key, add it
// as a key to the set
foreach (AssociationSetEnd end in relationshipSet.AssociationSetEnds) {
AssociationEndMember endMember = end.CorrespondingAssociationEndMember;
MemberPath prefix = new MemberPath(relationshipSet, endMember, workspace);
List keys = ExtentKey.GetKeysForEntityType(prefix, end.EntitySet.ElementType);
Debug.Assert(keys.Count > 0, "No keys for entity?");
Debug.Assert(keys.Count == 1, "Currently, we only support primary keys");
if (MetadataHelper.DoesEndFormKey(relationshipSet, endMember)) {
// This end has is a key end
AddKeyConstraints(keys, constraints);
hasAnEndThatFormsKey = true;
}
// Add the members of the (only) key to associationKey
associationKeyMembers.AddRange(keys[0].KeyFields);
}
// If an end forms a key then that key implies the full key
if (false == hasAnEndThatFormsKey) {
// No end is a key -- take all the end members and make a key
// based on that
ExtentKey key = new ExtentKey(associationKeyMembers);
ExtentKey[] keys = new ExtentKey[] { key };
AddKeyConstraints(keys, constraints);
}
}
// effects: Given keys for this relation, adds one key constraint for
// each key present in keys
private void AddKeyConstraints(IEnumerable keys, BasicSchemaConstraints constraints) {
foreach (ExtentKey key in keys) {
// If the key is being projected, only then do we add the key constraint
List keySlots = JoinTreeSlot.GetSlots(m_slots, key.KeyFields);
if (keySlots != null) {
BasicKeyConstraint keyConstraint = new BasicKeyConstraint(this, keySlots);
constraints.Add(keyConstraint);
}
}
}
#endregion
#region Comparer/String Methods
protected override int GetHash() {
// Note: Using CLR-Hashcode
return m_cellQuery.GetHashCode();
// We need not hash the slots, etc - cellQuery should give us enough
// differentiation and land the relation into the same bucket
}
internal override void ToCompactString(StringBuilder builder) {
builder.Append("BasicRel: ");
// Just print the extent name from slot 0
StringUtil.FormatStringBuilder(builder, "{0}", m_slots[0]);
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ComPlusServiceLoader.cs
- AudioFormatConverter.cs
- ReachSerializationCacheItems.cs
- SignedInfo.cs
- TransformerTypeCollection.cs
- HtmlTableRowCollection.cs
- ContentFileHelper.cs
- IndexedDataBuffer.cs
- XmlReaderSettings.cs
- Page.cs
- ResolveDuplexCD1AsyncResult.cs
- DelegateSerializationHolder.cs
- WorkflowOwnershipException.cs
- SingleAnimationUsingKeyFrames.cs
- Splitter.cs
- DrawingCollection.cs
- CustomTrackingRecord.cs
- MimeTypePropertyAttribute.cs
- ResolveDuplexAsyncResult.cs
- RSAOAEPKeyExchangeDeformatter.cs
- ToolConsole.cs
- TextSerializer.cs
- SerializationAttributes.cs
- RegexCode.cs
- WorkflowStateRollbackService.cs
- ThumbAutomationPeer.cs
- CommandValueSerializer.cs
- Substitution.cs
- Process.cs
- MemberNameValidator.cs
- SqlBulkCopy.cs
- AddingNewEventArgs.cs
- ExtendedProtectionPolicyTypeConverter.cs
- ConnectionStringSettings.cs
- SingleConverter.cs
- SqlUserDefinedTypeAttribute.cs
- TextContainerChangeEventArgs.cs
- TraceSource.cs
- NumberFormatInfo.cs
- HttpDictionary.cs
- MappingException.cs
- TemplateControlCodeDomTreeGenerator.cs
- AsyncPostBackTrigger.cs
- QueryGenerator.cs
- StorageModelBuildProvider.cs
- TypeDependencyAttribute.cs
- URLString.cs
- ConnectionsZone.cs
- ReflectionUtil.cs
- DiscoveryRequestHandler.cs
- SecureStringHasher.cs
- TCEAdapterGenerator.cs
- Matrix.cs
- ProfileInfo.cs
- XmlSchemaExternal.cs
- StreamProxy.cs
- Brush.cs
- WindowsToolbarItemAsMenuItem.cs
- OleDbParameter.cs
- BufferModeSettings.cs
- DataGridColumnEventArgs.cs
- CompositeScriptReference.cs
- ReferencedAssembly.cs
- AccessKeyManager.cs
- PathFigureCollectionConverter.cs
- BatchServiceHost.cs
- WindowsNonControl.cs
- XmlElementList.cs
- SpeechEvent.cs
- SiteMapDataSourceDesigner.cs
- XmlReaderSettings.cs
- XmlSerializationReader.cs
- SamlSecurityToken.cs
- NumericUpDownAccelerationCollection.cs
- AnnotationHelper.cs
- TypePropertyEditor.cs
- AnchoredBlock.cs
- AddInIpcChannel.cs
- ConnectionManager.cs
- GuidelineSet.cs
- BaseServiceProvider.cs
- Delegate.cs
- BaseProcessor.cs
- FileLevelControlBuilderAttribute.cs
- XmlBinaryReader.cs
- TimeSpanOrInfiniteConverter.cs
- XmlSchemaProviderAttribute.cs
- TemplateBindingExtensionConverter.cs
- RelOps.cs
- StylusButton.cs
- XmlNamedNodeMap.cs
- ClassHandlersStore.cs
- EraserBehavior.cs
- ScriptResourceHandler.cs
- X509ChainPolicy.cs
- PartitionResolver.cs
- RequiredAttributeAttribute.cs
- QuotedPrintableStream.cs
- AbstractExpressions.cs
- ApplicationSecurityInfo.cs