private ICommandBuilder[] GetPagedQueryCommandBuilders(ref SimpleQuery query, Int32 bulkIndex, out IEnumerable <SimpleQueryClauseBase> unhandledClauses) { var commandBuilders = new List <ICommandBuilder>(); var unhandledClausesList = new List <SimpleQueryClauseBase>(); unhandledClauses = unhandledClausesList; IEnumerable <SimpleQueryClauseBase> unhandledClausesForPagedQuery; ICommandBuilder mainCommandBuilder = new QueryBuilder(_adapter, bulkIndex).Build(query, out unhandledClausesForPagedQuery); unhandledClausesList.AddRange(unhandledClausesForPagedQuery); SkipClause skipClause = query.Clauses.OfType <SkipClause>().FirstOrDefault(); TakeClause takeClause = query.Clauses.OfType <TakeClause>().FirstOrDefault(); if (skipClause != null || takeClause != null) { var queryPager = _adapter.ProviderHelper.GetCustomProvider <IQueryPager>(_adapter.ConnectionProvider); if (queryPager == null) { SimpleDataTraceSources.TraceSource.TraceEvent(TraceEventType.Warning, SimpleDataTraceSources.PerformanceWarningMessageId, "There is no database-specific query paging in your current Simple.Data Provider. Paging will be done in memory."); DeferPaging(ref query, mainCommandBuilder, commandBuilders, unhandledClausesList); } else { ApplyPaging(query, commandBuilders, mainCommandBuilder, skipClause, takeClause, query.Clauses.OfType <WithClause>().Any(), queryPager); } } return(commandBuilders.ToArray()); }
private bool TryApplySkipClause(SkipClause clause, QueryCommand cmd) { if (cmd.SkipCount.HasValue || cmd.TakeCount.HasValue) { return(false); } cmd.SkipCount = clause.Count; return(true); }
private bool TryApplySkipClause(SkipClause clause) { if (SkipCount.HasValue || TakeCount.HasValue) { return(false); } SkipCount = clause.Count; return(true); }
private ICommandBuilder[] GetPagedQueryCommandBuilders(SimpleQuery query, Int32 bulkIndex, out IEnumerable <SimpleQueryClauseBase> unhandledClauses) { var commandBuilders = new List <ICommandBuilder>(); var unhandledClausesList = new List <SimpleQueryClauseBase>(); unhandledClauses = unhandledClausesList; IEnumerable <SimpleQueryClauseBase> unhandledClausesForPagedQuery; ICommandBuilder mainCommandBuilder = new QueryBuilder(this, bulkIndex).Build(query, out unhandledClausesForPagedQuery); unhandledClausesList.AddRange(unhandledClausesForPagedQuery); const int maxInt = 2147483646; SkipClause skipClause = query.Clauses.OfType <SkipClause>().FirstOrDefault() ?? new SkipClause(0); TakeClause takeClause = query.Clauses.OfType <TakeClause>().FirstOrDefault() ?? new TakeClause(maxInt); if (skipClause.Count != 0 || takeClause.Count != maxInt) { var queryPager = ProviderHelper.GetCustomProvider <IQueryPager>(ConnectionProvider); if (queryPager == null) { unhandledClausesList.AddRange(query.OfType <SkipClause>()); unhandledClausesList.AddRange(query.OfType <TakeClause>()); } IEnumerable <string> commandTexts = queryPager.ApplyPaging(mainCommandBuilder.Text, skipClause.Count, takeClause.Count); foreach (string commandText in commandTexts) { var commandBuilder = new CommandBuilder(commandText, _schema, mainCommandBuilder.Parameters); commandBuilders.Add(commandBuilder); } } return(commandBuilders.ToArray()); }
private bool TryApplySkipClause(SkipClause clause) { if (SkipCount.HasValue || TakeCount.HasValue) return false; SkipCount = clause.Count; return true; }
private void ApplyPaging(SimpleQuery query, List<ICommandBuilder> commandBuilders, ICommandBuilder mainCommandBuilder, SkipClause skipClause, TakeClause takeClause, bool hasWithClause, IQueryPager queryPager) { const int maxInt = 2147483646; IEnumerable<string> commandTexts; if (skipClause == null && !hasWithClause) { commandTexts = queryPager.ApplyLimit(mainCommandBuilder.Text, takeClause.Count); } else { var table = _adapter.GetSchema().FindTable(query.TableName); if (table.PrimaryKey == null || table.PrimaryKey.Length == 0) { throw new AdoAdapterException("Cannot apply paging to a table with no primary key."); } var keys = table.PrimaryKey.AsEnumerable() .Select(k => string.Format("{0}.{1}", table.QualifiedName, _adapter.GetSchema().QuoteObjectName(k))) .ToArray(); int skip = skipClause == null ? 0 : skipClause.Count; int take = takeClause == null ? maxInt : takeClause.Count; commandTexts = queryPager.ApplyPaging(mainCommandBuilder.Text, keys, skip, take); } commandBuilders.AddRange( commandTexts.Select( commandText => new CommandBuilder(commandText, _adapter.GetSchema(), mainCommandBuilder.Parameters))); }
private void ApplyPaging(SimpleQuery query, List <ICommandBuilder> commandBuilders, ICommandBuilder mainCommandBuilder, SkipClause skipClause, TakeClause takeClause, bool hasWithClause, IQueryPager queryPager) { const int maxInt = 2147483646; IEnumerable <string> commandTexts; if (skipClause == null && !hasWithClause) { commandTexts = queryPager.ApplyLimit(mainCommandBuilder.Text, takeClause.Count); } else { var table = _adapter.GetSchema().FindTable(query.TableName); var keys = new string[0]; if (table.PrimaryKey != null && table.PrimaryKey.Length > 0) { keys = table.PrimaryKey.AsEnumerable() .Select(k => string.Format("{0}.{1}", table.QualifiedName, _adapter.GetSchema().QuoteObjectName(k))) .ToArray(); } int skip = skipClause == null ? 0 : skipClause.Count; int take = takeClause == null ? maxInt : takeClause.Count; commandTexts = queryPager.ApplyPaging(mainCommandBuilder.Text, keys, skip, take); } commandBuilders.AddRange( commandTexts.Select( commandText => new CommandBuilder(commandText, _adapter.GetSchema(), mainCommandBuilder.Parameters))); }
private void ApplyPaging(List<ICommandBuilder> commandBuilders, ICommandBuilder mainCommandBuilder, SkipClause skipClause, TakeClause takeClause, IQueryPager queryPager) { const int maxInt = 2147483646; IEnumerable<string> commandTexts; if (skipClause == null) { commandTexts = queryPager.ApplyLimit(mainCommandBuilder.Text, takeClause.Count); } else { if (takeClause == null) takeClause = new TakeClause(maxInt); commandTexts = queryPager.ApplyPaging(mainCommandBuilder.Text, skipClause.Count, takeClause.Count); } commandBuilders.AddRange( commandTexts.Select( commandText => new CommandBuilder(commandText, _adapter.GetSchema(), mainCommandBuilder.Parameters))); }
/// <summary> /// Renders the clause in textual representation. /// </summary> /// <param name="writer">to output to</param> public void ToEPL(TextWriter writer) { string delimiter; writer.Write(" match_recognize ("); if (PartitionExpressions.Count > 0) { delimiter = ""; writer.Write(" partition by "); foreach (Expression part in PartitionExpressions) { writer.Write(delimiter); part.ToEPL(writer, ExpressionPrecedenceEnum.MINIMUM); delimiter = ", "; } } delimiter = ""; writer.Write(" measures "); foreach (SelectClauseExpression part in Measures) { writer.Write(delimiter); part.ToEPLElement(writer); delimiter = ", "; } if (IsAll) { writer.Write(" all matches"); } if (SkipClause != MatchRecognizeSkipClause.PAST_LAST_ROW) { writer.Write(" after match skip " + SkipClause.GetText()); } writer.Write(" pattern ("); Pattern.WriteEPL(writer); writer.Write(")"); if ((IntervalClause != null) && (IntervalClause.Expression != null)) { writer.Write(" interval "); IntervalClause.Expression.ToEPL(writer, ExpressionPrecedenceEnum.MINIMUM); if (IntervalClause.IsOrTerminated) { writer.Write(" or terminated"); } } delimiter = ""; if (!Defines.IsEmpty()) { writer.Write(" define "); foreach (MatchRecognizeDefine def in Defines) { writer.Write(delimiter); writer.Write(def.Name); writer.Write(" as "); def.Expression.ToEPL(writer, ExpressionPrecedenceEnum.MINIMUM); delimiter = ", "; } } writer.Write(")"); }
private bool TryApplySkipClause(SkipClause clause, QueryCommand cmd) { if (cmd.SkipCount.HasValue || cmd.TakeCount.HasValue) return false; cmd.SkipCount = clause.Count; return true; }
private void ApplyPaging(List <ICommandBuilder> commandBuilders, ICommandBuilder mainCommandBuilder, SkipClause skipClause, TakeClause takeClause, bool hasWithClause, IQueryPager queryPager) { const int maxInt = 2147483646; IEnumerable <string> commandTexts; if (skipClause == null && !hasWithClause) { commandTexts = queryPager.ApplyLimit(mainCommandBuilder.Text, takeClause.Count); } else { int skip = skipClause == null ? 0 : skipClause.Count; int take = takeClause == null ? maxInt : takeClause.Count; commandTexts = queryPager.ApplyPaging(mainCommandBuilder.Text, skip, take); } commandBuilders.AddRange( commandTexts.Select( commandText => new CommandBuilder(commandText, _adapter.GetSchema(), mainCommandBuilder.Parameters))); }