示例#1
0
        private VirtualKey RegisterOneToManyVKey(Type type, FieldInfo fi)
        {
            VirtualKey template;

            if (!fi.FieldType.IsGenericType)
            {
                throw new Serializer.SerializerException();
            }

            if (fi.FieldType.GetGenericArguments().Length != 1)
            {
                throw new Serializer.SerializerException();
            }

            if (AttributeWorker.GetMappedByAttribute(fi) != null)
            {
                throw new Serializer.SerializerException();
            }

            Type navigatedType = fi.FieldType.GetGenericArguments()[0];

            template = CreateTemplateEntry(type, navigatedType);

            JoinColumsAttribute[] jcs = AttributeWorker.GetJoinColumnsAttributes(fi);
            if (jcs.Length <= 0)
            {
                throw new Serializer.SerializerException();
            }

            foreach (JoinColumsAttribute jc in jcs)
            {
                Console.WriteLine(type + ":" + _worker.RetrieveField(type, jc.DefColumn, false));
                Console.WriteLine(navigatedType + ":" + _worker.RetrieveField(navigatedType, jc.JoinColumn, false));

                FieldInfo tmp = _worker.RetrieveField(type, jc.DefColumn, false);
                if (tmp == null)
                {
                    throw new Serializer.SerializerException();
                }
                template.AddDefKeyField(jc.DefColumn, tmp);
                template.SourceType = type;

                tmp = _worker.RetrieveField(navigatedType, jc.JoinColumn, false);
                if (tmp == null)
                {
                    throw new Serializer.SerializerException("Field " + jc.JoinColumn + " in " + navigatedType.FullName + " not found!");
                }

                template.AddJoinKeyField(jc.JoinColumn, tmp);
                template.TargetType = navigatedType;
                List <String> tmpList;
                try
                {
                    tmpList = _foreignKeys[navigatedType];
                }
                catch (KeyNotFoundException)
                {
                    tmpList = new List <String>();
                    _foreignKeys[navigatedType] = tmpList;
                }
                tmpList.Add(jc.JoinColumn);

                template.AddKeyTranslation(jc.DefColumn, jc.JoinColumn);

                template.SourceField = fi;
            }
            return(template);
        }
示例#2
0
        private VirtualKey RegisterManyToOneVKey(Type type, FieldInfo fi)
        {
            VirtualKey        template;
            MappedByAttribute a = AttributeWorker.GetMappedByAttribute(fi);

            if (a != null)
            {
                Type fType = fi.FieldType;

                FieldInfo tmp = _worker.RetrieveField(fType, a.MappedBy, true);

                if (tmp == null)
                {
                    throw new Serializer.SerializerException();
                }

                RelationalAttribute rTmp = AttributeWorker.GetRelationAttribute(tmp);
                if (rTmp == null || !(rTmp is OneToManyAttribute))
                {
                    throw new Serializer.SerializerException();
                }

                if (AttributeWorker.GetJoinColumnsAttributes(fi).Length > 0)
                {
                    throw new Serializer.SerializerException();
                }

                template             = CreateTemplateEntry(type, fType);
                template.TargetField = fi;
            }
            else
            {
                Type navigatedType = fi.FieldType;

                template = CreateTemplateEntry(type, navigatedType);


                JoinColumsAttribute[] jcs = AttributeWorker.GetJoinColumnsAttributes(fi);
                if (jcs.Length <= 0)
                {
                    throw new Serializer.SerializerException();
                }

                foreach (JoinColumsAttribute jc in jcs)
                {
                    Console.WriteLine(type + ":" + _worker.RetrieveField(type, jc.JoinColumn, false));
                    Console.WriteLine(navigatedType + ":" + _worker.RetrieveField(navigatedType, jc.DefColumn, false));

                    FieldInfo tmp = _worker.RetrieveField(type, jc.JoinColumn, false);
                    if (tmp == null)
                    {
                        throw new Serializer.SerializerException();
                    }

                    template.AddJoinKeyField(jc.JoinColumn, tmp);
                    template.TargetType = type;
                    List <String> tmpList;
                    try
                    {
                        tmpList = _foreignKeys[type];
                    }
                    catch (KeyNotFoundException)
                    {
                        tmpList            = new List <String>();
                        _foreignKeys[type] = tmpList;
                    }
                    tmpList.Add(jc.JoinColumn);


                    tmp = _worker.RetrieveField(navigatedType, jc.DefColumn, false);
                    if (tmp == null)
                    {
                        throw new Serializer.SerializerException();
                    }

                    template.AddDefKeyField(jc.DefColumn, tmp);
                    template.SourceType = navigatedType;

                    template.AddKeyTranslation(jc.DefColumn, jc.JoinColumn);
                    template.TargetField = fi;
                }
            }

            return(template);
        }
示例#3
0
        private VirtualKey RegisteReflexiveOneToOneDefVKey(ref Type type, FieldInfo fi)
        {
            VirtualKey template;
            Type       navigatedType = fi.FieldType;


            template = CreateTemplateEntry(type, navigatedType);

            JoinColumsAttribute[] jcs = AttributeWorker.GetJoinColumnsAttributes(fi);
            if (jcs.Length <= 0)
            {
                throw new Serializer.SerializerException();
            }

            bool dependencyResolved = false;

            foreach (JoinColumsAttribute jc in jcs)
            {
                if (_worker.RetrieveField(type, jc.DefColumn, false) != null &&
                    _worker.RetrieveField(navigatedType, jc.JoinColumn, false) != null)
                {
                    dependencyResolved = true;
                    continue;
                }
                else if (_worker.RetrieveField(navigatedType, jc.DefColumn, false) != null &&
                         _worker.RetrieveField(type, jc.JoinColumn, false) != null)
                {
                    Type tmp = navigatedType;
                    navigatedType      = type;
                    type               = tmp;
                    dependencyResolved = true;
                    continue;
                }
            }

            if (!dependencyResolved)
            {
                throw new Serializer.SerializerException();
            }

            foreach (JoinColumsAttribute jc in jcs)
            {
                Console.WriteLine(type + ":" + _worker.RetrieveField(type, jc.DefColumn, false));
                Console.WriteLine(navigatedType + ":" + _worker.RetrieveField(navigatedType, jc.JoinColumn, false));

                FieldInfo tmp = _worker.RetrieveField(type, jc.DefColumn, false);
                if (tmp == null)
                {
                    throw new Serializer.SerializerException();
                }
                template.AddDefKeyField(jc.DefColumn, tmp);
                template.SourceType = type;


                tmp = _worker.RetrieveField(navigatedType, jc.JoinColumn, false);
                if (tmp == null)
                {
                    throw new Serializer.SerializerException();
                }
                template.AddJoinKeyField(jc.JoinColumn, tmp);
                template.TargetType = navigatedType;

                List <String> tmpList;
                try
                {
                    tmpList = _foreignKeys[navigatedType];
                }
                catch (KeyNotFoundException)
                {
                    tmpList = new List <String>();
                    _foreignKeys[navigatedType] = tmpList;
                }
                tmpList.Add(jc.JoinColumn);

                template.AddKeyTranslation(jc.DefColumn, jc.JoinColumn);
                template.SourceField = fi;
                template.TargetField = fi;
            }
            return(template);
        }