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 / Structures / OneOfScalarConst.cs / 1 / OneOfScalarConst.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Data.Common.Utils.Boolean; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Data.Common.Utils; using System.Data.Metadata.Edm; using System.Linq; using System.Data.Entity; namespace System.Data.Mapping.ViewGeneration.Structures { using DomainBoolExpr = BoolExpr>; // A class that denotes the boolean expression: "scalarVar in values" // See the comments in OneOfConst for partially and fully-done objects internal class OneOfScalarConst : OneOfConst { #region Constructors // effects: Creates an expression of the form "node in scalar strings // corresponding to values". This constructor is needed for creating // discriminator type conditions internal OneOfScalarConst(JoinTreeNode node, object value, TypeUsage memberType) : this(node, new ScalarConstant(value)) { // CHANGE_[....]_IMPROVE: the memberType stuff has to be consumed } internal OneOfScalarConst(JoinTreeNode node, CellConstant value) : base(new JoinTreeSlot(node), value) { Debug.Assert(value is ScalarConstant || value.IsNull() || value.IsNotNull(), "Scalar, NULL, or NOT NULL expected"); } // effects: Creates an expression of the form "var = value" internal OneOfScalarConst(JoinTreeNode node, IEnumerable values, IEnumerable possibleValues) : base(new JoinTreeSlot(node), values, possibleValues) { } // effects: Creates an expression of the form "slot in domain" internal OneOfScalarConst(JoinTreeSlot slot, CellConstantDomain domain) : base(slot, domain) { } #endregion #region Methods // requires: IsFullyDone is true // effects: Fixes the range of this in accordance with range internal override DomainBoolExpr FixRange(Set range, MemberDomainMap memberDomainMap) { Debug.Assert(IsFullyDone, "Ranges are fixed only for fully done OneOfConsts"); IEnumerable newPossibleValues = memberDomainMap.GetDomain(Slot.MemberPath); BoolLiteral newLiteral = new OneOfScalarConst(Slot, new CellConstantDomain(range, newPossibleValues)); return newLiteral.GetDomainBoolExpression(memberDomainMap); } // requires: there is at most one negated Constant internal override StringBuilder AsCql(StringBuilder builder, string blockAlias, bool canSkipIsNotNull) { return ToStringHelper(builder, blockAlias, canSkipIsNotNull, false); } internal override StringBuilder AsUserString(StringBuilder builder, string blockAlias, bool canSkipIsNotNull) { return ToStringHelper(builder, blockAlias, canSkipIsNotNull, true); } //Common code for AsCQL and TouserString methods private StringBuilder ToStringHelper(StringBuilder builder, string blockAlias, bool canSkipIsNotNull, bool userString) { Debug.Assert(Slot.MemberPath.IsScalarType(), "Expected scalar"); Set constants = new Set (Values.Values, CellConstant.EqualityComparer); // * If no negated cell constant generate the normal list // * If nullable, add AND IS NOT NULL to the list of normal values // * If has a negated cell constant, come up with a simplified // version of the constants, e.g., 7, NOT(7, NULL) means NOT NULL // 7, 8, NOT(7, 8, 9, 10) Means NOT(9, 10) // Note: NOT(9, NULL) is NOT (a is 9 OR a is NULL) = // A IS NOT 9 AND A IS NOT NULL NegatedCellConstant negated = null; foreach (CellConstant constant in constants) { NegatedCellConstant tmpConstant = constant as NegatedCellConstant; if (tmpConstant != null) { Debug.Assert(negated == null, "Multiple negated constants?"); negated = tmpConstant; } } if (negated != null) { if (userString) { return negated.AsUserString(builder, blockAlias, constants, Slot.MemberPath, canSkipIsNotNull); } else { return negated.AsCql(builder, blockAlias, constants, Slot.MemberPath, canSkipIsNotNull); } } // We have only positive constants bool containsNull = constants.Contains(CellConstant.Null); constants.Remove(CellConstant.Null); //Constraint counter-example could contain undefined cellconstant. E.g for booleans (for int its optimized out due to negated constants) //we want to treat undefined as nulls if (constants.Contains(CellConstant.Undefined)) { constants.Remove(CellConstant.Undefined); containsNull = true; } if (containsNull) { if (constants.Count > 0) { builder.Append('('); } if (userString) { Slot.MemberPath.ToCompactString(builder, blockAlias); builder.Append(" is NULL"); } else { Slot.MemberPath.AsCql(builder, blockAlias); builder.Append(" IS NULL"); } if (constants.Count > 0) { builder.Append(" OR "); } } if (constants.Count == 0) { return builder; } bool isNullable = Slot.MemberPath.IsNullable; // Generate var IN {...} or var = ... // For nullable members, add (... AND var IS NOT NULL) // so the boolean _from variables never evaluate to null // This is needed because view generation assumes 2-valued boolean logic if (isNullable && canSkipIsNotNull == false) { builder.Append("("); // enclose AND var IS NOT NULL in brackets } if (userString) { Slot.MemberPath.ToCompactString(builder, blockAlias); } else { Slot.MemberPath.AsCql(builder, blockAlias); } if (constants.Count > 1) { // Multiple values builder.Append(" IN {"); bool isFirst = true; foreach (CellConstant constant in constants) { if (isFirst == false) { builder.Append(", "); } isFirst = false; if (userString) { constant.ToCompactString(builder); } else { constant.AsCql(builder, Slot.MemberPath, blockAlias); } } builder.Append("}"); } else { // Single value builder.Append(" = "); if (userString) { constants.Single().ToCompactString(builder); } else { constants.Single().AsCql(builder, Slot.MemberPath, blockAlias); } } if (isNullable && canSkipIsNotNull == false) { // add the AND var IS NOT NULL condition builder.Append(" AND "); if (userString) { Slot.MemberPath.ToCompactString(builder, Strings.ViewGen_EntityInstanceToken); builder.Append(" is not NULL)"); // plus the closing bracket } else { Slot.MemberPath.AsCql(builder, blockAlias); builder.Append(" IS NOT NULL)"); // plus the closing bracket } } if (containsNull) { // Close the OR builder.Append(')'); } return builder; } #endregion #region String methods internal override void ToCompactString(StringBuilder builder) { Slot.ToCompactString(builder); builder.Append(" IN ("); StringUtil.ToCommaSeparatedStringSorted(builder, Values.Values); builder.Append(")"); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System.Data.Common.Utils.Boolean; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Data.Common.Utils; using System.Data.Metadata.Edm; using System.Linq; using System.Data.Entity; namespace System.Data.Mapping.ViewGeneration.Structures { using DomainBoolExpr = BoolExpr>; // A class that denotes the boolean expression: "scalarVar in values" // See the comments in OneOfConst for partially and fully-done objects internal class OneOfScalarConst : OneOfConst { #region Constructors // effects: Creates an expression of the form "node in scalar strings // corresponding to values". This constructor is needed for creating // discriminator type conditions internal OneOfScalarConst(JoinTreeNode node, object value, TypeUsage memberType) : this(node, new ScalarConstant(value)) { // CHANGE_[....]_IMPROVE: the memberType stuff has to be consumed } internal OneOfScalarConst(JoinTreeNode node, CellConstant value) : base(new JoinTreeSlot(node), value) { Debug.Assert(value is ScalarConstant || value.IsNull() || value.IsNotNull(), "Scalar, NULL, or NOT NULL expected"); } // effects: Creates an expression of the form "var = value" internal OneOfScalarConst(JoinTreeNode node, IEnumerable values, IEnumerable possibleValues) : base(new JoinTreeSlot(node), values, possibleValues) { } // effects: Creates an expression of the form "slot in domain" internal OneOfScalarConst(JoinTreeSlot slot, CellConstantDomain domain) : base(slot, domain) { } #endregion #region Methods // requires: IsFullyDone is true // effects: Fixes the range of this in accordance with range internal override DomainBoolExpr FixRange(Set range, MemberDomainMap memberDomainMap) { Debug.Assert(IsFullyDone, "Ranges are fixed only for fully done OneOfConsts"); IEnumerable newPossibleValues = memberDomainMap.GetDomain(Slot.MemberPath); BoolLiteral newLiteral = new OneOfScalarConst(Slot, new CellConstantDomain(range, newPossibleValues)); return newLiteral.GetDomainBoolExpression(memberDomainMap); } // requires: there is at most one negated Constant internal override StringBuilder AsCql(StringBuilder builder, string blockAlias, bool canSkipIsNotNull) { return ToStringHelper(builder, blockAlias, canSkipIsNotNull, false); } internal override StringBuilder AsUserString(StringBuilder builder, string blockAlias, bool canSkipIsNotNull) { return ToStringHelper(builder, blockAlias, canSkipIsNotNull, true); } //Common code for AsCQL and TouserString methods private StringBuilder ToStringHelper(StringBuilder builder, string blockAlias, bool canSkipIsNotNull, bool userString) { Debug.Assert(Slot.MemberPath.IsScalarType(), "Expected scalar"); Set constants = new Set (Values.Values, CellConstant.EqualityComparer); // * If no negated cell constant generate the normal list // * If nullable, add AND IS NOT NULL to the list of normal values // * If has a negated cell constant, come up with a simplified // version of the constants, e.g., 7, NOT(7, NULL) means NOT NULL // 7, 8, NOT(7, 8, 9, 10) Means NOT(9, 10) // Note: NOT(9, NULL) is NOT (a is 9 OR a is NULL) = // A IS NOT 9 AND A IS NOT NULL NegatedCellConstant negated = null; foreach (CellConstant constant in constants) { NegatedCellConstant tmpConstant = constant as NegatedCellConstant; if (tmpConstant != null) { Debug.Assert(negated == null, "Multiple negated constants?"); negated = tmpConstant; } } if (negated != null) { if (userString) { return negated.AsUserString(builder, blockAlias, constants, Slot.MemberPath, canSkipIsNotNull); } else { return negated.AsCql(builder, blockAlias, constants, Slot.MemberPath, canSkipIsNotNull); } } // We have only positive constants bool containsNull = constants.Contains(CellConstant.Null); constants.Remove(CellConstant.Null); //Constraint counter-example could contain undefined cellconstant. E.g for booleans (for int its optimized out due to negated constants) //we want to treat undefined as nulls if (constants.Contains(CellConstant.Undefined)) { constants.Remove(CellConstant.Undefined); containsNull = true; } if (containsNull) { if (constants.Count > 0) { builder.Append('('); } if (userString) { Slot.MemberPath.ToCompactString(builder, blockAlias); builder.Append(" is NULL"); } else { Slot.MemberPath.AsCql(builder, blockAlias); builder.Append(" IS NULL"); } if (constants.Count > 0) { builder.Append(" OR "); } } if (constants.Count == 0) { return builder; } bool isNullable = Slot.MemberPath.IsNullable; // Generate var IN {...} or var = ... // For nullable members, add (... AND var IS NOT NULL) // so the boolean _from variables never evaluate to null // This is needed because view generation assumes 2-valued boolean logic if (isNullable && canSkipIsNotNull == false) { builder.Append("("); // enclose AND var IS NOT NULL in brackets } if (userString) { Slot.MemberPath.ToCompactString(builder, blockAlias); } else { Slot.MemberPath.AsCql(builder, blockAlias); } if (constants.Count > 1) { // Multiple values builder.Append(" IN {"); bool isFirst = true; foreach (CellConstant constant in constants) { if (isFirst == false) { builder.Append(", "); } isFirst = false; if (userString) { constant.ToCompactString(builder); } else { constant.AsCql(builder, Slot.MemberPath, blockAlias); } } builder.Append("}"); } else { // Single value builder.Append(" = "); if (userString) { constants.Single().ToCompactString(builder); } else { constants.Single().AsCql(builder, Slot.MemberPath, blockAlias); } } if (isNullable && canSkipIsNotNull == false) { // add the AND var IS NOT NULL condition builder.Append(" AND "); if (userString) { Slot.MemberPath.ToCompactString(builder, Strings.ViewGen_EntityInstanceToken); builder.Append(" is not NULL)"); // plus the closing bracket } else { Slot.MemberPath.AsCql(builder, blockAlias); builder.Append(" IS NOT NULL)"); // plus the closing bracket } } if (containsNull) { // Close the OR builder.Append(')'); } return builder; } #endregion #region String methods internal override void ToCompactString(StringBuilder builder) { Slot.ToCompactString(builder); builder.Append(" IN ("); StringUtil.ToCommaSeparatedStringSorted(builder, Values.Values); builder.Append(")"); } #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
- DataTransferEventArgs.cs
- ErrorProvider.cs
- UpdatePanel.cs
- APCustomTypeDescriptor.cs
- Tracking.cs
- arabicshape.cs
- ObjectStateManagerMetadata.cs
- DataListAutoFormat.cs
- WebPartTransformer.cs
- CodeRegionDirective.cs
- EntityProviderFactory.cs
- PermissionAttributes.cs
- WebPartPersonalization.cs
- BrushMappingModeValidation.cs
- DataServiceHost.cs
- FixedMaxHeap.cs
- NonVisualControlAttribute.cs
- OneWayElement.cs
- ConfigurationLocation.cs
- AdRotatorDesigner.cs
- SqlCachedBuffer.cs
- CheckBoxAutomationPeer.cs
- DataViewSettingCollection.cs
- DefaultClaimSet.cs
- ImageUrlEditor.cs
- OletxDependentTransaction.cs
- DebuggerAttributes.cs
- DataTablePropertyDescriptor.cs
- QilLiteral.cs
- InheritanceContextHelper.cs
- ClientTargetSection.cs
- FileLevelControlBuilderAttribute.cs
- Int32EqualityComparer.cs
- Int16Storage.cs
- BindingExpressionUncommonField.cs
- DateTimeOffsetStorage.cs
- _HelperAsyncResults.cs
- ScrollEvent.cs
- EntityDataSourceSelectingEventArgs.cs
- GridItemCollection.cs
- PackWebResponse.cs
- DetailsViewModeEventArgs.cs
- DesignerAutoFormatStyle.cs
- WebPartMenu.cs
- HebrewCalendar.cs
- EventItfInfo.cs
- Clause.cs
- TransformValueSerializer.cs
- SmiTypedGetterSetter.cs
- LeftCellWrapper.cs
- oledbmetadatacollectionnames.cs
- CodeAccessPermission.cs
- ClientRoleProvider.cs
- DataRelation.cs
- Expression.cs
- SharedStream.cs
- RoutedCommand.cs
- DecoderReplacementFallback.cs
- SystemFonts.cs
- webproxy.cs
- ComponentEditorPage.cs
- CalendarTable.cs
- SchemaImporterExtensionElement.cs
- WmlLiteralTextAdapter.cs
- ConfigurationElement.cs
- WebControl.cs
- CatalogPartCollection.cs
- AssociationTypeEmitter.cs
- _NegoStream.cs
- XmlNamedNodeMap.cs
- DataGridTablesFactory.cs
- StyleReferenceConverter.cs
- XmlSchemaAny.cs
- ExpressionPrefixAttribute.cs
- SerializationFieldInfo.cs
- OutOfProcStateClientManager.cs
- HtmlEncodedRawTextWriter.cs
- SmiEventSink_Default.cs
- EDesignUtil.cs
- MouseActionConverter.cs
- Control.cs
- EdmRelationshipRoleAttribute.cs
- COM2IPerPropertyBrowsingHandler.cs
- Triangle.cs
- FigureHelper.cs
- WebPartEditorOkVerb.cs
- DCSafeHandle.cs
- SerializationFieldInfo.cs
- WinCategoryAttribute.cs
- SecurityUtils.cs
- Point4D.cs
- EventProviderTraceListener.cs
- DataGridViewCellStateChangedEventArgs.cs
- SmiEventSink_Default.cs
- MediaCommands.cs
- TextEvent.cs
- ResourceDescriptionAttribute.cs
- MenuStrip.cs
- BindableTemplateBuilder.cs
- CurrentTimeZone.cs