private bool EnlistSessionIfHasTransactionActive(String key, ISession session)
        {
            if (!_kernel.HasComponent(typeof(ITransactionManager)))
            {
                return(false);
            }

            bool enlisted = false;

            ITransactionManager manager = (ITransactionManager)_kernel[typeof(ITransactionManager)];

            Transaction transaction = manager.CurrentTransaction;

            if (transaction != null)
            {
                if (!transaction.Context.Contains(key))
                {
                    transaction.Context[key] = true;
                    transaction.Enlist(new ResourceSessionAdapter(session.BeginTransaction()));
                    transaction.RegisterSynchronization(new SessionKeeper(session, key));
                    enlisted = true;
                }
            }

            _kernel.ReleaseComponent(manager);

            return(enlisted);
        }
Пример #2
0
        private bool EnlistSessionIfHasTransactionActive(String key, SqlMapper sqlMap)
        {
            if (!_kernel.HasComponent(typeof(ITransactionManager)))
            {
                return(false);
            }

            bool enlisted = false;

            if (key == null)
            {
                key = "iBATIS.DataMapper";
            }

            ITransactionManager manager = (ITransactionManager)_kernel[typeof(ITransactionManager)];

            Transaction transaction = manager.CurrentTransaction;

            if (transaction != null)
            {
                if (!transaction.Context.Contains(key))
                {
                    transaction.Context[key] = true;
                    transaction.Enlist(new ResourceSqlMapAdapter(sqlMap.BeginTransaction(false)));
                    transaction.RegisterSynchronization(new SqlMapKeeper(sqlMap));
                    enlisted = true;
                }
            }

            _kernel.ReleaseComponent(manager);

            return(enlisted);
        }
Пример #3
0
        /// <summary>
        ///     Enlists if necessary.
        /// </summary>
        /// <param name="weAreSessionOwner">if set to <c>true</c> [we are session owner].</param>
        /// <param name="transaction">The transaction.</param>
        /// <param name="session">The session.</param>
        /// <returns></returns>
        protected bool EnlistIfNecessary(bool weAreSessionOwner,
                                         ITransaction transaction,
                                         StatelessSessionDelegate session)
        {
            if (transaction == null)
            {
                return(false);
            }

            var list = (IList <IStatelessSession>)transaction.Context["nh.statelessSession.enlisted"];

            bool shouldEnlist;

            if (list == null)
            {
                list = new List <IStatelessSession>();

                shouldEnlist = true;
            }
            else
            {
                shouldEnlist = true;

                foreach (var s in list)
                {
                    if (StatelessSessionDelegate.AreEqual(session, s))
                    {
                        shouldEnlist = false;
                        break;
                    }
                }
            }

            if (shouldEnlist)
            {
                if (session.Transaction == null || !session.Transaction.IsActive)
                {
                    transaction.Context["nh.statelessSession.enlisted"] = list;

                    var level = TranslateIsolationLevel(transaction.IsolationMode);
                    transaction.Enlist(new ResourceAdapter(session.BeginTransaction(level), transaction.IsAmbient));

                    list.Add(session);
                }

                if (weAreSessionOwner)
                {
                    transaction.RegisterSynchronization(new StatelessSessionDisposeSynchronization(session));
                }
            }

            return(true);
        }
Пример #4
0
        protected bool EnlistIfNecessary(bool weAreSessionOwner,
                                         ITransaction transaction,
                                         SessionDelegate session)
        {
            if (transaction == null)
            {
                return(false);
            }

            IList list = (IList)transaction.Context["nh.session.enlisted"];

            bool shouldEnlist;

            if (list == null)
            {
                list = new ArrayList();

                transaction.Context["nh.session.enlisted"] = list;

                shouldEnlist = true;
            }
            else
            {
                shouldEnlist = true;

                foreach (ISession sess in list)
                {
                    if (SessionDelegate.AreEqual(session, sess))
                    {
                        shouldEnlist = false;
                        break;
                    }
                }
            }

            if (shouldEnlist)
            {
                // TODO: propagate IsolationLevel, expose as transaction property

                transaction.Enlist(new ResourceAdapter(session.BeginTransaction()));

                list.Add(session);

                if (weAreSessionOwner)
                {
                    transaction.RegisterSynchronization(
                        new SessionDisposeSynchronization(session));
                }
            }

            return(true);
        }
Пример #5
0
		/// <summary>
		/// Enlists if necessary.
		/// </summary>
		/// <param name="weAreSessionOwner">if set to <c>true</c> [we are session owner].</param>
		/// <param name="transaction">The transaction.</param>
		/// <param name="session">The session.</param>
		/// <returns></returns>
		protected bool EnlistIfNecessary(bool weAreSessionOwner, 
		                                 ITransaction transaction, 
		                                 SessionDelegate session)
		{
			if (transaction == null) return false;

			IList list = (IList) transaction.Context["nh.session.enlisted"];

			bool shouldEnlist;

			if (list == null)
			{
				list = new ArrayList();

				shouldEnlist = true;
			}
			else
			{
				shouldEnlist = true;

				foreach(ISession sess in list)
				{
					if (SessionDelegate.AreEqual(session, sess))
					{
						shouldEnlist = false;
						break;
					}
				}
			}

			if (shouldEnlist)
			{
				if (!transaction.DistributedTransaction)
				{
					transaction.Context["nh.session.enlisted"] = list;

					IsolationLevel level = TranslateIsolationLevel(transaction.IsolationMode);
					transaction.Enlist(new ResourceAdapter(session.BeginTransaction(level)));

					list.Add(session);
				}

				if (weAreSessionOwner)
				{
					transaction.RegisterSynchronization(new SessionDisposeSynchronization(session));
				}
			}

			return true;
		}