コード例 #1
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        public virtual void Assign(TMetaEntity me, CEntity rhs)
        {
            TMetaTable mt = me.MetaTable;

            TInheritMappingType   inheritType = mt.InheritMappingType;
            TMetaColumnCollection mcs         = null;

            if (inheritType == TInheritMappingType.TablePerConcreteClass)
            {
                mcs = mt.FullValueColumns;
            }
            else
            if (inheritType == TInheritMappingType.TablePerSubClass)
            {
                mcs = mt.ValueColumns;
            }

            CEntity that = rhs as CEntity;

            foreach (TMetaColumn mc in mcs)
            {
                //if (!cm.IsAssign)
                //    continue;
                if (mc.MemberName == "Captions.Cn (Assign)")
                {
                    System.Diagnostics.Debug.WriteLine(mc.MemberName);
                }

                object v2 = that.GetEpoPropertyValue(mc);
                this.SetEpoPorpertyValue(mc, v2);
            }
        }
コード例 #2
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //---------------------------------------------------------------------
        public virtual void Push(DataRow row)
        {
            TMetaEntity me = GetMetaEntity(this.GetType());

            //FillRow(me, row, e);
            this.Push(row, me);
        }
コード例 #3
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        private void Load(DataTable table, TMetaEntity me)
        {
            TMetaTable mt = me.MetaTable;

            if (table.Rows.Count == 0)
            {
                if (mt.InheritMappingType == TInheritMappingType.TablePerConcreteClass)
                {
                    throw new TFetchNoneException(this.GetType().ToString() + " Fetch None");
                }
            }

            if (table.Rows.Count == 1)
            {
                Load(table.Rows[0], me);
            }
            else if (table.Rows.Count > 1)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    sb.AppendLine(table.Rows[i]["ID"].ToString());
                }
                throw new TFetchMoreException(String.Format("{0}--Fetch More than one row{1}{2}", GetType(), Environment.NewLine, sb));
            }
        }
コード例 #4
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        // 分表储存
        private void SaveTablePerSubClass()
        {
            Type t2 = this.GetType();

            while (t2 != typeof(CEntity))
            {
                TMetaEntity         meta2       = GetMetaEntity(t2);
                TMetaTable          mt2         = meta2.MetaTable;
                TInheritMappingType inheritType = mt2.InheritMappingType;
                try
                {
                    // PerConcrete与PerSubClass同样都调用函数Save(meta)
                    // 在此函数中,去进一步区分MappingType
                    // NG
                    Save(meta2);
                }
                catch (TDataSilentlyChangedException e2)
                {
                    string trace = TEntityConcurrencyTrace.Trace(this, meta2);
                    SimpleLog.Write(trace);
                    SimpleLog.Write(e2);
                    throw e2;
                }
                t2 = t2.BaseType;
            }
        }
コード例 #5
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        public void Load(string id, TMetaEntity me)
        {
            CDataAccess access = Context.GetDataAccess(me);

            access.Context = this.Context;
            DataTable dataTable = access.SelectById(id);

            Load(dataTable, me);
        }
コード例 #6
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        public void Load(int no, TMetaEntity me)
        {
            CDataAccess access = Context.GetDataAccess(me);

            access.Context = this.Context;
            DataTable dataTable = access.SelectByNo(no);

            Load(dataTable, me);
        }
コード例 #7
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //--------------------------------------------------------------
        public bool Equals(Type t, object rhs)
        {
            if (rhs == null)
            {
                return(false);
            }

            if (object.ReferenceEquals(this, rhs))
            {
                return(true);
            }

            if (this.GetType() != rhs.GetType())
            {
                return(false);
            }

            CEntity that = rhs as CEntity;

            if (that == null)
            {
                return(false);
            }

            TMetaEntity           meta        = TMetaRegistry.Default.GetMeta(t);
            TMetaTable            mt          = meta.MetaTable;
            TInheritMappingType   inheritType = mt.InheritMappingType;
            TMetaColumnCollection mcs         = null;

            if (inheritType == TInheritMappingType.TablePerConcreteClass)
            {
                mcs = mt.FullValueColumns;
            }
            else if (inheritType == TInheritMappingType.TablePerSubClass)
            {
                mcs = mt.ValueColumns;
            }
            bool b = true;

            foreach (TMetaColumn mc in mcs)
            {
                //if (!cm.IsCompare)
                //    continue;
                if (mc.MemberName == "Captions.Cn (Equal)")
                {
                    System.Diagnostics.Debug.WriteLine(mc.MemberName);
                }
                object v1 = this.GetEpoPropertyValue(mc);
                object v2 = that.GetEpoPropertyValue(mc);
                b = b && (object.Equals(v1, v2));
            }
            b = b && (PersistState == that.PersistState);
            return(b);
        }
