예제 #1
0
        /// <summary>
        /// 根据实体状态来选择保存方法。
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="markSaved">是否当前正在保存最外层组合根对象。如果是,则应该在保存完成后,把整个组合对象状态清空。</param>
        /// <param name="withTreeChildren">是否需要同时处理树的子节点。</param>
        /// <exception cref="System.NotSupportedException"></exception>
        private void SubmitItem(Entity entity, bool markSaved, bool withTreeChildren)
        {
            //创建提交数据的参数。
            var args = new SubmitArgs
            {
                DataProvider     = _dataProvider,
                Entity           = entity,
                WithTreeChildren = withTreeChildren,
                Action           = GetAction(entity)
            };

            //提交更改。
            _submitter.Submit(args);

            //保存完毕,修改实体的状态
            switch (args.Action)
            {
            case SubmitAction.Delete:
                //在删除后,标记对象的状态到“新对象”。
                entity.PersistenceStatus = PersistenceStatus.New;
                break;

            case SubmitAction.Update:
            case SubmitAction.Insert:
            case SubmitAction.ChildrenOnly:
                if (markSaved)
                {
                    (entity as IDirtyAware).MarkSaved();
                }
                break;

            default:
                throw new NotSupportedException();
            }
        }
예제 #2
0
        /// <summary>
        /// 提交聚合对象到数据库中。
        ///
        /// 子类重写此方法实现整个聚合对象保存到非关系型数据库的逻辑。
        /// 如果只想重写单个对象的 CUD 逻辑,请重写 Insert、Update、Delete 方法。
        ///
        /// 注意,不论是聚合父对象,还是聚合子对象,还是没有聚合子的对象,都会执行该方法。
        /// 它与 Insert、Update、Delete 等方法的区别在于,重写此方法可以同时阻止对聚合子对象的默认保存逻辑。
        /// </summary>
        /// <param name="e"></param>
        internal protected virtual void Submit(SubmitArgs e)
        {
            var entity = e.Entity;

            switch (e.Action)
            {
            case SubmitAction.Delete:
                this.DoDelete(entity);
                break;

            case SubmitAction.Insert:
                this.DoInsert(entity, e.WithTreeChildren);
                break;

            case SubmitAction.Update:
                this.DoUpdate(entity, e.WithTreeChildren);
                break;

            case SubmitAction.ChildrenOnly:
                this.SubmitChildren(entity);
                if (e.WithTreeChildren && _repository.SupportTree)
                {
                    this.SubmitTreeChildren(entity);
                }
                break;

            default:
                throw new NotSupportedException();
            }
        }
예제 #3
0
        internal void Submit(SubmitArgs e)
        {
            //最后一个就是第一个。
            var first = _submitters[_submitters.Count - 1];

            first.Submit(e, this);
        }
예제 #4
0
        void ISubmitInterceptorLink.InvokeNext(SubmitInterceptor current, SubmitArgs e)
        {
            //不需要检查 Index。
            //因为作为最后一个 Submitter(DataProvider),不能再调用 GetNext 方法。
            var next = _submitters[current.SubmitInterceptorIndex - 1];

            next.Submit(e, this);
        }
예제 #5
0
파일: DataSaver.cs 프로젝트: zhuwansu/Rafy
        /// <summary>
        /// 根据实体状态来选择保存方法。
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="markSaved">是否当前正在保存最外层组合根对象。如果是,则应该在保存完成后,把整个组合对象状态清空。</param>
        /// <param name="withTreeChildren">是否需要同时处理树的子节点。</param>
        /// <exception cref="System.NotSupportedException"></exception>
        private void SubmitItem(Entity entity, bool markSaved, bool withTreeChildren)
        {
            //创建提交数据的参数。
            var args = new SubmitArgs
            {
                DataProvider     = _dataProvider,
                Entity           = entity,
                WithTreeChildren = withTreeChildren,
                Action           = GetAction(entity)
            };

            //提交更改。
            _submitter.Submit(args);

            //保存完毕,修改实体的状态
            if (markSaved)
            {
                (entity as IDirtyAware).MarkSaved();
            }
        }
예제 #6
0
 /// <summary>
 /// 提交聚合对象到数据库中。
 ///
 /// 子类重写此方法实现整个聚合对象保存到非关系型数据库的逻辑。
 /// 如果只想重写单个对象的 CUD 逻辑,请重写 Insert、Update、Delete 方法。
 /// </summary>
 /// <param name="e"></param>
 internal protected virtual void Submit(SubmitArgs e)
 {
     _dataSaver.Submit(e);
 }
예제 #7
0
 /// <summary>
 /// DataProvider 提交拦截器中的最后一个拦截器。
 /// </summary>
 /// <param name="e">The e.</param>
 /// <param name="locator">The locator.</param>
 internal protected sealed override void Submit(SubmitArgs e, ISubmitInterceptorLink locator)
 {
     this.Submit(e);
 }
예제 #8
0
 /// <summary>
 /// 提交指定的实体。
 /// 子类在此方法中,使用 locator.InvokeNext(e, this); 来调用被拦截的功能。
 /// </summary>
 /// <param name="e">提交参数,其中封装了需要对实体进行的操作。</param>
 /// <param name="link">使用此定位器来调用被拦截的实际提交器。</param>
 internal protected abstract void Submit(SubmitArgs e, ISubmitInterceptorLink link);
예제 #9
0
            protected override void Submit(SubmitArgs e)
            {
                EnsureStore();

                base.Submit(e);
            }