예제 #1
0
        public void Build(Type type)
        {
            DbRecordInfo info = DbAttributesManager.GetRecordInfo(type);

            TableName = info.TableName;

            Dictionary <string, string> fields = accessor.LoadFields(TableName);

            FieldsToCreate = new Dictionary <string, string>();
            FieldsToUpdate = new Dictionary <string, string>();

            DbFieldCheckResult checker = new DbFieldCheckResult(accessor);

            foreach (DbFieldInfo fi in info.Fields)
            {
                checker.Process(fields, fi);

                if (checker.IsNew)
                {
                    FieldsToCreate.Add(fi.Name, checker.SqlType);
                }
                else
                if (checker.IsDifferent)
                {
                    FieldsToUpdate.Add(fi.Name, checker.SqlType);
                }
            }
        }
예제 #2
0
        public bool IsAllFieldValid(Type type)
        {
            DbRecordInfo info = DbAttributesManager.GetRecordInfo(type);
            Dictionary <string, string> fields = accessor.LoadFields(info.TableName);

            if (fields.Count == 0)
            {
                throw new NdbException("Unable to load fields for the following table: " + info.TableName);
            }

            DbFieldCheckResult checker = new DbFieldCheckResult(accessor);

            foreach (DbFieldInfo fi in info.Fields)
            {
                checker.Process(fields, fi);

                if (checker.IsNew)
                {
                    LastError = string.Format("{0} in {1} ({2}) isn't present in db"
                                              , fi.Name, type, fi.FieldType);
                    return(false);
                }

                if (checker.IsDifferent)
                {
                    LastError = string.Format("{0} in {1} is {2} but column is {3}"
                                              , fi.Name, type, fi.FieldType, checker.CurrentSqlType);
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        private static DbRecords loadRecords(Type type, IDataReader reader)
        {
            DbRecordInfo info    = DbAttributesManager.GetRecordInfo(type);
            Array        records = DbGateway.LoadRecords(type, reader, info);

            return(new DbRecords(info, records));
        }
예제 #4
0
        /// <summary>
        /// Gets the records info.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static DbRecordInfo[] GetRecordInfo(Type[] type)
        {
            var list = new DbRecordInfo[type.Length];

            for (int i = 0; i < type.Length; i++)
            {
                list[i] = GetRecordInfo(type[i]);
            }
            return(list);
        }
예제 #5
0
        public static void Map(object[] parents, object[] childs)
        {
            if (IsEmpty(parents) || IsEmpty(childs))
            {
                return;
            }

            DbRecordInfo         childRecordInfo   = DbAttributesManager.GetRecordInfo(childs[0].GetType());
            Type                 parentType        = parents[0].GetType();
            DbIdentityRecordInfo primaryRecordInfo = DbAttributesManager.GetRecordInfo(parentType) as DbIdentityRecordInfo;

            if (primaryRecordInfo == null)
            {
                throw new NdbNotIdentityException("Only DbIdentityRecord objects can have childs");
            }

            if (!primaryRecordInfo.Childs.ContainsKey(childRecordInfo.RecordType))
            {
                throw new NdbRelationException("{0} doesn't contains Childs of {1} type",
                                               primaryRecordInfo.RecordType, childRecordInfo.RecordType);
            }

            MemberInfo childReferenceField = primaryRecordInfo.Childs[childRecordInfo.RecordType];
            Type       childType           = DbFieldInfo.GetType(childReferenceField).GetElementType();

            var childsList = new List <object>(childs);

            foreach (object parent in parents)
            {
                ArrayList list    = new ArrayList();
                object    pkvalue = primaryRecordInfo.PrimaryKey.GetValue(parent);
                for (int i = childsList.Count - 1; i >= 0; i--)
                {
                    object childRecord     = childsList[i];
                    object foreignKeyValue = childRecordInfo.ForeignKeys[parentType].GetValue(childRecord);

                    if (pkvalue.Equals(foreignKeyValue))
                    {
                        Type type = parent.GetType();
                        if (childRecordInfo.Parents.ContainsKey(type))
                        {
                            DbFieldInfo.SetValue(childRecordInfo.Parents[type], childRecord, parent);
                        }

                        list.Add(childRecord);
                        childsList.RemoveAt(i);
                    }
                }

                DbFieldInfo.SetValue(childReferenceField, parent, list.ToArray(childType));
            }
        }
예제 #6
0
        /// <summary>
        /// Load Record Structure Information
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static DbRecordInfo GetRecordInfo(Type type)
        {
            lock (records)
            {
                if (!records.ContainsKey(type))
                {
                    DbRecordInfo recordInfo = LoadRecordInfo(type);

                    records.Add(type, recordInfo);
                }
            }
            return(records[type]);
        }
예제 #7
0
파일: DbRecords.cs 프로젝트: mayvazyan/ndb
 public DbRecords(DbRecordInfo recordInfo, Array list)
 {
     RecordInfo = recordInfo;
     List       = list;
 }