コード例 #8
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //---------------------------------------------------------------------
        public virtual void Pull(CEntity e, DataRow row)
        {
            TMetaEntity meta = GetMetaEntity(this.GetType());

            foreach (TMetaColumn mc in meta.MetaTable.FullValueColumns)
            {
                if (!row.Table.Columns.Contains(mc.ColumnName))
                {
                    continue;
                }
                Pull(e, row, mc);
            }
        }
コード例 #9
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        private void SaveCore()
        {
            if (PersistState == TPersistState.OpenMemory)
            {
                PersistState = TPersistState.Added;
            }

            TMetaEntity         meta        = GetMetaEntity(this.GetType());
            TInheritMappingType inheritType = meta.MetaTable.InheritMappingType;

            // PerConcrete与PerSubClass同样都调用此函数Save(meta)
            // 在此函数中,去进一步区分MappingType
            // NG

            if (inheritType == TInheritMappingType.TablePerConcreteClass)
            {
                SaveTablePerConcreteClass(meta);
            }

            else if (inheritType == TInheritMappingType.TablePerSubClass)
            {
                SaveTablePerSubClass();
            }


            if (PersistState == TPersistState.Added)
            {
                PersistState = TPersistState.Opened;
            }

            else if (PersistState == TPersistState.Opened)
            {
                PersistState = TPersistState.Opened;
            }

            else if (PersistState == TPersistState.Modified)
            {
                PersistState = TPersistState.Opened;
            }


            else if (PersistState == TPersistState.MarkDeleted)
            {
                PersistState = TPersistState.Detached;
            }


            IsMarkDelete = false;
            //SetDirty(false);
            m_Dirty = TBoolEx.Null;
        }
コード例 #10
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //---------------------------------------------------------------------
        public virtual void Push(DataRow row, TMetaEntity me)
        {
            TMetaTable          mt          = me.MetaTable;
            TInheritMappingType inheritType = me.MetaTable.InheritMappingType;

            if (inheritType == TInheritMappingType.TablePerConcreteClass)
            {
                Push(row, mt.FullValueColumns);
            }
            else if (inheritType == TInheritMappingType.TablePerSubClass)
            {
                Push(row, mt.ValueColumns);
            }
        }
コード例 #11
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        public override void Assign(object rhs)
        {
            CEntity     that = rhs as CEntity;
            TMetaEntity meta = GetMetaEntity(this.GetType());

            foreach (TMetaColumn mc in meta.MetaTable.FullValueColumns)
            {
                //if (mc.ColumnName == "CAPTIONS_CN")
                //    System.Diagnostics.Debug.WriteLine(mc.ColumnName);

                object v = that.GetEpoPropertyValue(mc);
                this.SetEpoPorpertyValue(mc, v);
            }
        }
コード例 #12
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //--------------------------------------------------------------
        // TODO: Distinguish between Equals/Equal
        public override bool Equals(object rhs)
        {
            if (rhs == null)
            {
                return(false);
            }

            if (object.ReferenceEquals(this, rhs))
            {
                return(true);
            }

            if (this.GetType() != rhs.GetType())
            {
                return(false);
            }

            CEntity that = rhs as CEntity;

            if (that == null)
            {
                return(false);
            }


            TMetaEntity me = GetMetaEntity(this.GetType());

            if (me == null)
            {
                return(base.Equals(rhs));
            }

            bool b = true;

            foreach (TMetaColumn mc in me.MetaTable.FullValueColumns)
            {
                //if (!cm.IsCompare)
                //    continue;

                object v1 = this.GetEpoPropertyValue(mc);
                object v2 = that.GetEpoPropertyValue(mc);
                b = b && (object.Equals(v1, v2));
            }

            //b = b && (PersistState == that.PersistState);

            return(b);
        }
