Exemplo n.º 1
0
        internal IInnerConnection GetConnection(ConnectionOptions options, VirtuosoConnection connection)
        {
            Debug.WriteLineIf(CLI.FnTrace.Enabled, "ConnectionPool.GetConnection ()");

            IInnerConnection innerConnection = null;

            if (options.Enlist && ContextUtil.IsInTransaction)
            {
                innerConnection = (IInnerConnection)dtcPool.GetResource();
                if (innerConnection != null)
                {
                    innerConnection.OuterConnectionWeakRef = new WeakReference(connection);
                    return(innerConnection);
                }
            }

            lock (this)
            {
                if (pool == null)
                {
                    pool = new IInnerConnection[maxSize];
                    for (int i = 0; i < minSize; i++)
                    {
                        innerConnection           = connection.CreateInnerConnection(options, false);
                        innerConnection.TimeStamp = DateTime.Now;
                        PutConnection(innerConnection);
                    }
                }

                if (size > 0)
                {
                    innerConnection = pool[--size];
                }
            }

            if (innerConnection == null)
            {
                innerConnection           = connection.CreateInnerConnection(options, true);
                innerConnection.TimeStamp = DateTime.Now;
            }
            else
            {
                innerConnection.OuterConnectionWeakRef = new WeakReference(connection);
#if MTS
                if (options.Enlist && ContextUtil.IsInTransaction)
                {
                    connection.EnlistInnerConnection(innerConnection);
                }
#endif
            }

            return(innerConnection);
        }
Exemplo n.º 2
0
		internal IInnerConnection GetConnection (ConnectionOptions options, VirtuosoConnection connection)
		{
			Debug.WriteLineIf (CLI.FnTrace.Enabled, "ConnectionPool.GetConnection ()");

			IInnerConnection innerConnection = null;

			if (options.Enlist && ContextUtil.IsInTransaction)
			{
				innerConnection = (IInnerConnection) dtcPool.GetResource ();
				if (innerConnection != null)
				{
					innerConnection.OuterConnectionWeakRef = new WeakReference (connection);
					return innerConnection;
				}
			}

			lock (this)
			{
				if (pool == null)
				{
					pool = new IInnerConnection[maxSize];
					for (int i = 0; i < minSize; i++)
					{
						innerConnection = connection.CreateInnerConnection (options, false);
						innerConnection.TimeStamp = DateTime.Now;
						PutConnection (innerConnection);
					}
				}

				if (size > 0)
					innerConnection = pool[--size];
			}

			if (innerConnection == null)
			{
				innerConnection = connection.CreateInnerConnection (options, true);
				innerConnection.TimeStamp = DateTime.Now;
			}
			else
			{
				innerConnection.OuterConnectionWeakRef = new WeakReference (connection);
#if MTS 
				if (options.Enlist && ContextUtil.IsInTransaction)
					connection.EnlistInnerConnection (innerConnection);
#endif			
			}

			return innerConnection;
		}