コード例 #1
0
 /// <summary>
 /// Gets all public properties of this type.
 /// </summary>
 public PropertyInfo[] GetProperties()
 {
     return(PropertyInfoProvider.GetProperties(this));
 }
コード例 #2
0
        protected void InitializeValueObjectMapping()
        {
            Object writeLock = GetWriteLock();

            lock (writeLock)
            {
                this.businessObjectSaveOrder = null;

                HashMap <Type, IISet <Type> > boTypeToBeforeBoTypes = new HashMap <Type, IISet <Type> >();
                HashMap <Type, IISet <Type> > boTypeToAfterBoTypes  = new HashMap <Type, IISet <Type> >();

                foreach (Entry <Type, IValueObjectConfig> entry in ValueObjectMap.GetExtensions())
                {
                    IValueObjectConfig voConfig = entry.Value;
                    Type            entityType  = voConfig.EntityType;
                    Type            valueType   = voConfig.ValueType;
                    IEntityMetaData metaData    = GetMetaData(entityType);

                    if (metaData == null)
                    {
                        // Currently no bo metadata found. We can do nothing here
                        return;
                    }
                    IMap <String, ITypeInfoItem> boNameToVoMember = GetTypeInfoMapForVo(valueType);

                    foreach (RelationMember boMember in metaData.RelationMembers)
                    {
                        String        boMemberName = boMember.Name;
                        String        voMemberName = voConfig.GetValueObjectMemberName(boMemberName);
                        ITypeInfoItem voMember     = boNameToVoMember.Get(boMemberName);
                        if (voConfig.IsIgnoredMember(voMemberName) || voMember == null)
                        {
                            continue;
                        }
                        Type voMemberRealType = voMember.RealType;
                        if (voConfig.HoldsListType(voMember.Name))
                        {
                            IPropertyInfo[] properties = PropertyInfoProvider.GetProperties(voMemberRealType);
                            if (properties.Length != 1)
                            {
                                throw new ArgumentException("ListTypes must have exactly one property");
                            }
                            voMemberRealType = TypeInfoProvider.GetMember(voMemberRealType, properties[0]).RealType;
                        }
                        if (!ImmutableTypeSet.IsImmutableType(voMemberRealType))
                        {
                            // vo member is either a list or a single direct relation to another VO
                            // This implies that a potential service can handle both VO types as new objects at once
                            continue;
                        }
                        // vo member only holds a id reference which implies that the related VO has to be persisted first to
                        // contain an id which can be referred to. But we do NOT know the related VO here, but we know
                        // the related BO where ALL potential VOs will be derived from:
                        Type boMemberElementType = boMember.ElementType;

                        if (Object.Equals(entityType, boMemberElementType))
                        {
                            continue;
                        }

                        AddBoTypeAfter(entityType, boMemberElementType, boTypeToBeforeBoTypes, boTypeToAfterBoTypes);
                        AddBoTypeBefore(entityType, boMemberElementType, boTypeToBeforeBoTypes, boTypeToAfterBoTypes);
                    }
                }
                List <Type> businessObjectSaveOrder = new List <Type>();

                foreach (Type boType in boTypeToBeforeBoTypes.KeySet())
                {
                    // BeforeBoType are types which have to be saved BEFORE saving the boType
                    bool added = false;
                    for (int a = 0, size = businessObjectSaveOrder.Count; a < size; a++)
                    {
                        Type orderedBoType = businessObjectSaveOrder[a];

                        // OrderedBoType is the type currently inserted at the correct position in the save order - as far as the keyset
                        // has been traversed, yet

                        ISet <Type> typesBeforeOrderedType = boTypeToBeforeBoTypes.Get(orderedBoType);
                        // typesBeforeOrderedType are types which have to be

                        bool orderedHasToBeAfterCurrent = typesBeforeOrderedType != null && typesBeforeOrderedType.Contains(boType);

                        if (!orderedHasToBeAfterCurrent)
                        {
                            // our boType has nothing to do with the orderedBoType. So we let is be at it is
                            continue;
                        }
                        businessObjectSaveOrder.Insert(a, boType);
                        added = true;
                        break;
                    }
                    if (!added)
                    {
                        businessObjectSaveOrder.Add(boType);
                    }
                }
                foreach (Type boType in boTypeToAfterBoTypes.KeySet())
                {
                    if (boTypeToBeforeBoTypes.ContainsKey(boType))
                    {
                        // already handled in the previous loop
                        continue;
                    }
                    bool added = false;
                    for (int a = businessObjectSaveOrder.Count; a-- > 0;)
                    {
                        Type orderedBoType = businessObjectSaveOrder[a];

                        // OrderedBoType is the type currently inserted at the correct position in the save order - as far as the keyset
                        // has been traversed, yet

                        ISet <Type> typesBeforeOrderedType = boTypeToBeforeBoTypes.Get(orderedBoType);

                        bool orderedHasToBeAfterCurrent = typesBeforeOrderedType != null && typesBeforeOrderedType.Contains(boType);

                        if (!orderedHasToBeAfterCurrent)
                        {
                            // our boType has nothing to do with the orderedBoType. So we let it be as it is
                            continue;
                        }
                        businessObjectSaveOrder.Insert(a, boType);
                        added = true;
                        break;
                    }
                    if (!added)
                    {
                        businessObjectSaveOrder.Add(boType);
                    }
                }
                this.businessObjectSaveOrder = businessObjectSaveOrder.ToArray();
            }
        }
