Example #1
0
 private static void updateSingle(IEntity obj, EntityInfo entityInfo)
 {
     if (DbContext.shouldTransaction())
     {
         var        conn = DbContext.getConnection(entityInfo);
         IDbCommand cmd  = DataFactory.GetCommand(getUpdateSql(entityInfo), conn);
         if (cmd.Connection.State == Data.ConnectionState.Closed)
         {
             cmd.Connection.Open();
             OrmHelper.initCount++;
             LogManager.GetLogger("Class:System.ORM.Operation.UpdateOperation Method:updateSingle").Info("数据库连接已开启【" + OrmHelper.initCount + "】");
         }
         OrmHelper.SetParameters(cmd, "update", obj, entityInfo);
         DataFactory.SetParameter(cmd, "Id", obj.Id);
         cmd.ExecuteNonQuery();
     }
     else
     {
         using (var conn = DbContext.getConnection(entityInfo))
         {
             IDbCommand cmd = DataFactory.GetCommand(getUpdateSql(entityInfo), DbContext.getConnection(entityInfo));
             if (cmd.Connection.State == Data.ConnectionState.Closed)
             {
                 cmd.Connection.Open();
                 OrmHelper.initCount++;
                 LogManager.GetLogger("Class:System.ORM.Operation.UpdateOperation Method:updateSingle").Info("数据库连接已开启【" + OrmHelper.initCount + "】");
             }
             OrmHelper.SetParameters(cmd, "update", obj, entityInfo);
             DataFactory.SetParameter(cmd, "Id", obj.Id);
             cmd.ExecuteNonQuery();
         }
     }
 }
Example #2
0
        private static void updateSingle(IEntity obj, EntityInfo entityInfo)
        {
            IDbCommand cmd = DataFactory.GetCommand(getUpdateSql(entityInfo), DbContext.getConnection(entityInfo));

            OrmHelper.SetParameters(cmd, "update", obj, entityInfo);
            DataFactory.SetParameter(cmd, "Id", obj.Id);
            cmd.ExecuteNonQuery();
        }
Example #3
0
        private static Result Insert(IEntity obj, EntityInfo entityInfo, Boolean isInsertParent)
        {
            Result result = Validator.Validate(obj, "insert");

            if (result.HasErrors)
            {
                return(result);
            }

            if (isInsertParent && entityInfo.Parent != null)
            {
                IEntity objP = Entity.New(entityInfo.Type.BaseType.FullName);
                List <EntityPropertyInfo> eplist = Entity.GetInfo(objP).SavedPropertyList;
                foreach (EntityPropertyInfo info in eplist)
                {
                    if (info.IsList)
                    {
                        continue;
                    }
                    objP.set(info.Name, obj.get(info.Name));
                }
                ObjectDB.Insert(objP);

                obj.Id = objP.Id;
            }

            List <IInterceptor> ilist = MappingClass.Instance.InterceptorList;

            for (int i = 0; i < ilist.Count; i++)
            {
                ilist[i].BeforInsert(obj);
            }

            IDbCommand cmd = DataFactory.GetCommand(getInsertSql(entityInfo), DbContext.getConnection(entityInfo));

            OrmHelper.SetParameters(cmd, "insert", obj, entityInfo);

            lock (objLock) {
                executeCmd(cmd, entityInfo, ref obj);
            }

            for (int i = 0; i < ilist.Count; i++)
            {
                ilist[i].AfterInsert(obj);
            }
            CacheUtil.CheckCountCache("insert", obj, entityInfo);
            result.Info = obj;

            CacheTime.updateTable(obj.GetType());

            return(result);
        }
Example #4
0
        private static Result Insert(IEntity obj, EntityInfo entityInfo, Boolean isInsertParent)
        {
            Result result = Validator.Validate(obj, "insert");

            if (result.HasErrors)
            {
                return(result);
            }

            if (isInsertParent && entityInfo.Parent != null)
            {
                IEntity objP = Entity.New(entityInfo.Type.BaseType.FullName);
                List <EntityPropertyInfo> eplist = Entity.GetInfo(objP).SavedPropertyList;
                foreach (EntityPropertyInfo info in eplist)
                {
                    if (info.IsList)
                    {
                        continue;
                    }
                    objP.set(info.Name, obj.get(info.Name));
                }
                ObjectDb.Insert(objP);

                obj.Id = objP.Id;
            }

            List <IInterceptor> ilist = MappingClass.Instance.InterceptorList;

            for (int i = 0; i < ilist.Count; i++)
            {
                ilist[i].BeforInsert(obj);
            }
            var conn = DbContext.getConnection(entityInfo);

            if (conn.State == System.Data.ConnectionState.Closed)
            {
                conn.Open();
                OrmHelper.initCount++;
                LogManager.GetLogger("Class:System.Data.InsertOperation Method:Insert").Info("数据库连接已开启【" + OrmHelper.initCount + "】");
            }
            IDbCommand cmd = DataFactory.GetCommand(getInsertSql(entityInfo), conn);

            OrmHelper.SetParameters(cmd, "insert", obj, entityInfo);
            obj.Id = executeCmd(cmd, entityInfo);
            if (!DbContext.shouldTransaction())
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                    OrmHelper.clostCount++;
                    LogManager.GetLogger("Class:System.ORM.Operation.InsertOperation Method:Insert").Info("数据库连接已关闭【" + OrmHelper.clostCount + "】");
                }
            }
            for (int i = 0; i < ilist.Count; i++)
            {
                ilist[i].AfterInsert(obj);
            }
            CacheUtil.CheckCountCache("insert", obj, entityInfo);
            result.Info = obj;

            CacheTime.updateTable(obj.GetType());

            return(result);
        }