/// <summary> /// Return the transaction attribute, given this set of attributes /// attached to a method or class. Return null if it's not transactional. /// </summary> /// <remarks> /// Protected rather than private as subclasses may want to customize /// how this is done: for example, returning a /// <see cref="Spring.Transaction.Interceptor.ITransactionAttribute"/> /// affected by the values of other attributes. /// This implementation takes into account /// <see cref="Spring.Transaction.Interceptor.RollbackRuleAttribute"/>s, if /// the TransactionAttribute is a RuleBasedTransactionAttribute. /// </remarks> /// <param name="attributes"> /// Attributes attached to a method or class. May be null, in which case a null /// <see cref="Spring.Transaction.Interceptor.ITransactionAttribute"/> will be returned. /// </param> /// <returns> /// The <see cref="ITransactionAttribute"/> configured transaction attribute, or null /// if none was found. /// </returns> protected virtual ITransactionAttribute FindTransactionAttribute(Attribute[] attributes) { if (null == attributes) { return(null); } ITransactionAttribute transactionAttribute = null; foreach (Attribute currentAttribute in attributes) { transactionAttribute = currentAttribute as ITransactionAttribute; if (null != transactionAttribute) { break; } } RuleBasedTransactionAttribute ruleBasedTransactionAttribute = transactionAttribute as RuleBasedTransactionAttribute; if (null != ruleBasedTransactionAttribute) { IList rollbackRules = new LinkedList(); foreach (Attribute currentAttribute in attributes) { RollbackRuleAttribute rollbackRuleAttribute = currentAttribute as RollbackRuleAttribute; if (null != rollbackRuleAttribute) { rollbackRules.Add(rollbackRuleAttribute); } } ruleBasedTransactionAttribute.RollbackRules = rollbackRules; return(ruleBasedTransactionAttribute); } return(transactionAttribute); }
public void AlwaysTrue() { RollbackRuleAttribute rr = new RollbackRuleAttribute("System.Exception"); Assert.IsTrue(rr.GetDepth(typeof (SystemException)) > 0); Assert.IsTrue(rr.GetDepth(typeof (ApplicationException)) > 0); Assert.IsTrue(rr.GetDepth(typeof (DataException)) > 0); Assert.IsTrue(rr.GetDepth(typeof (TransactionSystemException)) > 0); }
public void AlwaysTrue() { RollbackRuleAttribute rr = new RollbackRuleAttribute("System.Exception"); Assert.IsTrue(rr.GetDepth(typeof(SystemException)) > 0); Assert.IsTrue(rr.GetDepth(typeof(ApplicationException)) > 0); Assert.IsTrue(rr.GetDepth(typeof(DataException)) > 0); Assert.IsTrue(rr.GetDepth(typeof(TransactionSystemException)) > 0); }
protected override ITransactionAttribute FindTransactionAttribute(Attribute[] attributes) { if (attributes == null) { return(null); } foreach (Attribute attr in attributes) { if (attr is TransactionAttribute) { TransactionAttribute ta = (TransactionAttribute)attr; RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute(); //TODO another reminder to sync property names rbta.PropagationBehavior = ta.TransactionPropagation; rbta.TransactionIsolationLevel = ta.IsolationLevel; rbta.ReadOnly = ta.ReadOnly; rbta.TransactionTimeout = ta.Timeout; #if NET_2_0 rbta.EnterpriseServicesInteropOption = ta.EnterpriseServicesInteropOption; #endif Type[] rbf = ta.RollbackFor; IList rollBackRules = new ArrayList(); if (rbf != null) { foreach (Type t in rbf) { RollbackRuleAttribute rule = new RollbackRuleAttribute(t); rollBackRules.Add(rule); } } Type[] nrbfc = ta.NoRollbackFor; if (nrbfc != null) { foreach (Type t in nrbfc) { NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(t); rollBackRules.Add(rule); } } rbta.RollbackRules = rollBackRules; return(rbta); } } return(null); }
/// <summary> /// Override of <see cref="System.Object.Equals(object)"/>. /// </summary> /// <param name="obj">The object to compare.</param> /// <returns><b>True</b> if the input object is equal to this instance.</returns> public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) { return(true); } RollbackRuleAttribute rollbackRuleAttribute = obj as RollbackRuleAttribute; if (rollbackRuleAttribute == null) { return(false); } return(Equals(rollbackRuleAttribute)); }
/// <summary> /// Will a transaction be rolled back if the supplied <parameref name="exception"/> /// is thrown during the lifecycle of a transaction to which this attribute is applied? /// </summary> /// <param name="exception">The offending <see cref="System.Exception"/>.</param> /// <returns>True if the exception should cause a rollback, false otherwise.</returns> public override bool RollbackOn(Exception exception) { RollbackRuleAttribute finalAttribute = null; int deepest = Int32.MaxValue; if (_rollbackRules != null) { foreach (RollbackRuleAttribute rule in _rollbackRules) { int depth = rule.GetDepth(exception); if ((depth >= 0) && (depth < deepest)) { deepest = depth; finalAttribute = rule; } } } if (null == finalAttribute) { return(base.RollbackOn(exception)); } return(!(finalAttribute is NoRollbackRuleAttribute)); }
protected override ITransactionAttribute FindTransactionAttribute(Attribute[] attributes) { if (attributes == null) { return null; } foreach (Attribute attr in attributes) { if (attr is TransactionAttribute) { TransactionAttribute ta = (TransactionAttribute)attr; RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute(); //TODO another reminder to sync property names rbta.PropagationBehavior = ta.TransactionPropagation; rbta.TransactionIsolationLevel = ta.IsolationLevel; rbta.ReadOnly = ta.ReadOnly; rbta.TransactionTimeout = ta.Timeout; #if NET_2_0 rbta.EnterpriseServicesInteropOption = ta.EnterpriseServicesInteropOption; #endif Type[] rbf = ta.RollbackFor; IList rollBackRules = new ArrayList(); if (rbf != null) { foreach (Type t in rbf) { RollbackRuleAttribute rule = new RollbackRuleAttribute(t); rollBackRules.Add(rule); } } Type[] nrbfc = ta.NoRollbackFor; if (nrbfc != null) { foreach (Type t in nrbfc) { NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(t); rollBackRules.Add(rule); } } rbta.RollbackRules = rollBackRules; return rbta; } } return null; }
public void Ancestry() { RollbackRuleAttribute rr = new RollbackRuleAttribute("System.Exception"); Assert.IsTrue(rr.GetDepth(typeof (DataException)) == 2); }
public void NotFound() { RollbackRuleAttribute rr = new RollbackRuleAttribute("System.Data.DataException"); Assert.IsTrue(rr.GetDepth(typeof (ApplicationException)) == -1); }
public void FoundImmediatelyWithType() { RollbackRuleAttribute rr = new RollbackRuleAttribute(typeof (Exception)); Assert.IsTrue(rr.GetDepth(typeof (Exception)) == 0); }
/// <summary> /// Strongly typed <c>Equals()</c> implementation. /// </summary> /// <param name="rollbackRuleAttribute"> /// The <see cref="Spring.Transaction.Interceptor.RollbackRuleAttribute"/> to compare. /// </param> /// <returns> /// <b>True</b> if the input object is equal to the supplied <paramref name="rollbackRuleAttribute"/>. /// </returns> public bool Equals(RollbackRuleAttribute rollbackRuleAttribute) { return(base.Equals(rollbackRuleAttribute)); }
/// <summary> /// Strongly typed <c>Equals()</c> implementation. /// </summary> /// <param name="rollbackRuleAttribute"> /// The <see cref="Spring.Transaction.Interceptor.RollbackRuleAttribute"/> to compare. /// </param> /// <returns> /// <b>True</b> if the input object is equal to the supplied <paramref name="rollbackRuleAttribute"/>. /// </returns> public bool Equals( RollbackRuleAttribute rollbackRuleAttribute ) { return base.Equals(rollbackRuleAttribute); }
/// <summary> /// Adds a <see cref="Spring.Transaction.Interceptor.RollbackRuleAttribute"/> to this /// attributes list of rollback rules. /// </summary> /// <param name="rule"> /// The <see cref="Spring.Transaction.Interceptor.RollbackRuleAttribute"/> to add. /// </param> public void AddRollbackRule( RollbackRuleAttribute rule ) { _rollbackRules.Add( rule ); }
/// <summary> /// Adds a <see cref="Spring.Transaction.Interceptor.RollbackRuleAttribute"/> to this /// attributes list of rollback rules. /// </summary> /// <param name="rule"> /// The <see cref="Spring.Transaction.Interceptor.RollbackRuleAttribute"/> to add. /// </param> public void AddRollbackRule(RollbackRuleAttribute rule) { _rollbackRules.Add(rule); }
public void FoundImmediatelyWithType() { RollbackRuleAttribute rr = new RollbackRuleAttribute(typeof(Exception)); Assert.IsTrue(rr.GetDepth(typeof(Exception)) == 0); }
public void Ancestry() { RollbackRuleAttribute rr = new RollbackRuleAttribute("System.Exception"); Assert.IsTrue(rr.GetDepth(typeof(DataException)) == 2); }
public void NotFound() { RollbackRuleAttribute rr = new RollbackRuleAttribute("System.Data.DataException"); Assert.IsTrue(rr.GetDepth(typeof(ApplicationException)) == -1); }