Exemplo n.º 1
0
        public IObjRef EntityToObjRef(Object entity, int idIndex, IEntityMetaData metaData, bool forceOri)
        {
            Object id;
            Object version;
            Member versionMember = metaData.VersionMember;

            if (entity is AbstractCacheValue)
            {
                AbstractCacheValue cacheValue = (AbstractCacheValue)entity;
                if (idIndex == ObjRef.PRIMARY_KEY_INDEX)
                {
                    id = cacheValue.Id;
                }
                else
                {
                    id = CompositeIdFactory.CreateIdFromPrimitives(metaData, idIndex, cacheValue);
                }
                version = cacheValue.Version;
            }
            else if (entity is ILoadContainer)
            {
                ILoadContainer lc = (ILoadContainer)entity;
                if (idIndex == ObjRef.PRIMARY_KEY_INDEX)
                {
                    id = lc.Reference.Id;
                }
                else
                {
                    id = CompositeIdFactory.CreateIdFromPrimitives(metaData, idIndex, lc.Primitives);
                }
                version = lc.Reference.Version;
            }
            else
            {
                id      = metaData.GetIdMemberByIdIndex(idIndex).GetValue(entity, false);
                version = versionMember != null?versionMember.GetValue(entity, false) : null;
            }
            IObjRef ori;

            if (id != null || forceOri)
            {
                ori = ObjRefFactory.CreateObjRef(metaData.EntityType, idIndex, id, version);
            }
            else
            {
                ori = new DirectObjRef(metaData.EntityType, entity);
            }

            return(ori);
        }
Exemplo n.º 2
0
        protected Member GetMemberIntern(Type type, String propertyName, Type baseType)
        {
            if (propertyName.Contains("&"))
            {
                String[]          compositePropertyNames = propertyName.Split('&');
                PrimitiveMember[] members = new PrimitiveMember[compositePropertyNames.Length];
                for (int a = compositePropertyNames.Length; a-- > 0;)
                {
                    members[a] = (PrimitiveMember)GetMemberIntern(type, compositePropertyNames[a], baseType);
                }
                return(CompositeIdFactory.CreateCompositeIdMember(type, members));
            }
            Type enhancedType = GetMemberTypeIntern(type, propertyName, baseType);

            if (enhancedType == baseType)
            {
                throw new Exception("Must never happen. No enhancement for " + baseType + " has been done");
            }
            ConstructorInfo constructor = enhancedType.GetConstructor(Type.EmptyTypes);

            return((Member)constructor.Invoke(EMPTY_OBJECTS));
        }
Exemplo n.º 3
0
        protected PrimitiveMember HandleMemberConfig(IEntityMetaData metaData, Type realType, IMemberConfig memberConfig,
                                                     IMap <String, Member> explicitMemberNameToMember, IMap <String, Member> allMemberNameToMember)
        {
            if (memberConfig == null)
            {
                return(null);
            }
            if (!(memberConfig is CompositeMemberConfig))
            {
                PrimitiveMember member = HandleMemberConfigIfNew(realType, memberConfig.Name, explicitMemberNameToMember);
                explicitMemberNameToMember.Put(memberConfig.Name, member);
                ((IPrimitiveMemberWrite)member).SetTransient(memberConfig.Transient);

                PrimitiveMember definedBy = memberConfig.DefinedBy != null?HandleMemberConfigIfNew(realType, memberConfig.DefinedBy,
                                                                                                   allMemberNameToMember) : null;

                ((IPrimitiveMemberWrite)member).SetDefinedBy(definedBy);
                return(member);
            }
            MemberConfig[]    memberConfigs = ((CompositeMemberConfig)memberConfig).GetMembers();
            PrimitiveMember[] members       = new PrimitiveMember[memberConfigs.Length];
            for (int a = memberConfigs.Length; a-- > 0;)
            {
                MemberConfig    memberPart = memberConfigs[a];
                PrimitiveMember member     = HandleMemberConfigIfNew(realType, memberPart.Name, explicitMemberNameToMember);
                members[a] = member;
            }
            PrimitiveMember compositeIdMember = CompositeIdFactory.CreateCompositeIdMember(metaData, members);

            explicitMemberNameToMember.Put(memberConfig.Name, compositeIdMember);
            ((IPrimitiveMemberWrite)compositeIdMember).SetTransient(memberConfig.Transient);

            PrimitiveMember definedBy2 = memberConfig.DefinedBy != null?HandleMemberConfigIfNew(realType, memberConfig.DefinedBy, allMemberNameToMember)
                                             : null;

            ((IPrimitiveMemberWrite)compositeIdMember).SetDefinedBy(definedBy2);
            return(compositeIdMember);
        }