コード例 #13
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        public virtual string CreateCoid()
        {
            string      coidPrefix;
            TMetaEntity meta = GetMetaEntity(this.GetType());

            if (meta != null)
            {
                coidPrefix = meta.MetaTable.CoidPrefix;
            }
            else
            {
                coidPrefix = String.Empty;
            }

            return(TCoid.CreateCoid(coidPrefix));
        }
コード例 #14
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
 //----------------------------------------------------------
 // 同表储存
 private void SaveTablePerConcreteClass(TMetaEntity meta)
 {
     try
     {
         // PerConcrete与PerSubClass同样都调用函数Save(meta)
         // 在此函数中,去进一步区分MappingType
         // NG
         Save(meta);
     }
     catch (TDataSilentlyChangedException e1)
     {
         string trace = TEntityConcurrencyTrace.Trace(this, meta);
         SimpleLog.Write(trace);
         SimpleLog.Write(e1);
         throw e1;
     }
 }
コード例 #15
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //---------------------------------------------------------------------
        public virtual void Pull(CEntity e, DataRow row, TMetaEntity me)
        {
            TInheritMappingType inheritType = me.MetaTable.InheritMappingType;

            if (inheritType == TInheritMappingType.TablePerConcreteClass)
            {
                foreach (TMetaColumn mc in me.MetaTable.FullValueColumns)
                {
                    Pull(e, row, mc);
                }
            }
            else if (inheritType == TInheritMappingType.TablePerSubClass)
            {
                foreach (TMetaColumn mc in me.MetaTable.ValueColumnsWithId)
                {
                    Pull(e, row, mc);
                }
            }
        }
コード例 #16
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //---------------------------------------------------------------------
        private void SaveColumnsBrutally(TMetaEntity me)
        {
            TMetaTable  mt     = me.MetaTable;
            CDataAccess access = Context.GetDataAccess(me);

            access.Context = this.Context;
            string tableName = mt.TableName;

            foreach (TMetaColumn mc in mt.Columns)
            {
                if (!mc.IsBrutallySave)
                {
                    continue;
                }

                object v        = GetEpoPropertyValue(mc);
                string strValue = null;
                switch (mc.DataType)
                {
                case TDataType.Int32:
                case TDataType.Int64:
                case TDataType.Int16:
                case TDataType.Decimal:
                    strValue = v.ToString();
                    break;

                case TDataType.String:
                    strValue = String.Format("'{0}'", v);
                    break;

                case TDataType.DateTime:
                    strValue = String.Format("'{0}'", v);
                    break;

                default:
                    strValue = v.ToString();
                    break;
                }
                string cmdText = String.Format("Update {0} set {1}={2} where ID='{3}'", mt.TableName, mc.ColumnName, strValue, Id);
                access.ExecuteNonQuery(cmdText);
            }
        }
コード例 #17
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        public virtual void InitMembers()
        {
            TMetaEntity me = GetMetaEntity(this.GetType());

            if (me == null)
            {
                return;
            }

            TMetaTable mt = me.MetaTable;

            foreach (TMetaColumn mc in mt.FullValueColumns)
            {
                TDataType dataType = mc.DataType;
                if (dataType == TDataType.DateTime || dataType == TDataType.Date)
                {
                    object nullValue = TConvert.GetNullValue(dataType);
                    this.SetEpoPorpertyValue(mc, nullValue);
                }
            }
        }
コード例 #18
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //---------------------------------------------------------
        public virtual CDataAccess GetDataAccess()
        {
            if (Context == null)
            {
                return(null);
            }

            Type        type = this.GetType();
            TMetaEntity meta = GetMetaEntity(type);

            CDataAccess access = Context.AccessCache.GetDataAccess(meta);

            if (access == null)
            {
                //TODO: DataAccess comes first from override method, then MetaEntity
                // find is there any override CreateDataAccess in exactly that hierarchy level?
                access           = CreateDataAccess();
                access.MetaTable = meta.MetaTable;
                Context.AccessCache.Register(meta, access);
            }
            access.Context = this.Context;
            return(access);
        }
