Ejemplo n.º 1
0
        public RecordStateFactory(int stateSlotNumber, int columnCount, RecordStateFactory[] nestedRecordStateFactories, DataRecordInfo dataRecordInfo, Expression gatherData, string[] propertyNames, TypeUsage[] typeUsages)
        {
            this.StateSlotNumber            = stateSlotNumber;
            this.ColumnCount                = columnCount;
            this.NestedRecordStateFactories = new System.Collections.ObjectModel.ReadOnlyCollection <RecordStateFactory>(nestedRecordStateFactories);
            this.DataRecordInfo             = dataRecordInfo;
            this.GatherData  = Translator.Compile <bool>(gatherData);
            this.Description = gatherData.ToString();
            this.ColumnNames = new System.Collections.ObjectModel.ReadOnlyCollection <string>(propertyNames);
            this.TypeUsages  = new System.Collections.ObjectModel.ReadOnlyCollection <TypeUsage>(typeUsages);

            this.FieldNameLookup = new FieldNameLookup(this.ColumnNames, -1);

            // pre-compute the nested objects from typeUsage, for performance
            bool[] isColumnNested = new bool[columnCount];

            for (int ordinal = 0; ordinal < columnCount; ordinal++)
            {
                switch (typeUsages[ordinal].EdmType.BuiltInTypeKind)
                {
                case BuiltInTypeKind.EntityType:
                case BuiltInTypeKind.ComplexType:
                case BuiltInTypeKind.RowType:
                case BuiltInTypeKind.CollectionType:
                    isColumnNested[ordinal] = true;
                    this.HasNestedColumns   = true;
                    break;

                default:
                    isColumnNested[ordinal] = false;
                    break;
                }
            }
            this.IsColumnNested = new System.Collections.ObjectModel.ReadOnlyCollection <bool>(isColumnNested);
        }
Ejemplo n.º 2
0
        private ComplexTypeMaterializer.Plan GetPlan(DataRecordInfo recordInfo)
        {
            ComplexTypeMaterializer.Plan[] planArray = this._lastPlans ?? (this._lastPlans = new ComplexTypeMaterializer.Plan[4]);
            int index1 = this._lastPlanIndex - 1;

            for (int index2 = 0; index2 < 4; ++index2)
            {
                index1 = (index1 + 1) % 4;
                if (planArray[index1] != null)
                {
                    if (planArray[index1].Key == recordInfo.RecordType)
                    {
                        this._lastPlanIndex = index1;
                        return(planArray[index1]);
                    }
                }
                else
                {
                    break;
                }
            }
            ObjectTypeMapping objectMapping = Util.GetObjectMapping(recordInfo.RecordType.EdmType, this._workspace);

            this._lastPlanIndex = index1;
            planArray[index1]   = new ComplexTypeMaterializer.Plan(recordInfo.RecordType, objectMapping, recordInfo.FieldMetadata);
            return(planArray[index1]);
        }
        internal StateManagerTypeMetadata(EdmType edmType, ObjectTypeMapping mapping)
        {
            this._typeUsage  = TypeUsage.Create(edmType);
            this._recordInfo = new DataRecordInfo(this._typeUsage);
            ReadOnlyMetadataCollection <EdmProperty> properties = TypeHelpers.GetProperties(edmType);

            this._members             = new StateManagerMemberMetadata[properties.Count];
            this._objectNameToOrdinal = new Dictionary <string, int>(properties.Count);
            this._cLayerNameToOrdinal = new Dictionary <string, int>(properties.Count);
            ReadOnlyMetadataCollection <EdmMember> metadataCollection = (ReadOnlyMetadataCollection <EdmMember>)null;

            if (Helper.IsEntityType(edmType))
            {
                metadataCollection = ((EntityTypeBase)edmType).KeyMembers;
            }
            for (int index = 0; index < this._members.Length; ++index)
            {
                EdmProperty           memberMetadata = properties[index];
                ObjectPropertyMapping memberMap      = (ObjectPropertyMapping)null;
                if (mapping != null)
                {
                    memberMap = mapping.GetPropertyMap(memberMetadata.Name);
                    if (memberMap != null)
                    {
                        this._objectNameToOrdinal.Add(memberMap.ClrProperty.Name, index);
                    }
                }
                this._cLayerNameToOrdinal.Add(memberMetadata.Name, index);
                this._members[index] = new StateManagerMemberMetadata(memberMap, memberMetadata, metadataCollection != null && metadataCollection.Contains((EdmMember)memberMetadata));
            }
        }
