Ejemplo n.º 1
0
 public void BeginReserved(string reservationName, RocketUnitOfWorkOptions options)
 {
     if (!TryBeginReserved(reservationName, options))
     {
         throw new RocketException($"Could not find a reserved unit of work with reservation name: {reservationName}");
     }
 }
Ejemplo n.º 2
0
        public virtual void Initialize(RocketUnitOfWorkOptions options)
        {
            Check.NotNull(options, nameof(options));

            if (Options != null)
            {
                throw new RocketException("This unit of work is already initialized before!");
            }

            Options    = _defaultOptions.Normalize(options.Clone());
            IsReserved = false;
        }
        internal RocketUnitOfWorkOptions Normalize(RocketUnitOfWorkOptions options)
        {
            if (options.IsolationLevel == null)
            {
                options.IsolationLevel = IsolationLevel;
            }

            if (options.Timeout == null)
            {
                options.Timeout = Timeout;
            }

            return(options);
        }
Ejemplo n.º 4
0
        private RocketUnitOfWorkOptions CreateOptions(IRocketMethodInvocation invocation, [CanBeNull] UnitOfWorkAttribute unitOfWorkAttribute)
        {
            var options = new RocketUnitOfWorkOptions();

            unitOfWorkAttribute?.SetOptions(options);

            if (unitOfWorkAttribute?.IsTransactional == null)
            {
                options.IsTransactional = _defaultOptions.CalculateIsTransactional(
                    autoValue: !invocation.Method.Name.StartsWith("Get", StringComparison.InvariantCultureIgnoreCase)
                    );
            }

            return(options);
        }
Ejemplo n.º 5
0
        public IUnitOfWork Begin(RocketUnitOfWorkOptions options, bool requiresNew = false)
        {
            Check.NotNull(options, nameof(options));

            var currentUow = Current;

            if (currentUow != null && !requiresNew)
            {
                return(new ChildUnitOfWork(currentUow));
            }

            var unitOfWork = CreateNewUnitOfWork();

            unitOfWork.Initialize(options);

            return(unitOfWork);
        }
Ejemplo n.º 6
0
        //TODO: 考虑实现更多的构造方法

        public virtual void SetOptions(RocketUnitOfWorkOptions options)
        {
            if (IsTransactional.HasValue)
            {
                options.IsTransactional = IsTransactional.Value;
            }

            if (Timeout.HasValue)
            {
                options.Timeout = Timeout;
            }

            if (IsolationLevel.HasValue)
            {
                options.IsolationLevel = IsolationLevel;
            }
        }
Ejemplo n.º 7
0
        public bool TryBeginReserved(string reservationName, RocketUnitOfWorkOptions options)
        {
            Check.NotNull(reservationName, nameof(reservationName));

            var uow = _ambientUnitOfWork.UnitOfWork;

            //工作单元解析
            while (uow != null && !uow.IsReservedFor(reservationName))
            {
                uow = uow.Outer;
            }

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

            uow.Initialize(options);

            return(true);
        }
Ejemplo n.º 8
0
 public void Initialize(RocketUnitOfWorkOptions options)
 {
     _parent.Initialize(options);
 }