private void checkTransactionProperties( ITransactionAttributeSource tas, MethodInfo method, TransactionPropagation transactionPropagation )
 {
     ITransactionAttribute ta = tas.ReturnTransactionAttribute( method, null );
     Assert.IsTrue( ta != null );
     Assert.IsTrue( ta.TransactionIsolationLevel == IsolationLevel.Unspecified );
     Assert.IsTrue( ta.PropagationBehavior == transactionPropagation);
 }
 public TransactionInterceptor(
     ITransactionAttributeSource transactionAttributeSource, 
     IPlatformTransactionManager transactionManager)
 {
     TransactionAttributeSource = transactionAttributeSource;
     TransactionManager = transactionManager;
 }
        private void checkTransactionProperties(ITransactionAttributeSource tas, MethodInfo method, TransactionPropagation transactionPropagation)
        {
            ITransactionAttribute ta = tas.ReturnTransactionAttribute(method, null);

            Assert.IsTrue(ta != null);
            Assert.IsTrue(ta.TransactionIsolationLevel == IsolationLevel.ReadCommitted);
            Assert.IsTrue(ta.PropagationBehavior == transactionPropagation);
        }
 /// <summary>
 /// Sets the tx attribute source.
 /// </summary>
 /// <param name="transactionInterceptor">The transaction interceptor.</param>
 protected void SetTxAttributeSource(TransactionInterceptor transactionInterceptor)
 {
     if (transactionInterceptor.TransactionAttributeSource == null)
     {
         throw new AopConfigException("Cannot construct a TransactionAttributeSourceAdvisor using a " +
                                      "TransactionInterceptor that has no TransactionAttributeSource configured.");
     }
     _transactionAttributeSource = transactionInterceptor.TransactionAttributeSource;
 }
Beispiel #5
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="Spring.Transaction.Interceptor.DefaultTransactionAttributeSourceAdvisor"/> class.
 /// </summary>
 public DefaultTransactionAttributeSourceAdvisor(ITransactionAttributeSource transactionAttributeSource, IAdvice advice)
     : base(advice)
 {
     if (transactionAttributeSource == null)
     {
         throw new AopConfigException("Cannot construct a DefaultTransactionAttributeSourceAdvisor if " +
                                      "TransactionAttributeSource is null.");
     }
     _transactionAttributeSource = transactionAttributeSource;
 }
		/// <summary>
		/// Creates a new instance of the
        /// <see cref="Spring.Transaction.Interceptor.DefaultTransactionAttributeSourceAdvisor"/> class.
		/// </summary>
        public DefaultTransactionAttributeSourceAdvisor(ITransactionAttributeSource transactionAttributeSource, IAdvice advice)
			: base( advice )
		{
            if (transactionAttributeSource == null)
			{
                throw new AopConfigException("Cannot construct a DefaultTransactionAttributeSourceAdvisor if " + 
					"TransactionAttributeSource is null.");
			}
            _transactionAttributeSource = transactionAttributeSource;
		}
        public void Null()
        {
            TransactionAttributeSourceEditor pe = new TransactionAttributeSourceEditor();

            pe.SetAsText(null);
            ITransactionAttributeSource tas = pe.Value;
            MethodInfo m = typeof(object).GetMethod("GetHashCode");

            Assert.IsTrue(tas.ReturnTransactionAttribute(m, null) == null);
        }
        public void MatchesAll()
        {
            TransactionAttributeSourceEditor pe = new TransactionAttributeSourceEditor();

            pe.SetAsText("System.Object.*, Mscorlib=PROPAGATION_REQUIRED");
            ITransactionAttributeSource tas = pe.Value;

            checkTransactionProperties(tas, typeof(object).GetMethod("GetHashCode"), TransactionPropagation.Required);
            checkTransactionProperties(tas, typeof(object).GetMethod("Equals", new Type[] { typeof(object) }), TransactionPropagation.Required);
            checkTransactionProperties(tas, typeof(object).GetMethod("GetType"), TransactionPropagation.Required);
            checkTransactionProperties(tas, typeof(object).GetMethod("ToString"), TransactionPropagation.Required);
        }
 protected override object Advised(object target, IPlatformTransactionManager ptm,
                                   ITransactionAttributeSource tas)
 {
     TransactionInterceptor ti = new TransactionInterceptor();
     ti.TransactionManager = ptm;
     Assert.AreEqual(ptm, ti.TransactionManager);
     ti.TransactionAttributeSource = tas;
     Assert.AreEqual(tas, ti.TransactionAttributeSource);
     ProxyFactory pf = new ProxyFactory(target);
     pf.AddAdvice(0, ti);
     return pf.GetProxy();
 }
        protected override object Advised(object target, IPlatformTransactionManager ptm,
                                          ITransactionAttributeSource tas)
        {
            TransactionInterceptor ti = new TransactionInterceptor();

            ti.TransactionManager = ptm;
            Assert.AreEqual(ptm, ti.TransactionManager);
            ti.TransactionAttributeSource = tas;
            Assert.AreEqual(tas, ti.TransactionAttributeSource);
            ProxyFactory pf = new ProxyFactory(target);

            pf.AddAdvice(0, ti);
            return(pf.GetProxy());
        }
        public void MatchesSpecific()
        {
            TransactionAttributeSourceEditor pe = new TransactionAttributeSourceEditor();

            pe.SetAsText("System.Object.GetHashCode, Mscorlib =PROPAGATION_REQUIRED\n" +
                         "System.Object.Equals, Mscorlib =PROPAGATION_MANDATORY\n" +
                         "System.Object.*pe, Mscorlib=PROPAGATION_SUPPORTS");
            ITransactionAttributeSource tas = pe.Value;

            checkTransactionProperties(tas, typeof(object).GetMethod("GetHashCode"), TransactionPropagation.Required);
            checkTransactionProperties(tas, typeof(object).GetMethod("Equals", new Type[] { typeof(object) }), TransactionPropagation.Mandatory);
            checkTransactionProperties(tas, typeof(object).GetMethod("GetType"), TransactionPropagation.Supports);
            checkTransactionProperties(tas, typeof(object).GetMethod("ToString"));
        }