Ejemplo n.º 4
0
 public RecordStateFactory(
     int stateSlotNumber,
     int columnCount,
     RecordStateFactory[] nestedRecordStateFactories,
     DataRecordInfo dataRecordInfo,
     Expression gatherData,
     string[] propertyNames,
     TypeUsage[] typeUsages)
     : this(stateSlotNumber, columnCount, nestedRecordStateFactories, dataRecordInfo, CodeGenEmitter.BuildShaperLambda <bool>(gatherData), propertyNames, typeUsages, (bool[])null)
 {
 }
Ejemplo n.º 5
0
 public PersistedStateEntry(EntityKey ekey, DataRecordInfo recordInfo, IExtendedDataRecord origValues, object entity, string errorMessage)
 {
     _eKey           = ekey;
     _detachedEntity = entity;
     _origValues     = new Dictionary <string, object>();
     _message        = errorMessage;
     for (var i = 0; i < origValues.FieldCount; i++)
     {
         _origValues.Add(recordInfo.FieldMetadata[i].FieldType.Name, origValues[i]);
     }
     _relationships = new List <RelationshipEnds>();
 }
Ejemplo n.º 6
0
 internal object CreateComplex(
     IExtendedDataRecord record,
     DataRecordInfo recordInfo,
     object result)
 {
     ComplexTypeMaterializer.Plan plan = this.GetPlan(recordInfo);
     if (result == null)
     {
         result = plan.ClrType();
     }
     this.SetProperties(record, result, plan.Properties);
     return(result);
 }
        internal StateManagerTypeMetadata(EdmType edmType, ObjectTypeMapping mapping)
        {
            DebugCheck.NotNull(edmType);
            Debug.Assert(
                Helper.IsEntityType(edmType) ||
                Helper.IsComplexType(edmType),
                "not Complex or EntityType");
            Debug.Assert(
                ReferenceEquals(mapping, null) ||
                ReferenceEquals(mapping.EdmType, edmType),
                "different EdmType instance");

            _typeUsage  = TypeUsage.Create(edmType);
            _recordInfo = new DataRecordInfo(_typeUsage);

            var members = TypeHelpers.GetProperties(edmType);

            _members             = new StateManagerMemberMetadata[members.Count];
            _objectNameToOrdinal = new Dictionary <string, int>(members.Count);
            _cLayerNameToOrdinal = new Dictionary <string, int>(members.Count);

            ReadOnlyMetadataCollection <EdmMember> keyMembers = null;

            if (Helper.IsEntityType(edmType))
            {
                keyMembers = ((EntityType)edmType).KeyMembers;
            }

            for (var i = 0; i < _members.Length; ++i)
            {
                var member = members[i];

                ObjectPropertyMapping memberMap = null;
                if (null != mapping)
                {
                    memberMap = mapping.GetPropertyMap(member.Name);
                    if (null != memberMap)
                    {
                        _objectNameToOrdinal.Add(memberMap.ClrProperty.Name, i); // olayer name
                    }
                }
                _cLayerNameToOrdinal.Add(member.Name, i); // clayer name

                // Determine whether this member is part of the identity of the entity.
                _members[i] = new StateManagerMemberMetadata(memberMap, member, ((null != keyMembers) && keyMembers.Contains(member)));
            }
        }
