/// <summary>
        /// Formata o texto de uma <see cref="QueryInfo" />
        /// </summary>
        /// <param name="queryInfo"></param>
        /// <param name="ignoreContainerFormat">Identifica que é para ignorar a formatação de de container para a consulta.</param>
        /// <returns></returns>
        private OracleQueryParser Format(QueryInfo queryInfo, bool ignoreContainerFormat = false)
        {
            var parser = new OracleQueryParser(this.Translator, this.TypeSchema, _takeParametersParser)
            {
                Owner            = this,
                UseTakeParameter = true
            };

            parser.Query = queryInfo;
            foreach (var parameter in queryInfo.Parameters)
            {
                if (!this.Query.Parameters.Any(f => f.Name == parameter.Name))
                {
                    this.Query.Parameters.Add(parameter);
                }
            }
            if (!ignoreContainerFormat)
            {
                Append('(');
            }
            Append(parser.GetText());
            if (!ignoreContainerFormat)
            {
                Append(')');
            }
            return(this);
        }
        private OracleQueryParser Format(QueryInfo a, bool b = false)
        {
            var c = new OracleQueryParser(this.Translator, this.TypeSchema, _takeParametersParser)
            {
                Owner            = this,
                UseTakeParameter = true
            };

            c.Query = a;
            foreach (var parameter in a.Parameters)
            {
                if (!this.Query.Parameters.Any(d => d.Name == parameter.Name))
                {
                    this.Query.Parameters.Add(parameter);
                }
            }
            if (!b)
            {
                Append('(');
            }
            Append(c.GetText());
            if (!b)
            {
                Append(')');
            }
            return(this);
        }
        /// <summary>
        /// Adiciona ao campo string builder o texto correspondente a parte SELECT da query
        /// </summary>
        /// <returns>Retorna o próprio objeto</returns>
        private OracleQueryParser SelectParser()
        {
            if (Query.IsSelectDistinct)
            {
                Append("SELECT DISTINCT ");
            }
            else
            {
                Append("SELECT ");
            }
            if (Query.Entities == null)
            {
                throw new InvalidOperationException(string.Format("Not found entities in query '{0}'", Query));
            }
            ITypeMetadata mainTypeMetadata = null;

            for (int i = 0; i < Query.Entities.Length; i++)
            {
                if (string.IsNullOrEmpty(Query.Entities[i].FullName))
                {
                    continue;
                }
                ITypeMetadata typeMetadata = null;
                if (!Query.IgnoreTypeSchema)
                {
                    typeMetadata = TypeSchema.GetTypeMetadata(Query.Entities[i].FullName);
                    if (typeMetadata == null)
                    {
                        throw new InvalidOperationException(ResourceMessageFormatter.Create(() => Properties.Resources.InvalidOperationException_TypeMetadataNotFoundByFullName, Query.Entities[i].FullName).Format());
                    }
                }
                if (i == 0)
                {
                    mainTypeMetadata = typeMetadata;
                    if (string.IsNullOrEmpty(Query.Entities[i].Alias))
                    {
                        Query.Entities[i].Alias = "main";
                    }
                }
                else if (string.IsNullOrEmpty(Query.Entities[i].Alias))
                {
                    Query.Entities[i].Alias = "main" + i.ToString();
                }
            }
            bool       rowVersionFound = false;
            EntityInfo entity          = Query.Entities[0];

            if (!string.IsNullOrEmpty(entity.FullName))
            {
                if (Query.Projection == null)
                {
                    if (mainTypeMetadata != null && mainTypeMetadata.IsVersioned)
                    {
                        Query.HasRowVersion = true;
                    }
                    var properties = mainTypeMetadata != null?mainTypeMetadata.Where(f => f.Direction == Data.Schema.DirectionParameter.Input || f.Direction == Data.Schema.DirectionParameter.InputOutput).ToArray() : new IPropertyMetadata[0];

                    if (properties.Length == 0)
                    {
                        throw new InvalidOperationException(ResourceMessageFormatter.Create(() => Properties.Resources.InvalidOperationException_NotFoundPropertiesForTypeMetadata, entity.FullName).Format());
                    }
                    Query.Projection = new Projection();
                    for (var i = 0; i < properties.Length; i++)
                    {
                        var prop = properties[i];
                        if (prop.Name == DataAccessConstants.RowVersionPropertyName)
                        {
                            rowVersionFound = true;
                        }
                        Query.Projection.Add(new ProjectionEntry(string.Format("{0}.{1}", entity.Alias, prop.Name), prop.Name));
                        var translateName       = Translator.GetName(entity, prop.Name, Query.IgnoreTypeSchema);
                        var translateColumnName = translateName as TranslatedColumnName;
                        if (translateColumnName != null)
                        {
                            if (!string.IsNullOrEmpty(translateColumnName.TableAlias))
                            {
                                AppendQuoteExpression(translateColumnName.TableAlias).Append('.');
                            }
                            AppendQuoteExpression(translateColumnName.Name);
                        }
                        if (prop.ColumnName != prop.Name)
                        {
                            Append(" AS ").AppendQuoteExpression(FormatProjectionAlias(prop.Name));
                        }
                        if (i + 1 < properties.Length)
                        {
                            Append(',');
                        }
                    }
                    Append(' ');
                }
                else
                {
                    ProjectionParser();
                }
                if (Query.HasRowVersion && !rowVersionFound)
                {
                    Append(", ").Append("CAST(ORA_ROWSCN AS NUMBER(18,0)) AS \"").Append(DataAccessConstants.RowVersionColumnName.ToUpper()).Append("\" ");
                }
                var tableName = Translator.GetName(entity, Query.IgnoreTypeSchema);
                if (tableName == null)
                {
                    throw new InvalidOperationException(string.Format("Not found table name for entity '{0}'", entity.FullName));
                }
                Append("FROM ").AppendTranslatedName(tableName).Append(' ').AppendQuoteExpression(entity.Alias).Append(' ');
            }
            else
            {
                var sqlParser = new OracleQueryParser(Translator, TypeSchema, _takeParametersParser)
                {
                    Query            = entity.SubQuery,
                    UseTakeParameter = true
                };
                var subQueryText = sqlParser.GetText();
                if (Query.Projection == null)
                {
                    Query.Projection = new Projection();
                    foreach (var column in entity.SubQuery.Projection)
                    {
                        Query.Projection.Add(new ProjectionEntry(!string.IsNullOrEmpty(entity.Alias) ? string.Format("{0}.{1}", entity.Alias, string.IsNullOrEmpty(column.Alias) ? (string.IsNullOrEmpty(column.GetColumnInfo().Alias) ? column.GetColumnInfo().Name : column.GetColumnInfo().Alias) : column.Alias) : column.Alias, column.Alias));
                    }
                }
                ProjectionParser();
                Append("FROM (").Append(subQueryText).Append(") ").AppendQuoteExpression(entity.Alias);
            }
            return(this);
        }
        private OracleQueryParser SelectParser()
        {
            if (Query.IsSelectDistinct)
            {
                Append("SELECT DISTINCT ");
            }
            else
            {
                Append("SELECT ");
            }
            if (Query.Entities == null)
            {
                throw new InvalidOperationException(string.Format("Not found entities in query '{0}'", Query));
            }
            ITypeMetadata a = null;

            for (int b = 0; b < Query.Entities.Length; b++)
            {
                if (string.IsNullOrEmpty(Query.Entities [b].FullName))
                {
                    continue;
                }
                ITypeMetadata c = null;
                if (!Query.IgnoreTypeSchema)
                {
                    c = TypeSchema.GetTypeMetadata(Query.Entities [b].FullName);
                    if (c == null)
                    {
                        throw new InvalidOperationException(ResourceMessageFormatter.Create(() => Properties.Resources.InvalidOperationException_TypeMetadataNotFoundByFullName, Query.Entities [b].FullName).Format());
                    }
                }
                if (b == 0)
                {
                    a = c;
                    if (string.IsNullOrEmpty(Query.Entities [b].Alias))
                    {
                        Query.Entities [b].Alias = "main";
                    }
                }
                else if (string.IsNullOrEmpty(Query.Entities [b].Alias))
                {
                    Query.Entities [b].Alias = "main" + b.ToString();
                }
            }
            bool       d = false;
            EntityInfo e = Query.Entities [0];

            if (!string.IsNullOrEmpty(e.FullName))
            {
                if (Query.Projection == null)
                {
                    if (a != null && a.IsVersioned)
                    {
                        Query.HasRowVersion = true;
                    }
                    var f = a != null?a.Where(g => g.Direction == Data.Schema.DirectionParameter.Input || g.Direction == Data.Schema.DirectionParameter.InputOutput).ToArray() : new IPropertyMetadata[0];

                    if (f.Length == 0)
                    {
                        throw new InvalidOperationException(ResourceMessageFormatter.Create(() => Properties.Resources.InvalidOperationException_NotFoundPropertiesForTypeMetadata, e.FullName).Format());
                    }
                    Query.Projection = new Projection();
                    for (var b = 0; b < f.Length; b++)
                    {
                        var h = f [b];
                        if (h.Name == DataAccessConstants.RowVersionPropertyName)
                        {
                            d = true;
                        }
                        Query.Projection.Add(new ProjectionEntry(string.Format("{0}.{1}", e.Alias, h.Name), h.Name));
                        var j = Translator.GetName(e, h.Name, Query.IgnoreTypeSchema);
                        var k = j as TranslatedColumnName;
                        if (k != null)
                        {
                            if (!string.IsNullOrEmpty(k.TableAlias))
                            {
                                AppendQuoteExpression(k.TableAlias).Append('.');
                            }
                            AppendQuoteExpression(k.Name);
                        }
                        if (h.ColumnName != h.Name)
                        {
                            Append(" AS ").AppendQuoteExpression(FormatProjectionAlias(h.Name));
                        }
                        if (b + 1 < f.Length)
                        {
                            Append(',');
                        }
                    }
                    Append(' ');
                }
                else
                {
                    ProjectionParser();
                }
                if (Query.HasRowVersion && !d)
                {
                    Append(", ").Append("CAST(ORA_ROWSCN AS NUMBER(18,0)) AS \"").Append(DataAccessConstants.RowVersionColumnName.ToUpper()).Append("\" ");
                }
                var l = Translator.GetName(e, Query.IgnoreTypeSchema);
                if (l == null)
                {
                    throw new InvalidOperationException(string.Format("Not found table name for entity '{0}'", e.FullName));
                }
                Append("FROM ").AppendTranslatedName(l).Append(' ').AppendQuoteExpression(e.Alias).Append(' ');
            }
            else
            {
                var m = new OracleQueryParser(Translator, TypeSchema, _takeParametersParser)
                {
                    Query            = e.SubQuery,
                    UseTakeParameter = true
                };
                var n = m.GetText();
                if (Query.Projection == null)
                {
                    Query.Projection = new Projection();
                    foreach (var column in e.SubQuery.Projection)
                    {
                        Query.Projection.Add(new ProjectionEntry(!string.IsNullOrEmpty(e.Alias) ? string.Format("{0}.{1}", e.Alias, string.IsNullOrEmpty(column.Alias) ? (string.IsNullOrEmpty(column.GetColumnInfo().Alias) ? column.GetColumnInfo().Name : column.GetColumnInfo().Alias) : column.Alias) : column.Alias, column.Alias));
                    }
                }
                ProjectionParser();
                Append("FROM (").Append(n).Append(") ").AppendQuoteExpression(e.Alias);
            }
            return(this);
        }