コード例 #3
0
ファイル: EntityMetaDataReader.cs プロジェクト: vogelb/ambeth
        public void AddMembers(EntityMetaData metaData, IEntityConfig entityConfig)
        {
            Type realType = entityConfig.RealType;

            ISet <String>                      memberNamesToIgnore      = new HashSet <String>();
            ISet <String>                      explicitBasicMemberNames = new HashSet <String>();
            IList <IMemberConfig>              embeddedMembers          = new List <IMemberConfig>();
            IMap <String, IMemberConfig>       nameToMemberConfig       = new HashMap <String, IMemberConfig>();
            IMap <String, IRelationConfig>     nameToRelationConfig     = new HashMap <String, IRelationConfig>();
            IdentityLinkedMap <String, Member> nameToMemberMap          = new IdentityLinkedMap <String, Member>();

            FillNameCollections(entityConfig, memberNamesToIgnore, explicitBasicMemberNames, embeddedMembers, nameToMemberConfig, nameToRelationConfig);

            IdentityLinkedSet <PrimitiveMember> alternateIdMembers = new IdentityLinkedSet <PrimitiveMember>();
            IdentityLinkedSet <PrimitiveMember> primitiveMembers   = new IdentityLinkedSet <PrimitiveMember>();
            IdentityLinkedSet <RelationMember>  relationMembers    = new IdentityLinkedSet <RelationMember>();
            IdentityLinkedSet <Member>          notMergeRelevant   = new IdentityLinkedSet <Member>();

            IdentityLinkedSet <Member> containedInAlternateIdMember = new IdentityLinkedSet <Member>();

            IPropertyInfo[] properties = PropertyInfoProvider.GetProperties(realType);

            IdentityLinkedMap <String, Member> explicitlyConfiguredMemberNameToMember = new IdentityLinkedMap <String, Member>();

            HashMap <String, IOrmConfig> nameToConfigMap = new HashMap <String, IOrmConfig>();

            // Resolve members for all explicit configurations - both simple and composite ones, each with embedded
            // functionality (dot-member-path)
            foreach (IMemberConfig memberConfig in entityConfig.GetMemberConfigIterable())
            {
                PutNameToConfigMap(memberConfig, nameToConfigMap);
                if (memberConfig.Ignore)
                {
                    continue;
                }
                HandleMemberConfig(metaData, realType, memberConfig, explicitlyConfiguredMemberNameToMember, nameToMemberMap);
            }
            foreach (IRelationConfig relationConfig in entityConfig.GetRelationConfigIterable())
            {
                PutNameToConfigMap(relationConfig, nameToConfigMap);
                HandleRelationConfig(realType, relationConfig, explicitlyConfiguredMemberNameToMember);
            }
            PutNameToConfigMap(entityConfig.IdMemberConfig, nameToConfigMap);
            PutNameToConfigMap(entityConfig.VersionMemberConfig, nameToConfigMap);
            PutNameToConfigMap(entityConfig.CreatedByMemberConfig, nameToConfigMap);
            PutNameToConfigMap(entityConfig.CreatedOnMemberConfig, nameToConfigMap);
            PutNameToConfigMap(entityConfig.UpdatedByMemberConfig, nameToConfigMap);
            PutNameToConfigMap(entityConfig.UpdatedOnMemberConfig, nameToConfigMap);

            metaData.IdMember        = HandleMemberConfig(metaData, realType, entityConfig.IdMemberConfig, explicitlyConfiguredMemberNameToMember, nameToMemberMap);
            metaData.VersionMember   = HandleMemberConfig(metaData, realType, entityConfig.VersionMemberConfig, explicitlyConfiguredMemberNameToMember, nameToMemberMap);
            metaData.CreatedByMember = HandleMemberConfig(metaData, realType, entityConfig.CreatedByMemberConfig, explicitlyConfiguredMemberNameToMember, nameToMemberMap);
            metaData.CreatedOnMember = HandleMemberConfig(metaData, realType, entityConfig.CreatedOnMemberConfig, explicitlyConfiguredMemberNameToMember, nameToMemberMap);
            metaData.UpdatedByMember = HandleMemberConfig(metaData, realType, entityConfig.UpdatedByMemberConfig, explicitlyConfiguredMemberNameToMember, nameToMemberMap);
            metaData.UpdatedOnMember = HandleMemberConfig(metaData, realType, entityConfig.UpdatedOnMemberConfig, explicitlyConfiguredMemberNameToMember, nameToMemberMap);

            IdentityHashSet <Member> idMembers = new IdentityHashSet <Member>();
            Member idMember = metaData.IdMember;

            if (idMember is CompositeIdMember)
            {
                idMembers.AddAll(((CompositeIdMember)idMember).Members);
            }
            else
            {
                idMembers.Add(idMember);
            }

            // Handle all explicitly configured members
            foreach (Entry <String, Member> entry in explicitlyConfiguredMemberNameToMember)
            {
                String     memberName = entry.Key;
                IOrmConfig ormConfig  = nameToConfigMap.Get(memberName);

                Member member = entry.Value;

                if (idMembers.Contains(member))
                {
                    continue;
                }
                if (ormConfig.ExplicitlyNotMergeRelevant)
                {
                    notMergeRelevant.Add(member);
                }
                if (ormConfig is IRelationConfig)
                {
                    if (!relationMembers.Add((RelationMember)member))
                    {
                        throw new Exception("Member has been registered as relation multiple times: " + member.Name);
                    }
                    continue;
                }
                if (!(ormConfig is IMemberConfig))
                {
                    continue;
                }
                if (((IMemberConfig)ormConfig).AlternateId)
                {
                    if (!alternateIdMembers.Add((PrimitiveMember)member))
                    {
                        throw new Exception("Member has been registered as alternate id multiple times: " + member.Name);
                    }
                    if (member is CompositeIdMember)
                    {
                        Member[] containedMembers = ((CompositeIdMember)member).Members;
                        containedInAlternateIdMember.AddAll(containedMembers);
                    }
                }
                if (!(member is CompositeIdMember) && metaData.VersionMember != member)
                {
                    // Alternate Ids are normally primitives, too. But Composite Alternate Ids not - only their composite
                    // items are primitives
                    primitiveMembers.Add((PrimitiveMember)member);
                }
            }
            IdentityHashSet <String> explicitTypeInfoItems = IdentityHashSet <String> .Create(explicitlyConfiguredMemberNameToMember.Count);

            foreach (Entry <String, Member> entry in explicitlyConfiguredMemberNameToMember)
            {
                Member member = entry.Value;
                explicitTypeInfoItems.Add(member.Name);
                if (member is IEmbeddedMember)
                {
                    explicitTypeInfoItems.Add(((IEmbeddedMember)member).GetMemberPath()[0].Name);
                }
            }
            // Go through the available members to look for potential auto-mapping (simple, no embedded)
            for (int i = 0; i < properties.Length; i++)
            {
                IPropertyInfo property   = properties[i];
                String        memberName = property.Name;
                if (memberNamesToIgnore.Contains(memberName))
                {
                    continue;
                }
                if (explicitTypeInfoItems.Contains(memberName))
                {
                    // already configured, no auto mapping needed for this member
                    continue;
                }

                MethodPropertyInfo mProperty = (MethodPropertyInfo)property;
                Type elementType             = TypeInfoItemUtil.GetElementTypeUsingReflection(mProperty.Getter.ReturnType, null);
                if ((nameToMemberMap.Get(property.Name) is RelationMember) || RelationProvider.IsEntityType(elementType))
                {
                    RelationMember member = GetRelationMember(metaData.EntityType, property, nameToMemberMap);
                    relationMembers.Add(member);
                    continue;
                }
                PrimitiveMember member2 = GetPrimitiveMember(metaData.EntityType, property, nameToMemberMap);
                if (metaData.IdMember == null && memberName.Equals(EntityMetaData.DEFAULT_NAME_ID))
                {
                    metaData.IdMember = member2;
                    continue;
                }
                if (idMembers.Contains(member2) && !alternateIdMembers.Contains(member2) && !containedInAlternateIdMember.Contains(member2))
                {
                    continue;
                }
                if (member2.Equals(metaData.IdMember) || member2.Equals(metaData.VersionMember) || member2.Equals(metaData.CreatedByMember) ||
                    member2.Equals(metaData.CreatedOnMember) || member2.Equals(metaData.UpdatedByMember) || member2.Equals(metaData.UpdatedOnMember))
                {
                    continue;
                }
                if (metaData.VersionMember == null && memberName.Equals(EntityMetaData.DEFAULT_NAME_VERSION))
                {
                    metaData.VersionMember = member2;
                    continue;
                }
                if (metaData.CreatedByMember == null && memberName.Equals(EntityMetaData.DEFAULT_NAME_CREATED_BY))
                {
                    metaData.CreatedByMember = member2;
                }
                else if (metaData.CreatedOnMember == null && memberName.Equals(EntityMetaData.DEFAULT_NAME_CREATED_ON))
                {
                    metaData.CreatedOnMember = member2;
                }
                else if (metaData.UpdatedByMember == null && memberName.Equals(EntityMetaData.DEFAULT_NAME_UPDATED_BY))
                {
                    metaData.UpdatedByMember = member2;
                }
                else if (metaData.UpdatedOnMember == null && memberName.Equals(EntityMetaData.DEFAULT_NAME_UPDATED_ON))
                {
                    metaData.UpdatedOnMember = member2;
                }
                primitiveMembers.Add(member2);
            }
            foreach (PrimitiveMember member in primitiveMembers)
            {
                String memberName = member.Name;
                if (explicitBasicMemberNames.Contains(memberName))
                {
                    // Even if the name would match, this member was explicitly configured as "basic"
                    continue;
                }
                if (metaData.CreatedByMember == null && memberName.Equals(EntityMetaData.DEFAULT_NAME_CREATED_BY))
                {
                    metaData.CreatedByMember = member;
                }
                else if (metaData.CreatedOnMember == null && memberName.Equals(EntityMetaData.DEFAULT_NAME_CREATED_ON))
                {
                    metaData.CreatedOnMember = member;
                }
                else if (metaData.UpdatedByMember == null && memberName.Equals(EntityMetaData.DEFAULT_NAME_UPDATED_BY))
                {
                    metaData.UpdatedByMember = member;
                }
                else if (metaData.UpdatedOnMember == null && memberName.Equals(EntityMetaData.DEFAULT_NAME_UPDATED_ON))
                {
                    metaData.UpdatedOnMember = member;
                }
            }
            FilterWrongRelationMappings(relationMembers);
            // Order of setter calls is important
            PrimitiveMember[] primitives   = primitiveMembers.ToArray();
            PrimitiveMember[] alternateIds = alternateIdMembers.ToArray();
            RelationMember[]  relations    = relationMembers.ToArray();
            Array.Sort(primitives);
            Array.Sort(alternateIds);
            Array.Sort(relations);
            metaData.PrimitiveMembers   = primitives;
            metaData.AlternateIdMembers = alternateIds;
            metaData.RelationMembers    = relations;

            foreach (Member member in notMergeRelevant)
            {
                metaData.SetMergeRelevant(member, false);
            }
            if (metaData.IdMember == null)
            {
                throw new Exception("No ID member could be resolved for entity of type " + metaData.RealType);
            }
        }
コード例 #4
0
ファイル: Type.cs プロジェクト: luozhiping1987/api
 public PropertyInfo[] GetDeclaredProperties()
 {
     return(PropertyInfoProvider.GetProperties(GenericsReflection.EnsureTypeDef(this), this));
 }