Ejemplo n.º 8
0
        public RecordStateFactory(
            int stateSlotNumber,
            int columnCount,
            RecordStateFactory[] nestedRecordStateFactories,
            DataRecordInfo dataRecordInfo,
            Expression <Func <Shaper, bool> > gatherData,
            string[] propertyNames,
            TypeUsage[] typeUsages,
            bool[] isColumnNested)
        {
            this.StateSlotNumber            = stateSlotNumber;
            this.ColumnCount                = columnCount;
            this.NestedRecordStateFactories = new ReadOnlyCollection <RecordStateFactory>((IList <RecordStateFactory>)nestedRecordStateFactories);
            this.DataRecordInfo             = dataRecordInfo;
            this.GatherData      = gatherData.Compile();
            this.Description     = gatherData.ToString();
            this.ColumnNames     = new ReadOnlyCollection <string>((IList <string>)propertyNames);
            this.TypeUsages      = new ReadOnlyCollection <TypeUsage>((IList <TypeUsage>)typeUsages);
            this.FieldNameLookup = new FieldNameLookup(this.ColumnNames);
            if (isColumnNested == null)
            {
                isColumnNested = new bool[columnCount];
                for (int index = 0; index < columnCount; ++index)
                {
                    switch (typeUsages[index].EdmType.BuiltInTypeKind)
                    {
                    case BuiltInTypeKind.CollectionType:
                    case BuiltInTypeKind.ComplexType:
                    case BuiltInTypeKind.EntityType:
                    case BuiltInTypeKind.RowType:
                        isColumnNested[index] = true;
                        this.HasNestedColumns = true;
                        break;

                    default:
                        isColumnNested[index] = false;
                        break;
                    }
                }
            }
            this.IsColumnNested = new ReadOnlyCollection <bool>((IList <bool>)isColumnNested);
        }
Ejemplo n.º 9
0
        internal object CreateComplex(IExtendedDataRecord record, DataRecordInfo recordInfo, object result)
        {
            Debug.Assert(null != record, "null IExtendedDataRecord");
            Debug.Assert(null != recordInfo, "null DataRecordInfo");
            Debug.Assert(null != recordInfo.RecordType, "null TypeUsage");
            Debug.Assert(null != recordInfo.RecordType.EdmType, "null EdmType");

            Debug.Assert(Helper.IsEntityType(recordInfo.RecordType.EdmType) ||
                         Helper.IsComplexType(recordInfo.RecordType.EdmType),
                         "not EntityType or ComplexType");

            Plan plan = GetPlan(record, recordInfo);

            if (null == result)
            {
                result = ((Func <object>)plan.ClrType)();
            }
            SetProperties(record, result, plan.Properties);
            return(result);
        }
        internal object CreateComplex(IExtendedDataRecord record, DataRecordInfo recordInfo, object result)
        {
            DebugCheck.NotNull(record);
            DebugCheck.NotNull(recordInfo);
            DebugCheck.NotNull(recordInfo.RecordType);
            DebugCheck.NotNull(recordInfo.RecordType.EdmType);

            Debug.Assert(
                Helper.IsEntityType(recordInfo.RecordType.EdmType) ||
                Helper.IsComplexType(recordInfo.RecordType.EdmType),
                "not EntityType or ComplexType");

            var plan = GetPlan(recordInfo);

            if (null == result)
            {
                result = plan.ClrType();
            }
            SetProperties(record, result, plan.Properties);
            return(result);
        }
        private Plan GetPlan(DataRecordInfo recordInfo)
        {
            DebugCheck.NotNull(recordInfo);
            DebugCheck.NotNull(recordInfo.RecordType);

            var plans = _lastPlans ?? (_lastPlans = new Plan[MaxPlanCount]);

            // find an existing plan in circular buffer
            var index = _lastPlanIndex - 1;

            for (var i = 0; i < MaxPlanCount; ++i)
            {
                index = (index + 1) % MaxPlanCount;
                if (null == plans[index])
                {
                    break;
                }
                if (plans[index].Key
                    == recordInfo.RecordType)
                {
                    _lastPlanIndex = index;
                    return(plans[index]);
                }
            }
            Debug.Assert(0 <= index, "negative index");
            Debug.Assert(index != _lastPlanIndex || (null == plans[index]), "index wrapped around");

            // create a new plan
            var mapping = Util.GetObjectMapping(recordInfo.RecordType.EdmType, _workspace);

            Debug.Assert(null != mapping, "null ObjectTypeMapping");

            Debug.Assert(
                Helper.IsComplexType(recordInfo.RecordType.EdmType),
                "IExtendedDataRecord is not ComplexType");

            _lastPlanIndex = index;
            plans[index]   = new Plan(recordInfo.RecordType, mapping, recordInfo.FieldMetadata);
            return(plans[index]);
        }
