/// <summary>
        /// Executa as várias consultas.
        /// </summary>
        /// <param name="session"></param>
        /// <param name="queryInfo"></param>
        /// <returns></returns>
        protected virtual IQueryResult Execute(GDASession session, QueryInfo queryInfo)
        {
            if (session.State == GDASessionState.Closed)
            {
                throw new QueryException("Database connection is closed to execute query");
            }
            queryInfo.Require("queries").NotNull();
            string providerName          = ProviderLocator.GetProviderName(queryInfo);
            var    providerConfiguration = GDASettings.GetProviderConfiguration(providerName);

            if (queryInfo.StoredProcedureName == null)
            {
                SqlQueryParser parser      = CreateParser(queryInfo);
                string         queryString = parser.GetText();
                try
                {
                    return(ExecuteQuery(session, queryString, queryInfo));
                }
                catch (GDAException ex)
                {
                    throw new QueryException(string.Format("{0}. Query: {1}", ex.Message, queryInfo.ToString()), ex.InnerException);
                }
            }
            else
            {
                return(ExecuteStoredProcedure(session, queryInfo));
            }
        }
        /// <summary>
        /// Executa uma procedure no sistema.
        /// </summary>
        /// <param name="queryInfo">Informações da procedure.</param>
        /// <returns>Resultado da consulta.</returns>
        protected override IQueryResult ExecuteStoredProcedure(QueryInfo queryInfo)
        {
            var        group   = new QueryExecutionGroup(ProviderLocator.GetProviderName(queryInfo), queryInfo.IsolationLevel);
            GDASession session = CreateSession(group);

            try
            {
                if (!queryInfo.IgnoreRegisterUserInfo)
                {
                    RegisterUserInfo(new GDAStoredProcedureTransaction(session, group.ProviderName));
                }
                RegisterSession(session);
                var result = ExecuteStoredProcedure(session, queryInfo);
                if (result != null)
                {
                    EventHandler methodHandler = null;
                    methodHandler = new EventHandler((sender, e) => {
                        result.Disposed -= methodHandler;
                        if (session is GDATransaction)
                        {
                            ((GDATransaction)session).Commit();
                        }
                        session.Dispose();
                    });
                    result.Disposed += methodHandler;
                    return(result);
                }
            }
            catch
            {
                if (session is GDATransaction)
                {
                    ((GDATransaction)session).Rollback();
                }
                session.Dispose();
                throw;
            }
            if (session is GDATransaction)
            {
                ((GDATransaction)session).Commit();
            }
            session.Dispose();
            return(null);
        }
        /// <summary>
        /// Executa as várias consultas.
        /// </summary>
        /// <param name="queries"></param>
        /// <returns></returns>
        public override IEnumerable <IQueryResult> Execute(QueryInfo[] queries)
        {
            queries.Require("queries").NotNull();
            var result = new IQueryResult[queries.Length];
            Dictionary <QueryExecutionGroup, IList <int> > providerDictionary = new Dictionary <QueryExecutionGroup, IList <int> >(QueryExecutionGroup.Comparer);

            for (int i = 0; i < queries.Length; i++)
            {
                string      providerName = ProviderLocator.GetProviderName(queries[i]);
                var         group        = new QueryExecutionGroup(providerName, queries[i].IsolationLevel);
                IList <int> indexes;
                if (providerDictionary.TryGetValue(group, out indexes))
                {
                    indexes.Add(i);
                }
                else
                {
                    indexes = new List <int>();
                    indexes.Add(i);
                    providerDictionary.Add(group, indexes);
                }
            }
            IStoredProcedureTransaction storedProcedureTransaction = null;

            foreach (var provider in providerDictionary)
            {
                using (var session = CreateSession(provider.Key))
                {
                    RegisterSession(session);
                    foreach (var index in provider.Value)
                    {
                        IQueryResult queryResult = null;
                        try
                        {
                            if (queries[index].StoredProcedureName == null)
                            {
                                SqlQueryParser parser      = CreateParser(queries[index]);
                                string         queryString = parser.GetText();
                                try
                                {
                                    queryResult = ExecuteQuery(session, queryString, queries[index]);
                                }
                                catch (GDAException ex)
                                {
                                    throw new GDAException(string.Format("{0}. Query: {1}", ex.Message, queries[index].ToString()), ex.InnerException);
                                }
                            }
                            else
                            {
                                if (storedProcedureTransaction == null)
                                {
                                    storedProcedureTransaction = new GDAStoredProcedureTransaction(session, provider.Key.ProviderName);
                                    if (!queries[index].IgnoreRegisterUserInfo)
                                    {
                                        RegisterUserInfo(storedProcedureTransaction);
                                    }
                                }
                                queryResult = ExecuteStoredProcedure(session, queries[index]);
                            }
                        }
                        catch
                        {
                            if (session is GDATransaction)
                            {
                                ((GDATransaction)session).Rollback();
                            }
                            throw;
                        }
                        yield return(queryResult);
                    }
                    if (session is GDATransaction)
                    {
                        ((GDATransaction)session).Commit();
                    }
                }
            }
        }