コード例 #19
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        public virtual void Load(int no)
        {
            //throw new Exception("The method  is not implemented.");
            BeforeLoad();
            Type t2 = this.GetType();

            while (t2 != typeof(CEntity))
            {
                TMetaEntity         me2         = GetMetaEntity(t2);
                TMetaTable          mt2         = me2.MetaTable;
                TInheritMappingType inheritType = mt2.InheritMappingType;

                ///单表继承--单表存贮
                if (inheritType == TInheritMappingType.TablePerConcreteClass)
                {
                    Load(no, me2);
                    if (IsBakMode)
                    {
                        AcceptChanges(me2);
                    }
                    break;
                }
                /// 多表继承--分表存贮
                else if (inheritType == TInheritMappingType.TablePerSubClass)
                {
                    Load(no, me2);
                    if (IsBakMode)
                    {
                        AcceptChanges(me2);
                    }
                    t2 = t2.BaseType;
                }
            }
            PersistState = TPersistState.Opened;
            AfterLoad();
        }
コード例 #20
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        ////----------------------------------------------------------
        // 不支持继承
        //public virtual void Load(string id)
        //{
        //    DataTable dataTable = DataAccess.SelectById(id);
        //    Load(dataTable);
        //}
        //----------------------------------------------------------
        // 支持继承
        public virtual void Load(string id)
        {
            BeforeLoad();
            Type t2 = this.GetType();

            while (t2 != typeof(CEntity))
            {
                TMetaEntity         me2         = GetMetaEntity(t2);
                TMetaTable          mt2         = me2.MetaTable;
                TInheritMappingType inheritType = mt2.InheritMappingType;

                ///单表继承--单表存贮
                if (inheritType == TInheritMappingType.TablePerConcreteClass)
                {
                    Load(id, me2);
                    if (IsBakMode)
                    {
                        AcceptChanges(me2);
                    }

                    break;
                }
                /// 多表继承--分表存贮
                else if (inheritType == TInheritMappingType.TablePerSubClass)
                {
                    Load(id, me2);
                    if (IsBakMode)
                    {
                        AcceptChanges(me2);
                    }
                    t2 = t2.BaseType;
                }
            }
            PersistState = TPersistState.Opened;
            AfterLoad();
        }
コード例 #21
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
 //----------------------------------------------------------
 private void Load(DataRow row, TMetaEntity me)
 {
     Pull(this, row, me);
     //if (IsBakMode)
     //    AcceptChanges();
 }
コード例 #22
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        public virtual void Assign(Type t, CEntity rhs)
        {
            TMetaEntity me = TMetaRegistry.Default.GetMeta(t);

            Assign(me, rhs);
        }
コード例 #23
0
ファイル: Entity.cs プロジェクト: GoldyWang2013/hello-world
        //----------------------------------------------------------
        public void Save(TMetaEntity me)
        {
            // PerConcrete与PerSubClass同样都调用函数Save(meta)
            // 在此函数中,去进一步区分MappingType
            // NG

            /// 注意,Meta分级存贮。分表时要补Id

            TracSave(me);
            CDataAccess access = Context.GetDataAccess(me);

            access.Context = this.Context;

            TMetaTable mt    = me.MetaTable;
            TDataTable table = Context.CreateDataTable(mt);
            TDataRow   row   = table.CreateDataRow();

            if (PersistState == TPersistState.Added)
            {
                //FillRow(me, row, this);
                this.Push(row, me);
                table.Rows.Add(row);
                access.InsertRow(table);
                AcceptChanges(me);
            }
            else if (PersistState == TPersistState.Opened || PersistState == TPersistState.Modified)
            {
                if (me.MetaTable.InheritMappingType == TInheritMappingType.TablePerSubClass)
                {
                    if (!access.ExistId(Id))
                    {
                        //FillRow(me, row, this);
                        this.Push(row, me);
                        table.Rows.Add(row);
                        access.InsertRow(table);
                        AcceptChanges(me);
                        return;
                    }
                }

                if (IsBakMode)
                {
                    //FillRow(me, row, this.Bak1);
                    this.Bak1.Push(row, me);
                    table.Rows.Add(row);
                    row.AcceptChanges();
                }

                //FillRow(me, row, this);
                this.Push(row, me);
                access.EditRow(table);

                SaveColumnsBrutally(me);    ///

                AcceptChanges(me);
            }
            else if (PersistState == TPersistState.MarkDeleted)
            {
                //FillRow(me, row, this.Bak1);
                this.Bak1.Push(row, me);
                table.Rows.Add(row);
                row.AcceptChanges();
                row.Delete();
                access.Delete(table);
                AcceptChanges(me);
            }
        }