//~ Methods ////////////////////////////////////////////////////////////////
        public override ICollection GetKeys(String prefix, int type)
        {
            lock (this)
            {

                IList result = new LinkedList();
                foreach(String key in Map.Keys){

                    if ((prefix == null) || key.StartsWith(prefix))
                    {
                        if (type == 0)
                        {
                            result.Add(key);
                        }
                        else
                        {
                            ValueEntry v = (ValueEntry) Map[key];

                            if (v.type == type)
                            {
                                result.Add(key);
                            }
                        }
                    }
                }

                Collections.Sort(result);

                return result;
            }
        }
			public void RuleForSelectiveRollbackOnCheckedWithClass()
		{
			IList list = new LinkedList();
			list.Add( new RollbackRuleAttribute(typeof(TransactionSystemException)));
			RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute( TransactionPropagation.Required, list );
			ruleForSelectionRollbackOnChecked( rta );
		}
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CachedSession"/> class.
 /// </summary>
 /// <param name="targetSession">The target session.</param>
 /// <param name="sessionList">The session list.</param>
 /// <param name="ccf">The CachingConnectionFactory.</param>
 public CachedSession(ISession targetSession, LinkedList sessionList, CachingConnectionFactory ccf)
 {
     target = targetSession;
     this.sessionList = sessionList;
     sessionCacheSize = ccf.SessionCacheSize;
     shouldCacheProducers = ccf.CacheProducers;
     shouldCacheConsumers = ccf.CacheConsumers;
     this.ccf = ccf;
 }
			public void RuleForCommitOnSubclassOfChecked()
		{
			IList list = new LinkedList();
			list.Add( new RollbackRuleAttribute("System.Data.DataException"));
			list.Add( new NoRollbackRuleAttribute("Spring.Transaction.TransactionSystemException"));
			RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute( TransactionPropagation.Required, list );
			
			Assert.IsTrue( rta.RollbackOn(new SystemException()));
			Assert.IsFalse( rta.RollbackOn(new TransactionSystemException()));																		 
		}
		public void AddMultipleObjects()
		{
			LinkedList ll = new LinkedList();
			ll.Add("item1");
			ll.Add("item2");
			ll.Add("item3");
			Assert.IsTrue(ll.Count == 3, "Expected 3 items not " + ll.Count);
			Assert.IsTrue(ll[0].Equals("item1"), "Expected first element to be \"item1\" not " + ll[0]);
			Assert.IsTrue(ll[1].Equals("item2"), "Expected second element to be \"item2\" not " + ll[1]);
		}
		public void Insert()
		{
			LinkedList ll = new LinkedList();
			ll.Add("item1");
			ll.Add("item2");
			ll.Insert(1, "item1andahalf");
			Assert.IsTrue(ll.Count == 3, "Expected 3 items not " + ll.Count);
			Assert.IsTrue(ll[0].Equals("item1"), "Expected first element to be \"item1\" not " + ll[0]);
			Assert.IsTrue(ll[1].Equals("item1andahalf"), "Expected second element to be \"item1andahalf\" not " + ll[1]);
			Assert.IsTrue(ll[2].Equals("item2"), "Expected third element to be \"item2\" not " + ll[0]);
		}
		public void RemoveAt()
		{
			LinkedList ll = new LinkedList();
			ll.Add("item1");
			ll.Add("item2");
			ll.Add("item3");
			ll.RemoveAt(1);
			Assert.IsTrue(ll.Count == 2, "Expected 2 items not " + ll.Count);
			Assert.IsTrue(ll[0].Equals("item1"), "Expected first element to be \"item1\" not " + ll[0]);
			Assert.IsTrue(ll[1].Equals("item3"), "Expected second element to be \"item3\" not " + ll[1]);
		}
			public void RollbackNever()
		{
			IList list = new LinkedList();
			list.Add( new NoRollbackRuleAttribute("System.Exception"));
			RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute( TransactionPropagation.Required, list );

			Assert.IsFalse(rta.RollbackOn(new SystemException()));
			Assert.IsFalse(rta.RollbackOn(new DataException()));
			Assert.IsFalse(rta.RollbackOn(new ApplicationException()));
			Assert.IsFalse(rta.RollbackOn(new TransactionSystemException()));
		}
			public void RuleForRollbackOnApplicationException()
		{
			IList list = new LinkedList();
			list.Add(new RollbackRuleAttribute("Spring.Transaction.TransactionSystemException"));
			RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute( TransactionPropagation.Required, list );

			Assert.IsTrue( rta.RollbackOn(new SystemException()));
            //mlp 3/17 changed rollback to rollback on all exceptions.
			Assert.IsTrue( rta.RollbackOn(new ApplicationException()));
			Assert.IsTrue(( rta.RollbackOn( new TransactionSystemException())));
		}
		public void RemoveObject()
		{
			string item1 = "item1";
			string item2 = "item2";
			string item3 = "item3";
			LinkedList ll = new LinkedList();
			ll.Add(item1);
			ll.Add(item2);
			ll.Add(item3);
			ll.Remove(item2);
			Assert.IsTrue(ll.Count == 2, "Expected 2 items not " + ll.Count);
			Assert.IsTrue(ll[0].Equals("item1"), "Expected first element to be \"item1\" not " + ll[0]);
			Assert.IsTrue(ll[1].Equals("item3"), "Expected second element to be \"item3\" not " + ll[1]);
		}
		public void RemoveAtOnEmptyLinkedList()
		{
			LinkedList ll = new LinkedList();
			Assert.Throws<ArgumentOutOfRangeException>(() => ll.RemoveAt(0));
		}
 /// <summary>
 /// Wraps the given Session so that it delegates every method call to the target session but
 /// adapts close calls. This is useful for allowing application code to
 /// handle a special framework Session just like an ordinary Session.
 /// </summary>
 /// <param name="targetSession">The original Session to wrap.</param>
 /// <param name="sessionList">The List of cached Sessions that the given Session belongs to.</param>
 /// <returns>The wrapped Session</returns>
 protected virtual ISession GetCachedSessionWrapper(ISession targetSession, LinkedList sessionList)
 {
     return new CachedSession(targetSession, sessionList, this);
 }
		public void ConstructorWithIList()
		{
			ArrayList al = new ArrayList();
			al.Add("al1");
			al.Add("al2");
			al.Add("al3");
			LinkedList ll = new LinkedList(al);
			Assert.IsTrue(ll.Count == 3, "Expected 3 items not " + ll.Count);
			Assert.IsTrue(ll[0].Equals("al1"), "Expected first element to be \"al1\" not " + ll[0]);
			Assert.IsTrue(ll[1].Equals("al2"), "Expected second element to be \"al2\" not " + ll[1]);
		}
        /// <summary>
        /// Obtaining a cached Session.
        /// </summary>
        /// <param name="con">The connection to operate on.</param>
        /// <param name="mode">The session ack mode.</param>
        /// <returns>The Session to use
        /// </returns>
        public override ISession GetSession(IConnection con, SessionMode mode)
        {
            LinkedList sessionList;
            lock (cachedSessions)
            {
                sessionList = (LinkedList) cachedSessions[mode];
                if (sessionList == null)
                {
                    sessionList = new LinkedList();
                    cachedSessions.Add(mode, sessionList);
                }
            }

            ISession session = null;
            lock (sessionList)
            {
                if (sessionList.Count > 0)
                {
                    session = (ISession) sessionList[0];
                    sessionList.RemoveAt(0);
                }
            }
            if (session != null)
            {
                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug("Found cached Session for mode " + mode + ": "
                              + (session is IDecoratorSession ? ((IDecoratorSession) session).TargetSession : session));
                }
            } else
            {
                ISession targetSession = CreateSession(con, mode);
                if (LOG.IsDebugEnabled)
                {
                    LOG.Debug("Creating cached Session for mode " + mode + ": " + targetSession);
                }
                session = GetCachedSessionWrapper(targetSession, sessionList);
            }
            return session;
        }
		public void CopyToWithNegativeIndex()
		{
			LinkedList ll = new LinkedList();
			ll.Add("item1");
			string[] strings = new string[1];
            Assert.Throws<ArgumentOutOfRangeException>(() => ll.CopyTo(strings, -1));
		}
		public void CopyToWithNullArray()
		{
			LinkedList ll = new LinkedList();
			ll.Add("item1");
            Assert.Throws<ArgumentNullException>(() => ll.CopyTo(null, 0));
		}
		public void CopyToWithNonZeroIndex()
		{
			LinkedList ll = new LinkedList();
			ll.Add("item1");
			ll.Add("item2");
			ll.Add("item3");
			string[] strings = new string[5];
			strings[0] = "string1";
			strings[1] = "string2";
			ll.CopyTo(strings, 2);
			Assert.IsTrue(strings[0].Equals("string1"), "Expected first element to be \"string1\" not " + strings[0]);
			Assert.IsTrue(strings[1].Equals("string2"), "Expected second element to be \"string2\" not " + strings[1]);
			Assert.IsTrue(strings[2].Equals("item1"), "Expected third element to be \"item1\" not " + strings[2]);
			Assert.IsTrue(strings[3].Equals("item2"), "Expected fourth element to be \"item2\" not " + strings[3]);
			Assert.IsTrue(strings[4].Equals("item3"), "Expected fifth element to be \"item3\" not " + strings[4]);
		}
		public void CopyToWithZeroIndex()
		{
			LinkedList ll = new LinkedList();
			ll.Add("item1");
			ll.Add("item2");
			ll.Add("item3");
			string[] strings = new string[3];
			ll.CopyTo(strings, 0);
			Assert.IsTrue(strings[0].Equals("item1"), "Expected first element to be \"item1\" not " + strings[0]);
			Assert.IsTrue(strings[1].Equals("item2"), "Expected second element to be \"item2\" not " + strings[1]);
			Assert.IsTrue(strings[2].Equals("item3"), "Expected third element to be \"item3\" not " + strings[2]);
		}
		public void IndexOfObject()
		{
			string item1 = "item1";
			string item2 = "item2";
			string item3 = "item3";
			LinkedList ll = new LinkedList();
			ll.Add(item1);
			ll.Add(item2);
			ll.Add(item3);
			int index = ll.IndexOf(item2);
			Assert.IsTrue(index == 1, "Expected index of 1 not " + index);
		}
