コード例 #1
0
        IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, ClearDependenceInfo depend, EntityDTO masterEntity)
        {
            var list = core.UoW.Session.CreateCriteria(ObjectClass)
                       .Add(Restrictions.Eq(depend.PropertyName + ".Id", (int)masterEntity.Id)).List();

            return(MakeResultList(list));
        }
コード例 #2
0
        internal override void Execute(IDeleteCore core, CancellationToken cancellation)
        {
            if (cancellation.IsCancellationRequested)
            {
                return;
            }

            ChildBeforeOperations.ForEach(o => o.Execute(core, cancellation));

            if (cancellation.IsCancellationRequested)
            {
                return;
            }

            core.AddExcuteOperation(String.Format("Удаляем из таблицы {0}", TableName));
            core.ExecuteSql(
                String.Format("DELETE FROM {0} {1}", TableName, WhereStatment),
                ItemId);

            if (cancellation.IsCancellationRequested)
            {
                return;
            }

            ChildAfterOperations.ForEach(o => o.Execute(core, cancellation));
        }
コード例 #3
0
        IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, DeleteDependenceInfo depend, EntityDTO masterEntity)
        {
            if (depend.PropertyName != null)
            {
                var list = core.UoW.Session.CreateCriteria(ObjectClass)
                           .Add(Restrictions.Eq(depend.PropertyName + ".Id", (int)masterEntity.Id)).List();

                return(MakeResultList(list));
            }
            else if (depend.CollectionName != null)
            {
                CheckAndLoadEntity(core, masterEntity);
                return(MakeResultList(
                           masterEntity.Entity.GetPropertyValue(depend.CollectionName) as IList));
            }
            else if (depend.ParentPropertyName != null)
            {
                CheckAndLoadEntity(core, masterEntity);
                var value = (TEntity)masterEntity.Entity.GetPropertyValue(depend.ParentPropertyName);

                return(MakeResultList(value == null ? new List <TEntity>() : new List <TEntity> {
                    value
                }));
            }

            throw new NotImplementedException();
        }
コード例 #4
0
        internal override void Execute(IDeleteCore core)
        {
            var sql = $"UPDATE {TableName} SET {CleanField} = NULL " + WhereStatment;

            core.AddExcuteOperation(String.Format("Очищаем ссылки в таблице {0}", TableName));
            core.ExecuteSql(sql, ItemId);
        }
コード例 #5
0
        IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, DeleteDependenceInfo depend, EntityDTO masterEntity)
        {
            if (depend.PropertyName != null)
            {
                var list = core.UoW.Session.CreateCriteria(ObjectClass)
                           .Add(Restrictions.Eq(depend.PropertyName + ".Id", (int)masterEntity.Id)).List();

                return(MakeResultList(list));
            }
            else if (depend.CollectionName != null)
            {
                CheckAndLoadEntity(core, masterEntity);
                return(MakeResultList(
                           masterEntity.Entity.GetPropertyValue(depend.CollectionName) as IList));
            }
            else if (depend.ParentPropertyName != null)
            {
                CheckAndLoadEntity(core, masterEntity);
                var value = (TEntity)masterEntity.Entity.GetPropertyValue(depend.ParentPropertyName);
                try {
                    NHibernateUtil.Initialize(value);
                }
                catch (ObjectNotFoundException ex) {
                    logger.Error($"{masterEntity.ClassType}#{masterEntity.Id}.{depend.ParentPropertyName} ссылается на {ex.EntityName}, но его нет в базе данных.");
                    value = null;
                    masterEntity.Entity.SetPropertyValue(depend.ParentPropertyName, null);
                }
                return(MakeResultList(value == null ? new List <TEntity>() : new List <TEntity> {
                    value
                }));
            }

            throw new NotImplementedException();
        }
コード例 #6
0
        internal override void Execute(IDeleteCore core, CancellationToken cancellation)
        {
            if (cancellation.IsCancellationRequested)
            {
                return;
            }

            ChildBeforeOperations.ForEach(o => o.Execute(core, cancellation));

            if (cancellation.IsCancellationRequested)
            {
                return;
            }

            core.AddExcuteOperation(String.Format("Удаляем {0}", DomainHelper.GetSubjectNames(DeletingItems[0].Entity)?.NominativePlural));
            foreach (var item in DeletingItems)
            {
                if (cancellation.IsCancellationRequested)
                {
                    return;
                }

                logger.Debug($"Удаляем [{item.Id}] {item.Title}...");
                core.UoW.TryDelete(item.Entity);
            }

            if (cancellation.IsCancellationRequested)
            {
                return;
            }

            ChildAfterOperations.ForEach(o => o.Execute(core, cancellation));
        }
コード例 #7
0
        internal override void Execute(IDeleteCore core)
        {
            core.AddExcuteOperation(String.Format("Очищаем коллекции в {0}", DomainHelper.GetSubjectNames(RemoveInClassType).NominativePlural));
            var collectionProp = RemoveInClassType.GetProperty(CollectionName);
            var removeMethod   = String.IsNullOrEmpty(RemoveMethodName) ? null : RemoveInClassType.GetMethod(RemoveMethodName);

            foreach (var item in RemoveInItems)
            {
                logger.Debug("Удаляем {2} из коллекции {0} в {1}...", CollectionName, item.Title, RemovingEntity.Title);
                if (removeMethod != null)
                {
                    if (item.Entity is IBusinessObject)
                    {
                        (item.Entity as IBusinessObject).UoW = core.UoW;
                    }
                    removeMethod.Invoke(item.Entity, new object[] { RemovingEntity.Entity });
                }
                else
                {
                    var collection = (IList)collectionProp.GetValue(item.Entity, null);
                    collection.Remove(RemovingEntity.Entity);
                }
                core.UoW.TrySave(item.Entity);
            }
        }
