public void RuleBasedTransactionAttributeToString()
        {
            RuleBasedTransactionAttribute source = new RuleBasedTransactionAttribute();

            source.PropagationBehavior       = TransactionPropagation.Supports;
            source.TransactionIsolationLevel = IsolationLevel.RepeatableRead;
            source.TransactionTimeout        = 10;
            source.ReadOnly = true;
            source.AddRollbackRule(new RollbackRuleAttribute("ArgumentException"));
            source.AddRollbackRule(new NoRollbackRuleAttribute("IllegalTransactionStateException"));

            TransactionAttributeEditor editor = new TransactionAttributeEditor();

            editor.SetAsText(source.ToString());
            ITransactionAttribute ta = editor.Value;

            Assert.AreEqual(source, ta);
            Assert.AreEqual(ta.PropagationBehavior, TransactionPropagation.Supports);
            Assert.AreEqual(ta.TransactionIsolationLevel, IsolationLevel.RepeatableRead);
            Assert.AreEqual(ta.TransactionTimeout, 10);
            Assert.IsTrue(ta.ReadOnly);
            Assert.IsTrue(ta.RollbackOn(new ArgumentException()));
            Assert.IsFalse(ta.RollbackOn(new IllegalTransactionStateException()));

            source.ClearRollbackRules();
            Assert.IsFalse(ta == source);
            source.AddRollbackRule(new RollbackRuleAttribute("ArgumentException"));
            source.AddRollbackRule(new NoRollbackRuleAttribute("IllegalTransactionStateException"));
            Assert.AreEqual(ta, source);
        }
        public void RuleBasedTransactionAttributeToString()
        {
            RuleBasedTransactionAttribute source = new RuleBasedTransactionAttribute();
            source.PropagationBehavior = TransactionPropagation.Supports;
            source.TransactionIsolationLevel = IsolationLevel.RepeatableRead;
            source.TransactionTimeout = 10;
            source.ReadOnly = true;
            source.AddRollbackRule( new RollbackRuleAttribute("ArgumentException"));
            source.AddRollbackRule( new NoRollbackRuleAttribute("IllegalTransactionStateException"));

            TransactionAttributeEditor editor = new TransactionAttributeEditor();
            editor.SetAsText( source.ToString() );
            ITransactionAttribute ta = editor.Value;
            Assert.AreEqual( source, ta );
            Assert.AreEqual( ta.PropagationBehavior, TransactionPropagation.Supports );
            Assert.AreEqual( ta.TransactionIsolationLevel, IsolationLevel.RepeatableRead );
            Assert.AreEqual( ta.TransactionTimeout, 10 );
            Assert.IsTrue( ta.ReadOnly );
            Assert.IsTrue(ta.RollbackOn(new ArgumentException()));
            Assert.IsFalse( ta.RollbackOn(new IllegalTransactionStateException()));

            source.ClearRollbackRules();
            Assert.IsFalse( ta == source );
            source.AddRollbackRule( new RollbackRuleAttribute("ArgumentException"));
            source.AddRollbackRule( new NoRollbackRuleAttribute("IllegalTransactionStateException"));
            Assert.AreEqual( ta, source );
        }
예제 #3
0
 /// <summary>
 /// Parses the input properties string into a valid <see cref="Spring.Transaction.Interceptor.ITransactionAttribute"/>
 /// instance
 /// </summary>
 /// <param name="transactionProperties">
 /// The string defining the transactional properties.
 /// </param>
 public void SetAsText(string transactionProperties)
 {
     if (!StringUtils.HasText(transactionProperties))
     {
         _attribute = null;
     }
     else
     {
         string[] tokens = StringUtils.CommaDelimitedListToStringArray(transactionProperties);
         RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute();
         for (int i = 0; i < tokens.Length; i++)
         {
             string token = tokens[i].Trim();
             if (token.StartsWith(DefaultTransactionAttribute.PROPAGATION_CONSTANT_PREFIX))
             {
                 attribute.PropagationBehavior = convertPropagationValue(token);
             }
             else if (token.StartsWith(DefaultTransactionAttribute.ISOLATION_CONSTANT_PREFIX))
             {
                 attribute.TransactionIsolationLevel = convertIsolationValue(token);
             }
             else if (token.StartsWith(DefaultTransactionAttribute.TIMEOUT_PREFIX))
             {
                 string value = token.Substring(DefaultTransactionAttribute.TIMEOUT_PREFIX.Length);
                 attribute.TransactionTimeout = Convert.ToInt32(value);
             }
             else if (token.StartsWith(DefaultTransactionAttribute.READ_ONLY_MARKER))
             {
                 attribute.ReadOnly = true;
             }
             else if (token.StartsWith(DefaultTransactionAttribute.COMMIT_RULE_PREFIX))
             {
                 attribute.AddRollbackRule(new NoRollbackRuleAttribute(token.Substring(1)));
             }
             else if (token.StartsWith(DefaultTransactionAttribute.ROLLBACK_RULE_PREFIX))
             {
                 attribute.AddRollbackRule(new RollbackRuleAttribute(token.Substring(1)));
             }
             else
             {
                 throw new ArgumentException("Illegal transaction attribute token: [" + token + "]");
             }
         }
         _attribute = attribute;
     }
 }
		/// <summary>
		/// Parses the input properties string into a valid <see cref="Spring.Transaction.Interceptor.ITransactionAttribute"/>
		/// instance
		/// </summary>
		/// <param name="transactionProperties">
		/// The string defining the transactional properties.
		/// </param>
		public void SetAsText( string transactionProperties )
		{
			if (!StringUtils.HasText(transactionProperties))
			{
				_attribute = null;
			}
			else
			{
				string[] tokens = StringUtils.CommaDelimitedListToStringArray( transactionProperties );
				RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute();
				for ( int i = 0; i < tokens.Length; i++ )
				{
					string token = tokens[i].Trim();
					if ( token.StartsWith(DefaultTransactionAttribute.PROPAGATION_CONSTANT_PREFIX))
					{
						attribute.PropagationBehavior = convertPropagationValue( token );
					} else if ( token.StartsWith(DefaultTransactionAttribute.ISOLATION_CONSTANT_PREFIX ) )
					{
						attribute.TransactionIsolationLevel = convertIsolationValue( token );
					} else if ( token.StartsWith(DefaultTransactionAttribute.TIMEOUT_PREFIX ) )
					{
						string value = token.Substring(DefaultTransactionAttribute.TIMEOUT_PREFIX.Length);
						attribute.TransactionTimeout = Convert.ToInt32( value );
					} else if ( token.StartsWith( DefaultTransactionAttribute.READ_ONLY_MARKER ) )
					{
						attribute.ReadOnly = true;
					} else if ( token.StartsWith( DefaultTransactionAttribute.COMMIT_RULE_PREFIX ) )
					{
						attribute.AddRollbackRule( new NoRollbackRuleAttribute(token.Substring( 1 ) ) );
					} else if ( token.StartsWith( DefaultTransactionAttribute.ROLLBACK_RULE_PREFIX ) )
					{
						attribute.AddRollbackRule( new RollbackRuleAttribute( token.Substring( 1 ) ) );
					} else
					{
						throw new ArgumentException("Illegal transaction attribute token: [" + token + "]");
					}		
				}
				_attribute = attribute;
			}
		}