Ejemplo n.º 12
0
        public RecordStateFactory(
            int stateSlotNumber, int columnCount, RecordStateFactory[] nestedRecordStateFactories, DataRecordInfo dataRecordInfo,
            Expression <Func <Shaper, bool> > gatherData, string[] propertyNames, TypeUsage[] typeUsages, bool[] isColumnNested)
        {
            StateSlotNumber            = stateSlotNumber;
            ColumnCount                = columnCount;
            NestedRecordStateFactories = new ReadOnlyCollection <RecordStateFactory>(nestedRecordStateFactories);
            DataRecordInfo             = dataRecordInfo;
            GatherData  = gatherData.Compile();
            Description = gatherData.ToString();
            ColumnNames = new ReadOnlyCollection <string>(propertyNames);
            TypeUsages  = new ReadOnlyCollection <TypeUsage>(typeUsages);

            FieldNameLookup = new FieldNameLookup(ColumnNames);

            // pre-compute the nested objects from typeUsage, for performance
            if (isColumnNested == null)
            {
                isColumnNested = new bool[columnCount];

                for (var ordinal = 0; ordinal < columnCount; ordinal++)
                {
                    switch (typeUsages[ordinal].EdmType.BuiltInTypeKind)
                    {
                    case BuiltInTypeKind.EntityType:
                    case BuiltInTypeKind.ComplexType:
                    case BuiltInTypeKind.RowType:
                    case BuiltInTypeKind.CollectionType:
                        isColumnNested[ordinal] = true;
                        HasNestedColumns        = true;
                        break;

                    default:
                        isColumnNested[ordinal] = false;
                        break;
                    }
                }
            }
            IsColumnNested = new ReadOnlyCollection <bool>(isColumnNested);
        }
Ejemplo n.º 13
0
        private Plan GetPlan(IExtendedDataRecord record, DataRecordInfo recordInfo)
        {
            Debug.Assert(null != record, "null IExtendedDataRecord");
            Debug.Assert(null != recordInfo, "null DataRecordInfo");
            Debug.Assert(null != recordInfo.RecordType, "null TypeUsage");

            Plan[] plans = _lastPlans ?? (_lastPlans = new Plan[MaxPlanCount]);

            // find an existing plan in circular buffer
            int index = _lastPlanIndex - 1;

            for (int i = 0; i < MaxPlanCount; ++i)
            {
                index = (index + 1) % MaxPlanCount;
                if (null == plans[index])
                {
                    break;
                }
                if (plans[index].Key == recordInfo.RecordType)
                {
                    _lastPlanIndex = index;
                    return(plans[index]);
                }
            }
            Debug.Assert(0 <= index, "negative index");
            Debug.Assert(index != _lastPlanIndex || (null == plans[index]), "index wrapped around");

            // create a new plan
            ObjectTypeMapping mapping = System.Data.Common.Internal.Materialization.Util.GetObjectMapping(recordInfo.RecordType.EdmType, _workspace);

            Debug.Assert(null != mapping, "null ObjectTypeMapping");

            Debug.Assert(Helper.IsComplexType(recordInfo.RecordType.EdmType),
                         "IExtendedDataRecord is not ComplexType");

            _lastPlanIndex = index;
            plans[index]   = new Plan(recordInfo.RecordType, mapping, recordInfo.FieldMetadata);
            return(plans[index]);
        }
