Ejemplo n.º 1
0
        public virtual string Build(QueryBuilder builder, DynamicData param, DataTable table)
        {
            //代理内部默认使用映射器来构建
            if (builder.ObjectType == null)
            {
                return(string.Empty);                            //没有定义对象类型就不需要映射
            }
            var mapper = DataMapperFactory.Create(builder.ObjectType);

            return(mapper.Build(builder, param, table));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建根内部引用外部根时映射的表
        /// </summary>
        /// <param name="master"></param>
        /// <param name="memberField"></param>
        /// <param name="objectType"></param>
        /// <returns></returns>
        private static DataTable CreateAggregateRootTable(DataTable root, DataTable master, IDataField memberField, Type objectType)
        {
            //var model = DataModel.CreateNew(objectType);
            //var table = model.Root;
            //table.Root = root;
            //table.Master = master;
            //table.MemberField = memberField;
            //return table;

            var mapper       = DataMapperFactory.Create(objectType);
            var objectFields = mapper.GetObjectFields(objectType, master.IsSnapshot);
            var table        = Create(root, master, objectType, master.IsSnapshot, DataTableType.AggregateRoot, objectFields, memberField);

            return(table);
            //return DataTable.Create(root, master, objectType, DataTableType.AggregateRoot, memberField);
        }
Ejemplo n.º 3
0
        private DataTable(Type objectType,
                          bool isSnapshot,
                          DataTable chainRoot,
                          DataTable master,
                          DataTableType type,
                          string name,
                          IEnumerable <IDataField> tableFields,
                          IEnumerable <IDataField> objectFields,
                          IDataField memberField)
        {
            this.UniqueKey = GetUniqueKey(memberField, chainRoot?.Name, name);
            AddBuildtimeIndex(this);
            if (memberField != null)
            {
                memberField.Table = this;
            }


            this.Type = type;

            this.ChainRoot   = chainRoot;
            this.Master      = master;
            this.MemberField = memberField;
            this.Root        = FindActualRoot(chainRoot);
            InitObjectType(objectType, memberField?.Tip);

            this.Chain      = this.MemberField == null ? ObjectChain.Empty : new ObjectChain(this.MemberField);
            this.IsSnapshot = isSnapshot;

            this.IsMultiple = memberField == null ? false : memberField.IsMultiple;

            this.Name   = name;
            this.Fields = TidyFields(tableFields);

            this.ObjectFields = objectFields;
            this.PropertyTips = GetPropertyTips();
            InitDerived();
            InitConnectionName();
            InitTableIdName();
            InitChilds();
            InitDynamic();
            this.Mapper = DataMapperFactory.Create(this.ObjectType);
            //这里触发,是为了防止程序员在程序启动时手工初始化,但会遗漏动态表的初始化
            //所以在表构造的时候主动创建
            this.Build();
        }
Ejemplo n.º 4
0
        private static IEnumerable <string> GetIndexs()
        {
            DomainObject.CheckInitialized();

            List <string> tables = new List <string>();

            foreach (var objectType in DomainObject.TypeIndex)
            {
                if (DomainObject.IsEmpty(objectType))
                {
                    continue;
                }
                var mapper = DataMapperFactory.Create(objectType);
                var fileds = mapper.GetObjectFields(objectType, false);
                tables.Add(objectType.Name);
                tables.AddRange(DataTable.GetRelatedNames(objectType, fileds));
            }
            return(tables.Distinct());
        }
Ejemplo n.º 5
0
        internal static DataModel CreateNew(Type objectType)
        {
            var mapper = DataMapperFactory.Create(objectType);

            var objectFields = mapper.GetObjectFields(objectType, false);
            var root         = DataTable.Create(objectType, objectFields);

            DataTable snapshot = null;

            if (DomainObject.IsAggregateRoot(objectType))
            {
                var tip = ObjectRepositoryAttribute.GetTip(objectType, true);
                if (tip.Snapshot)
                {
                    var snapshotObjectFields = mapper.GetObjectFields(objectType, true);
                    snapshot = DataTable.CreateSnapshot(objectType, snapshotObjectFields);
                }
            }
            return(new DataModel(objectType, root, snapshot));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 创建实体对象的表
        /// </summary>
        /// <param name="root"></param>
        /// <param name="master"></param>
        /// <param name="memberField"></param>
        /// <param name="isMultiple"></param>
        /// <returns></returns>
        private static DataTable CreateEntityObjectTable(DataTable root, DataTable master, IDataField memberField, Type objectType)
        {
            //注意,在内聚模型中,只要是实体对象,那么它就是相对于内聚根的实体对象,而不是所在对象的实体对象
            //因此,所有的实体对象,外键存放的都是内聚根的编号
            var fields = new List <IDataField>();
            var mapper = DataMapperFactory.Create(objectType);

            fields.AddRange(mapper.GetObjectFields(objectType, master.IsSnapshot)); //增加对象定义的领域属性
            if (!objectType.IsDerived())
            {
                //派生类不必有引用次数
                fields.Add(GeneratedField.CreateAssociatedCount(objectType));//追加被引用次数
            }

            return(DataTable.Create(root,
                                    master,
                                    objectType,
                                    master.IsSnapshot,//根据从表,判断是否为快照
                                    DataTableType.EntityObject, fields, memberField));
        }
Ejemplo n.º 7
0
        private static IEnumerable <string> GetIndexs()
        {
            List <string> tables = new List <string>();

            foreach (var objectType in DomainObject.TypeIndex)
            {
                if (DomainObject.IsEmpty(objectType))
                {
                    continue;
                }
                var mapper = DataMapperFactory.Create(objectType);
                var fields = mapper.GetObjectFields(objectType, false);
                AddIndexName(tables, objectType.Name);
                var relatedNames = GetRelatedNames(objectType, fields);
                foreach (var relatedName in relatedNames)
                {
                    AddIndexName(tables, relatedName);
                }
            }
            return(tables.Distinct());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 创建值对象的表
        /// </summary>
        /// <param name="root"></param>
        /// <param name="master"></param>
        /// <param name="memberField"></param>
        /// <param name="isMultiple"></param>
        /// <returns></returns>
        private static DataTable CreateValueObjectTable(DataTable root, DataTable master, IDataField memberField, Type objectType)
        {
            var fields = new List <IDataField>();

            fields.Add(GeneratedField.CreateValueObjectPrimaryKey(objectType));  //追加主键
            var mapper = DataMapperFactory.Create(objectType);

            fields.AddRange(mapper.GetObjectFields(objectType, master.IsSnapshot)); //增加对象定义的领域属性

            if (!objectType.IsDerived())
            {
                //派生类不必追加引用次数
                fields.Add(GeneratedField.CreateAssociatedCount(objectType));//追加被引用次数
            }

            return(DataTable.Create(root,
                                    master,
                                    objectType,
                                    master.IsSnapshot,//根据主表,判断是否为快照
                                    DataTableType.ValueObject,
                                    fields,
                                    memberField));
        }