Beispiel #12
0
        public void RollbackRules()
        {
            TransactionInterceptor txInterceptor = ctx.GetObject("txRollbackAdvice") as TransactionInterceptor;

            Assert.IsNotNull(txInterceptor);

            MethodInfo getDescriptionMethod          = typeof(ITestObject).GetMethod("GetDescription");
            MethodInfo exceptionalMethod             = typeof(ITestObject).GetMethod("Exceptional");
            ITransactionAttributeSource txAttrSource = txInterceptor.TransactionAttributeSource;
            ITransactionAttribute       txAttr       = txAttrSource.ReturnTransactionAttribute(getDescriptionMethod, typeof(ITestObject));

            Assert.IsTrue(txAttr.RollbackOn(new System.ApplicationException()));

            txAttr = txAttrSource.ReturnTransactionAttribute(exceptionalMethod, typeof(ITestObject));
            Assert.IsFalse(txAttr.RollbackOn(new System.ArithmeticException()));
        }
        /// <summary>
        /// Parses the input properties <see cref="System.String"/> into a valid
        /// <see cref="Spring.Transaction.Interceptor.ITransactionAttributeSource"/>
        /// instance
        /// </summary>
        /// <param name="attributeSource">The properties string to be parsed.</param>
        public void SetAsText(string attributeSource)
        {
            MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource();

            if (attributeSource == null || attributeSource.Length == 0)
            {
                _attributeSource = null;
            }
            else
            {
                PropertiesEditor           editor = new PropertiesEditor(attributeSource);
                TransactionAttributeEditor tae    = new TransactionAttributeEditor();

                foreach (string name in editor.Keys)
                {
                    string value = editor[name];
                    tae.SetAsText(value);
                    ITransactionAttribute transactionAttribute = tae.Value;
                    source.AddTransactionalMethod(name, transactionAttribute);
                }
            }
            _attributeSource = source;
        }
 private void checkTransactionProperties( ITransactionAttributeSource tas, MethodInfo method )
 {
     ITransactionAttribute ta = tas.ReturnTransactionAttribute( method, null );
     Assert.IsNull(ta);
 }
 protected abstract object Advised(object target, IPlatformTransactionManager ptm,
                                   ITransactionAttributeSource tas);
        /// <summary>
        /// Sets the tx attribute source.
        /// </summary>
        /// <param name="transactionInterceptor">The transaction interceptor.</param>
	    protected void SetTxAttributeSource(TransactionInterceptor transactionInterceptor)
	    {
	        if (transactionInterceptor.TransactionAttributeSource == null)
	        {
	            throw new AopConfigException("Cannot construct a TransactionAttributeSourceAdvisor using a " +
	                                         "TransactionInterceptor that has no TransactionAttributeSource configured.");
	        }
	        _transactionAttributeSource = transactionInterceptor.TransactionAttributeSource;
	    }
        /// <summary>
        /// Does the supplied <paramref name="method"/> satisfy this matcher?
        /// </summary>
        /// <remarks>
        /// <p>
        /// Must be implemented by a derived class in order to specify matching
        /// rules.
        /// </p>
        /// </remarks>
        /// <param name="method">The candidate method.</param>
        /// <param name="targetType">
        /// The target <see cref="System.Type"/> (may be <see langword="null"/>,
        /// in which case the candidate <see cref="System.Type"/> must be taken
        /// to be the <paramref name="method"/>'s declaring class).
        /// </param>
        /// <returns>
        /// <see langword="true"/> if this this method matches statically.
        /// </returns>
        public override bool Matches(MethodInfo method, Type targetType)
        {
            ITransactionAttributeSource tas = TransactionAttributeSource;

            return(tas == null || TransactionAttributeSource.ReturnTransactionAttribute(method, targetType) != null);
        }
		/// <summary>
		/// Parses the input properties <see cref="System.String"/> into a valid
		/// <see cref="Spring.Transaction.Interceptor.ITransactionAttributeSource"/>
		/// instance
		/// </summary>
		/// <param name="attributeSource">The properties string to be parsed.</param>
		public void SetAsText( string attributeSource )
		{
			MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource();
			if ( attributeSource == null || attributeSource.Length == 0 )
			{
				_attributeSource = null;
			} else
			{
				PropertiesEditor editor = new PropertiesEditor(attributeSource);
				TransactionAttributeEditor tae = new TransactionAttributeEditor();

				foreach ( string name in editor.Keys )
				{
					string value = editor[name];
					tae.SetAsText( value );
					ITransactionAttribute transactionAttribute = tae.Value;
					source.AddTransactionalMethod( name, transactionAttribute );
				}
			}
			_attributeSource = source;
		}
 protected abstract object Advised(object target, IPlatformTransactionManager ptm,
                                        ITransactionAttributeSource tas);
        private void checkTransactionProperties(ITransactionAttributeSource tas, MethodInfo method)
        {
            ITransactionAttribute ta = tas.ReturnTransactionAttribute(method, null);

            Assert.IsNull(ta);
        }