Ejemplo n.º 14
0
        public RecordStateFactory(int stateSlotNumber, int columnCount, RecordStateFactory[] nestedRecordStateFactories, DataRecordInfo dataRecordInfo, Expression gatherData, string[] propertyNames, TypeUsage[] typeUsages)
        {
            this.StateSlotNumber = stateSlotNumber;
            this.ColumnCount = columnCount;
            this.NestedRecordStateFactories = new System.Collections.ObjectModel.ReadOnlyCollection<RecordStateFactory>(nestedRecordStateFactories);
            this.DataRecordInfo = dataRecordInfo;
            this.GatherData = Translator.Compile<bool>(gatherData);
            this.Description = gatherData.ToString();
            this.ColumnNames = new System.Collections.ObjectModel.ReadOnlyCollection<string>(propertyNames);
            this.TypeUsages = new System.Collections.ObjectModel.ReadOnlyCollection<TypeUsage>(typeUsages);

            this.FieldNameLookup = new FieldNameLookup(this.ColumnNames, -1);

            // pre-compute the nested objects from typeUsage, for performance
            bool[] isColumnNested = new bool[columnCount];

            for (int ordinal = 0; ordinal < columnCount; ordinal++)
            {
                switch (typeUsages[ordinal].EdmType.BuiltInTypeKind)
                {
                    case BuiltInTypeKind.EntityType:
                    case BuiltInTypeKind.ComplexType:
                    case BuiltInTypeKind.RowType:
                    case BuiltInTypeKind.CollectionType:
                        isColumnNested[ordinal] = true;
                        this.HasNestedColumns = true;
                        break;
                    default:
                        isColumnNested[ordinal] = false;
                        break;
                }
            }
            this.IsColumnNested = new System.Collections.ObjectModel.ReadOnlyCollection<bool>(isColumnNested);
        }
 public RecordStateFactory(
     int stateSlotNumber, int columnCount, RecordStateFactory[] nestedRecordStateFactories, DataRecordInfo dataRecordInfo,
     Expression gatherData, string[] propertyNames, TypeUsage[] typeUsages)
     : this(stateSlotNumber, columnCount, nestedRecordStateFactories, dataRecordInfo,
         CodeGenEmitter.BuildShaperLambda<bool>(gatherData), propertyNames, typeUsages, isColumnNested: null)
 {
 }
        public RecordStateFactory(
            int stateSlotNumber, int columnCount, RecordStateFactory[] nestedRecordStateFactories, DataRecordInfo dataRecordInfo,
            Expression<Func<Shaper, bool>> gatherData, string[] propertyNames, TypeUsage[] typeUsages, bool[] isColumnNested)
        {
            StateSlotNumber = stateSlotNumber;
            ColumnCount = columnCount;
            NestedRecordStateFactories = new ReadOnlyCollection<RecordStateFactory>(nestedRecordStateFactories);
            DataRecordInfo = dataRecordInfo;
            GatherData = gatherData.Compile();
            Description = gatherData.ToString();
            ColumnNames = new ReadOnlyCollection<string>(propertyNames);
            TypeUsages = new ReadOnlyCollection<TypeUsage>(typeUsages);

            FieldNameLookup = new FieldNameLookup(ColumnNames, -1);

            // pre-compute the nested objects from typeUsage, for performance
            if (isColumnNested == null)
            {
                isColumnNested = new bool[columnCount];

                for (var ordinal = 0; ordinal < columnCount; ordinal++)
                {
                    switch (typeUsages[ordinal].EdmType.BuiltInTypeKind)
                    {
                        case BuiltInTypeKind.EntityType:
                        case BuiltInTypeKind.ComplexType:
                        case BuiltInTypeKind.RowType:
                        case BuiltInTypeKind.CollectionType:
                            isColumnNested[ordinal] = true;
                            HasNestedColumns = true;
                            break;
                        default:
                            isColumnNested[ordinal] = false;
                            break;
                    }
                }
            }
            IsColumnNested = new ReadOnlyCollection<bool>(isColumnNested);
        }
Ejemplo n.º 17
0
        private bool EndIsSingular(DataRecordInfo dataRecordInfo, int index)
        {
            var associationEndMember = dataRecordInfo.FieldMetadata[index].FieldType as AssociationEndMember;

            return(associationEndMember.RelationshipMultiplicity != RelationshipMultiplicity.Many);
        }