Beispiel #20
0
			public LinkedListEnumerator(LinkedList ll)
			{
				this._ll = ll;
				this._modId = ll._modId;
				this._current = _ll._rootNode;
			}
		/// <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 Enumerator()
		{
			LinkedList ll = new LinkedList();
			ll.Add("item1");
			ll.Add("item2");
			ll.Add("item3");
			IEnumerator ienum = ll.GetEnumerator();
			Assert.IsTrue(ienum.MoveNext());
			Assert.IsTrue(ienum.Current.Equals("item1"), "Expected first element to be \"item1\" not " + ienum.Current);
			Assert.IsTrue(ienum.MoveNext());
			Assert.IsTrue(ienum.Current.Equals("item2"), "Expected second element to be \"item2\" not " + ienum.Current);
		}
		public void CopyToWithIndexGreaterThanArrayLength()
		{
			LinkedList ll = new LinkedList();
			ll.Add("item1");
			string[] strings = new string[1];
            Assert.Throws<ArgumentOutOfRangeException>(() => ll.CopyTo(strings, 2));
		}
		public void EnumeratorModification()
		{
			LinkedList ll = new LinkedList();
			ll.Add("item1");
			ll.Add("item2");
			ll.Add("item3");
			IEnumerator ienum = ll.GetEnumerator();
			Assert.IsTrue(ienum.MoveNext());
			ll.RemoveAt(0);
            Assert.Throws<InvalidOperationException>(() => ienum.MoveNext());
		}
 /// <summary>
 /// Adds the session and connection to the list of resources managed by this holder.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <param name="connection">The connection.</param>
 public void AddSession(ISession session, IConnection connection)
 {
     AssertUtils.IsTrue(!frozen, "Cannot add ISession because MessageResourceHolder is frozen");
     AssertUtils.ArgumentNotNull(session, "ISession must not be null");
     if (!sessions.Contains(session))
     {
         sessions.Add(session);
         if (connection != null)
         {
             IList sessionsList = (IList)sessionsPerIConnection[connection];
             if (sessionsList == null)
             {
                 sessionsList = new LinkedList();
                 sessionsPerIConnection[connection] = sessionsList;
             }
             sessionsList.Add(session);
         }
     }
 }
		public void CopyToWithInsufficientSizeArray()
		{
			LinkedList ll = new LinkedList();
			ll.Add("item1");
			ll.Add("item2");
			string[] strings = new string[2];
            Assert.Throws<ArgumentException>(() => ll.CopyTo(strings, 1));
		}
        /// <summary>
        /// Create an array of arguments to invoke a constructor or static factory method,
        /// given the resolved constructor arguments values.
        /// </summary>
        /// <remarks>When return value is null the out parameter UnsatisfiedDependencyExceptionData will contain
        /// information for use in throwing a UnsatisfiedDependencyException by the caller.  This avoids using
        /// exceptions for flow control as in the original implementation.</remarks>
        private ArgumentsHolder CreateArgumentArray(string objectName, RootObjectDefinition rod, ConstructorArgumentValues resolvedValues, ObjectWrapper wrapper, Type[] paramTypes, MethodBase methodOrCtorInfo, bool autowiring, out UnsatisfiedDependencyExceptionData unsatisfiedDependencyExceptionData)
        {
            string methodType = (methodOrCtorInfo is ConstructorInfo) ? "constructor" : "factory method";
            unsatisfiedDependencyExceptionData = null;

            ArgumentsHolder args = new ArgumentsHolder(paramTypes.Length);
            ISet usedValueHolders = new HybridSet();
            IList autowiredObjectNames = new LinkedList();
            bool resolveNecessary = false;

            ParameterInfo[] argTypes = methodOrCtorInfo.GetParameters();

            for (int paramIndex = 0; paramIndex < paramTypes.Length; paramIndex++)
            {
                Type paramType = paramTypes[paramIndex];

                string parameterName = argTypes[paramIndex].Name;
                // If we couldn't find a direct match and are not supposed to autowire,
                // let's try the next generic, untyped argument value as fallback:
                // it could match after type conversion (for example, String -> int).               
                ConstructorArgumentValues.ValueHolder valueHolder = null;
                if (resolvedValues.GetNamedArgumentValue(parameterName) != null)
                {
                    valueHolder = resolvedValues.GetArgumentValue(parameterName, paramType, usedValueHolders);
                }
                else
                {
                    valueHolder = resolvedValues.GetArgumentValue(paramIndex, paramType, usedValueHolders);
                }


                if (valueHolder == null && !autowiring)
                {
                    valueHolder = resolvedValues.GetGenericArgumentValue(null, usedValueHolders);
                }
                if (valueHolder != null)
                {
                    // We found a potential match - let's give it a try.
                    // Do not consider the same value definition multiple times!
                    usedValueHolders.Add(valueHolder);
                    args.rawArguments[paramIndex] = valueHolder.Value;
                    try
                    {
                        object originalValue = valueHolder.Value;
                        object convertedValue = TypeConversionUtils.ConvertValueIfNecessary(paramType, originalValue, null);
                        args.arguments[paramIndex] = convertedValue;

                        //?
                        args.preparedArguments[paramIndex] = convertedValue;
                    }
                    catch (TypeMismatchException ex)
                    {
                        //To avoid using exceptions for flow control, this is not a cost in Java as stack trace is lazily created.
                        string errorMessage = String.Format(CultureInfo.InvariantCulture,
                                   "Could not convert {0} argument value [{1}] to required type [{2}] : {3}",
                                   methodType, valueHolder.Value,
                                   paramType, ex.Message);
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, errorMessage);
                        return null;
                    }
                }
                else
                {
                    // No explicit match found: we're either supposed to autowire or
                    // have to fail creating an argument array for the given constructor.
                    if (!autowiring)
                    {
                        string errorMessage = String.Format(CultureInfo.InvariantCulture,
                                  "Ambiguous {0} argument types - " +
                                  "Did you specify the correct object references as {0} arguments?",
                                  methodType);
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, errorMessage);

                        return null;
                    }
                    try
                    {
                        MethodParameter param = MethodParameter.ForMethodOrConstructor(methodOrCtorInfo, paramIndex);
                        object autowiredArgument = ResolveAutoWiredArgument(param, objectName, autowiredObjectNames);
                        args.rawArguments[paramIndex] = autowiredArgument;
                        args.arguments[paramIndex] = autowiredArgument;
                        args.preparedArguments[paramIndex] = new AutowiredArgumentMarker();
                        resolveNecessary = true;
                    }
                    catch (ObjectsException ex)
                    {
                        unsatisfiedDependencyExceptionData = new UnsatisfiedDependencyExceptionData(paramIndex, paramType, ex.Message);

                        return null;
                    }

                }
            }
            foreach (string autowiredObjectName in autowiredObjectNames)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Autowiring by type from object name '" + objectName +
                         "' via " + methodType + " to object named '" + autowiredObjectName + "'");
                }
            }


            return args;

        }
		public void Contains()
		{
			LinkedList ll = new LinkedList();
			Assert.IsFalse(ll.Contains("Foo"));
            
			ll = new LinkedList();
			Assert.IsFalse(ll.Contains(null));
			ll.Add("Foo");
			ll.Add(null);
			ll.Add("Bar");
			Assert.IsTrue(ll.Contains(null));
			Assert.IsTrue(ll.Contains("Bar"));
			Assert.IsTrue(ll.Contains("Foo"));

			ll = new LinkedList();
			ll.Add("Foo");
			ll.Add("Bar");
			Assert.IsFalse(ll.Contains(null));
		}
        private AbstractObjectDefinition ParseAttributeSource(XmlElement element, ParserContext parserContext)
        {
            XmlNodeList methods = element.SelectNodes("*[local-name()='method' and namespace-uri()='" + element.NamespaceURI + "']");
            ManagedDictionary transactionAttributeMap = new ManagedDictionary();
            foreach (XmlElement methodElement in methods)
            {
                string name = GetAttributeValue(methodElement, "name");
                TypedStringValue nameHolder = new TypedStringValue(name);
                
                RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute();
                string propagation = GetAttributeValue(methodElement, PROPAGATION);
                string isolation = GetAttributeValue(methodElement, ISOLATION);
                string timeout = GetAttributeValue(methodElement, TIMEOUT);
                string readOnly = GetAttributeValue(methodElement, READ_ONLY);
                if (StringUtils.HasText(propagation))
                {
                    attribute.PropagationBehavior = (TransactionPropagation) Enum.Parse(typeof (TransactionPropagation), propagation, true);
                }
                if (StringUtils.HasText(isolation))
                {
                    attribute.TransactionIsolationLevel =
                        (IsolationLevel) Enum.Parse(typeof (IsolationLevel), isolation, true);
                }
                if (StringUtils.HasText(timeout))
                {
                    try
                    {
                        attribute.TransactionTimeout = Int32.Parse(timeout);
                    }
                    catch (FormatException ex)
                    {
                        parserContext.ReaderContext.ReportException(methodElement,"tx advice","timeout must be an integer value: [" + timeout + "]", ex);
                    }
                }
                if (StringUtils.HasText(readOnly))
                {
                    attribute.ReadOnly = Boolean.Parse(GetAttributeValue(methodElement, READ_ONLY));
                }
                IList rollbackRules = new LinkedList();
                if (methodElement.HasAttribute(ROLLBACK_FOR))
                {
                    string rollbackForValue = GetAttributeValue(methodElement, ROLLBACK_FOR);
                    AddRollbackRuleAttributesTo(rollbackRules, rollbackForValue);
                }
                if (methodElement.HasAttribute(NO_ROLLBACK_FOR))
                {
                    string noRollbackForValue = GetAttributeValue(methodElement, NO_ROLLBACK_FOR);
                    AddNoRollbackRuleAttributesTo(rollbackRules, noRollbackForValue);
                }
                attribute.RollbackRules = rollbackRules;

                transactionAttributeMap[nameHolder] = attribute;
            }

            ObjectDefinitionBuilder builder = parserContext
                                                .ParserHelper
                                                .CreateRootObjectDefinitionBuilder(typeof (NameMatchTransactionAttributeSource));
            builder.AddPropertyValue(NAME_MAP, transactionAttributeMap);
            return builder.ObjectDefinition;

        }
Beispiel #30
0
		public void RemoveAtOnEmptyLinkedList()
		{
			LinkedList ll = new LinkedList();
			ll.RemoveAt(0);
		}