コード例 #8
0
        IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, RemoveFromDependenceInfo depend, EntityDTO masterEntity)
        {
            var list = core.UoW.Session.CreateCriteria(ObjectClass)
                       .CreateAlias(depend.CollectionName, "childs")
                       .Add(Restrictions.Eq(String.Format("childs.Id", depend.CollectionName), (int)masterEntity.Id)).List();

            return(MakeResultList(list));
        }
コード例 #9
0
        internal override void Execute(IDeleteCore core)
        {
            ChildBeforeOperations.ForEach(o => o.Execute(core));

            core.AddExcuteOperation(String.Format("Удаляем из таблицы {0}", TableName));
            core.ExecuteSql(
                String.Format("DELETE FROM {0} {1}", TableName, WhereStatment),
                ItemId);

            ChildAfterOperations.ForEach(o => o.Execute(core));
        }
コード例 #10
0
        EntityDTO IDeleteInfo.GetSelfEntity(IDeleteCore core, uint id)
        {
            var item = core.UoW.GetById <TEntity> ((int)id);

            return(new EntityDTO {
                Id = (uint)item.Id,
                ClassType = ObjectClass,
                Title = DomainHelper.GetObjectTilte(item),
                Entity = item
            });
        }
コード例 #11
0
        internal override void Execute(IDeleteCore core, CancellationToken cancellation)
        {
            if (cancellation.IsCancellationRequested)
            {
                return;
            }

            var sql = $"UPDATE {TableName} SET {CleanField} = NULL " + WhereStatment;

            core.AddExcuteOperation(String.Format("Очищаем ссылки в таблице {0}", TableName));
            core.ExecuteSql(sql, ItemId);
        }
コード例 #12
0
        internal override void Execute(IDeleteCore core)
        {
            core.AddExcuteOperation(String.Format("Очищаем ссылки в {0}", DomainHelper.GetSubjectNames(EntityType).NominativePlural));
            var propertyCache = EntityType.GetProperty(PropertyName);

            foreach (var item in ClearingItems)
            {
                logger.Debug("Очищаем свойство {0} в {1}...", PropertyName, item.Title);
                propertyCache.SetValue(item.Entity, null, null);
                core.UoW.TrySave(item.Entity);
            }
        }
コード例 #13
0
        internal override void Execute(IDeleteCore core)
        {
            ChildBeforeOperations.ForEach(o => o.Execute(core));

            core.AddExcuteOperation(String.Format("Удаляем {0}", DomainHelper.GetSubjectNames(DeletingItems[0].Entity).NominativePlural));
            foreach (var item in DeletingItems)
            {
                logger.Debug("Удаляем {0}...", item.Title);
                core.UoW.TryDelete(item.Entity);
            }

            ChildAfterOperations.ForEach(o => o.Execute(core));
        }
コード例 #14
0
        private bool CheckAndLoadEntity(IDeleteCore core, EntityDTO entity)
        {
            if (entity.Entity != null)
            {
                return(true);
            }

            if (entity.ClassType == null)
            {
                throw new InvalidOperationException("EntityDTO без указания класса не может использоваться в связке с NHibernate");
            }

            entity.Entity = core.UoW.GetById(entity.ClassType, (int)entity.Id);
            return(entity.Entity != null);
        }
コード例 #15
0
 internal abstract void Execute(IDeleteCore core, CancellationToken cancellation);
コード例 #16
0
ファイル: DeleteInfo.cs プロジェクト: Enzogord/QSProjects
 EntityDTO IDeleteInfo.GetSelfEntity(IDeleteCore core, uint id)
 {
     return(GetEntitiesList(String.Format("WHERE {0}.id = @id", TableName), id)[0]);
 }
コード例 #17
0
ファイル: DeleteInfo.cs プロジェクト: Enzogord/QSProjects
 IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, DeleteDependenceInfo depend, EntityDTO masterEntity)
 {
     return(GetEntitiesList(depend.WhereStatment, masterEntity.Id));
 }
コード例 #18
0
 internal abstract void Execute(IDeleteCore core);
コード例 #19
0
 EntityDTO IDeleteInfo.GetSelfEntity(IDeleteCore core, uint id)
 {
     return(GetEntitiesList(core.UoW.Session.Connection, String.Format("WHERE {0}.id = @id", TableName), id)[0]);
 }
コード例 #20
0
 IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, RemoveFromDependenceInfo depend, EntityDTO masterEntity)
 {
     throw new NotImplementedException();
 }
コード例 #21
0
 IList <EntityDTO> IDeleteInfo.GetDependEntities(IDeleteCore core, ClearDependenceInfo depend, EntityDTO masterEntity)
 {
     return(GetEntitiesList(core.UoW.Session.Connection, depend.WhereStatment, masterEntity.Id));
 }