From 9d5a5cb36453fbb8cc8d1bfffa10f96af8ce7999 Mon Sep 17 00:00:00 2001 From: Jim Borden Date: Fri, 7 Jul 2017 13:44:48 +0900 Subject: [PATCH] Clean up some ambiguously named classes and let GroupBy directly take expressions --- src/Couchbase.Lite.Tests.Shared/QueryTest.cs | 16 +- src/Couchbase.Lite/API/Query/GroupBy.cs | 44 ------ .../API/Query/IGroupByRouter.cs | 18 +-- src/Couchbase.Lite/API/Query/IJoinRouter.cs | 2 +- .../API/Query/IOrderByRouter.cs | 4 +- src/Couchbase.Lite/API/Query/Joins.cs | 10 +- src/Couchbase.Lite/Query/DataSource.cs | 96 ++++++------ src/Couchbase.Lite/Query/DatabaseSource.cs | 148 +++++++++--------- src/Couchbase.Lite/Query/From.cs | 12 +- src/Couchbase.Lite/Query/Join.cs | 14 +- src/Couchbase.Lite/Query/QueryGroupBy.cs | 26 ++- src/Couchbase.Lite/Query/QueryOrdering.cs | 4 +- src/Couchbase.Lite/Query/Select.cs | 4 +- src/Couchbase.Lite/Query/Where.cs | 6 +- src/Couchbase.Lite/Query/XQuery.cs | 76 ++++----- 15 files changed, 201 insertions(+), 279 deletions(-) delete mode 100644 src/Couchbase.Lite/API/Query/GroupBy.cs diff --git a/src/Couchbase.Lite.Tests.Shared/QueryTest.cs b/src/Couchbase.Lite.Tests.Shared/QueryTest.cs index 6abe94427..ebfb46457 100644 --- a/src/Couchbase.Lite.Tests.Shared/QueryTest.cs +++ b/src/Couchbase.Lite.Tests.Shared/QueryTest.cs @@ -21,11 +21,7 @@ using System; using System.Collections.Generic; -using System.Diagnostics; -using System.IO; using System.Linq; -using System.Reflection; -using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -33,13 +29,7 @@ using Couchbase.Lite; using Couchbase.Lite.Query; using FluentAssertions; -using LiteCore.Interop; using Newtonsoft.Json; -using Couchbase.Lite.Internal.Query; -using DataSource = Couchbase.Lite.Query.DataSource; -using Function = Couchbase.Lite.Query.Function; -using GroupBy = Couchbase.Lite.Query.GroupBy; -using Ordering = Couchbase.Lite.Query.Ordering; #if !WINDOWS_UWP using Xunit; using Xunit.Abstractions; @@ -574,7 +564,7 @@ public void TestJoin() var number2Prop = Expression.Property("number2"); using (var q = Query.Select(SelectResult.Expression(number2Prop.From("main"))) .From(DataSource.Database(Db).As("main")) - .Join(Joins.Join(DataSource.Database(Db).As("secondary")) + .Joins(Join.DefaultJoin(DataSource.Database(Db).As("secondary")) .On(Expression.Property("number1").From("main") .EqualTo(Expression.Property("theone").From("secondary"))))) { using (var results = q.Run()) { @@ -628,7 +618,7 @@ public void TestGroupBy() using (var q = Query.Select(SelectResult.Expression(STATE), SelectResult.Expression(COUNT), SelectResult.Expression(MAXZIP)) .From(DataSource.Database(Db)) .Where(gender.EqualTo("female")) - .GroupBy(GroupBy.Expression(STATE)) + .GroupBy(STATE) .OrderBy(Ordering.Expression(STATE))) { var numRows = VerifyQuery(q, (n, row) => { @@ -651,7 +641,7 @@ public void TestGroupBy() using (var q = Query.Select(SelectResult.Expression(STATE), SelectResult.Expression(COUNT), SelectResult.Expression(MAXZIP)) .From(DataSource.Database(Db)) .Where(gender.EqualTo("female")) - .GroupBy(GroupBy.Expression(STATE)) + .GroupBy(STATE) .Having(COUNT.GreaterThan(1)) .OrderBy(Ordering.Expression(STATE))) { var numRows = VerifyQuery(q, (n, row) => diff --git a/src/Couchbase.Lite/API/Query/GroupBy.cs b/src/Couchbase.Lite/API/Query/GroupBy.cs deleted file mode 100644 index bc01dd631..000000000 --- a/src/Couchbase.Lite/API/Query/GroupBy.cs +++ /dev/null @@ -1,44 +0,0 @@ -// -// QueryGroupBy.cs -// -// Author: -// Jim Borden -// -// Copyright (c) 2017 Couchbase, Inc All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -using Couchbase.Lite.Internal.Query; - -namespace Couchbase.Lite.Query -{ - /// - /// A class for creating instances - /// - public static class GroupBy - { - #region Public Methods - - /// - /// Creates an instance that will group a query by the given expression - /// - /// The expression to group the query by - /// An instance that will group a query by the given expression - public static IGroupBy Expression(IExpression expression) - { - return new QueryGroupBy(expression); - } - - #endregion - } -} diff --git a/src/Couchbase.Lite/API/Query/IGroupByRouter.cs b/src/Couchbase.Lite/API/Query/IGroupByRouter.cs index e7638c03e..d99146747 100644 --- a/src/Couchbase.Lite/API/Query/IGroupByRouter.cs +++ b/src/Couchbase.Lite/API/Query/IGroupByRouter.cs @@ -18,24 +18,24 @@ // See the License for the specific language governing permissions and // limitations under the License. // - -namespace Couchbase.Lite.Query -{ + +namespace Couchbase.Lite.Query +{ /// /// An interface representing a portion of a query which can take GROUP BY /// as its next step /// - public interface IGroupByRouter - { + public interface IGroupByRouter + { #region Public Methods /// /// Groups the current query by the given GROUP BY clauses /// - /// The clauses to group by + /// The clauses to group by /// The query grouped by the given clauses for further processing - IGroupBy GroupBy(params IGroupBy[] groupBy); + IGroupBy GroupBy(params IExpression[] expressions); #endregion - } -} + } +} diff --git a/src/Couchbase.Lite/API/Query/IJoinRouter.cs b/src/Couchbase.Lite/API/Query/IJoinRouter.cs index fe31234d8..442260beb 100644 --- a/src/Couchbase.Lite/API/Query/IJoinRouter.cs +++ b/src/Couchbase.Lite/API/Query/IJoinRouter.cs @@ -34,7 +34,7 @@ public interface IJoinRouter /// /// The join clauses to add /// The query with the join statement, for further processing - IJoin Join(params IJoin[] joins); + IJoin Joins(params IJoin[] joins); #endregion } diff --git a/src/Couchbase.Lite/API/Query/IOrderByRouter.cs b/src/Couchbase.Lite/API/Query/IOrderByRouter.cs index f6301124a..7cb08aeff 100644 --- a/src/Couchbase.Lite/API/Query/IOrderByRouter.cs +++ b/src/Couchbase.Lite/API/Query/IOrderByRouter.cs @@ -32,10 +32,10 @@ public interface IOrderByRouter /// /// Routes this IExpression to the next ORDER BY portion of the query /// - /// An array of order by operations to consider in the + /// An array of order by operations to consider in the /// ORDER BY portion of the query /// The next ORDER BY portion of the query - IOrdering OrderBy(params IOrdering[] ordering); + IOrdering OrderBy(params IOrdering[] orderings); #endregion } diff --git a/src/Couchbase.Lite/API/Query/Joins.cs b/src/Couchbase.Lite/API/Query/Joins.cs index b5b9de04e..299384ed6 100644 --- a/src/Couchbase.Lite/API/Query/Joins.cs +++ b/src/Couchbase.Lite/API/Query/Joins.cs @@ -25,7 +25,7 @@ namespace Couchbase.Lite.Query /// /// A class for creating instances /// - public static class Joins + public static class Join { #region Public Methods @@ -36,7 +36,7 @@ public static class Joins /// An instance for processing public static IJoinOn CrossJoin(IDataSource dataSource) { - return new Join("CROSS", dataSource); + return new QueryJoin("CROSS", dataSource); } /// @@ -46,7 +46,7 @@ public static IJoinOn CrossJoin(IDataSource dataSource) /// An instance for processing public static IJoinOn InnerJoin(IDataSource dataSource) { - return new Join(null, dataSource); + return new QueryJoin(null, dataSource); } /// @@ -54,7 +54,7 @@ public static IJoinOn InnerJoin(IDataSource dataSource) /// /// The data source to JOIN with /// An instance for processing - public static IJoinOn Join(IDataSource dataSource) + public static IJoinOn DefaultJoin(IDataSource dataSource) { return InnerJoin(dataSource); } @@ -76,7 +76,7 @@ public static IJoinOn LeftJoin(IDataSource dataSource) /// An instance for processing public static IJoinOn LeftOuterJoin(IDataSource dataSource) { - return new Join("LEFT OUTER", dataSource); + return new QueryJoin("LEFT OUTER", dataSource); } #endregion diff --git a/src/Couchbase.Lite/Query/DataSource.cs b/src/Couchbase.Lite/Query/DataSource.cs index cc6a22f27..02df93b60 100644 --- a/src/Couchbase.Lite/Query/DataSource.cs +++ b/src/Couchbase.Lite/Query/DataSource.cs @@ -1,48 +1,48 @@ -// -// DataSource.cs -// -// Author: -// Jim Borden -// -// Copyright (c) 2017 Couchbase, Inc All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -using Couchbase.Lite.Query; - -namespace Couchbase.Lite.Internal.Query -{ - internal abstract class DataSource : IDataSource - { - #region Properties - - internal object Source { get; } - - #endregion - - #region Constructors - - protected DataSource(object source) - { - Source = source; - } - - #endregion - - #region Public Methods - - public abstract object ToJSON(); - - #endregion - } -} +// +// DataSource.cs +// +// Author: +// Jim Borden +// +// Copyright (c) 2017 Couchbase, Inc All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +using Couchbase.Lite.Query; + +namespace Couchbase.Lite.Internal.Query +{ + internal abstract class QueryDataSource : IDataSource + { + #region Properties + + internal object Source { get; } + + #endregion + + #region Constructors + + protected QueryDataSource(object source) + { + Source = source; + } + + #endregion + + #region Public Methods + + public abstract object ToJSON(); + + #endregion + } +} diff --git a/src/Couchbase.Lite/Query/DatabaseSource.cs b/src/Couchbase.Lite/Query/DatabaseSource.cs index e7e7d380f..e89a47938 100644 --- a/src/Couchbase.Lite/Query/DatabaseSource.cs +++ b/src/Couchbase.Lite/Query/DatabaseSource.cs @@ -1,74 +1,74 @@ -// -// DatabaseSource.cs -// -// Author: -// Jim Borden -// -// Copyright (c) 2017 Couchbase, Inc All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -using System.Collections.Generic; -using Couchbase.Lite.Query; - -namespace Couchbase.Lite.Internal.Query -{ - internal sealed class DatabaseSource : DataSource, IDataSourceAs - { - #region Variables - - private string _as; - - #endregion - - #region Properties - - internal Database Database => Source as Database; - - #endregion - - #region Constructors - - public DatabaseSource(Database database) : base(database) - { - - } - - #endregion - - #region Overrides - - public override object ToJSON() - { - if (_as == null) { - return null; - } - - return new Dictionary { - ["AS"] = _as - }; - } - - #endregion - - #region IDataSourceAs - - public IDataSource As(string alias) - { - _as = alias; - return this; - } - - #endregion - } -} +// +// DatabaseSource.cs +// +// Author: +// Jim Borden +// +// Copyright (c) 2017 Couchbase, Inc All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +using System.Collections.Generic; +using Couchbase.Lite.Query; + +namespace Couchbase.Lite.Internal.Query +{ + internal sealed class DatabaseSource : QueryDataSource, IDataSourceAs + { + #region Variables + + private string _as; + + #endregion + + #region Properties + + internal Database Database => Source as Database; + + #endregion + + #region Constructors + + public DatabaseSource(Database database) : base(database) + { + + } + + #endregion + + #region Overrides + + public override object ToJSON() + { + if (_as == null) { + return null; + } + + return new Dictionary { + ["AS"] = _as + }; + } + + #endregion + + #region IDataSourceAs + + public IDataSource As(string alias) + { + _as = alias; + return this; + } + + #endregion + } +} diff --git a/src/Couchbase.Lite/Query/From.cs b/src/Couchbase.Lite/Query/From.cs index 4d0522c5c..42a05de05 100644 --- a/src/Couchbase.Lite/Query/From.cs +++ b/src/Couchbase.Lite/Query/From.cs @@ -30,7 +30,7 @@ public From(XQuery query, IDataSource impl) { Copy(query); - FromImpl = impl; + FromImpl = impl as QueryDataSource; Database = (impl as DatabaseSource)?.Database; } @@ -40,25 +40,25 @@ public From(XQuery query, IDataSource impl) public object ToJSON() { - return (FromImpl as DataSource)?.ToJSON(); + return FromImpl?.ToJSON(); } #endregion #region IGroupByRouter - public IGroupBy GroupBy(params IGroupBy[] groupBy) + public IGroupBy GroupBy(params IExpression[] expressions) { - return new QueryGroupBy(this, groupBy); + return new QueryGroupBy(this, expressions); } #endregion #region IJoinRouter - public IJoin Join(params IJoin[] @join) + public IJoin Joins(params IJoin[] joins) { - return new Join(this, join); + return new QueryJoin(this, joins); } #endregion diff --git a/src/Couchbase.Lite/Query/Join.cs b/src/Couchbase.Lite/Query/Join.cs index e1c2d0d9b..a8b40de85 100644 --- a/src/Couchbase.Lite/Query/Join.cs +++ b/src/Couchbase.Lite/Query/Join.cs @@ -1,5 +1,5 @@ // -// Join.cs +// QueryJoin.cs // // Author: // Jim Borden @@ -26,7 +26,7 @@ namespace Couchbase.Lite.Internal.Query { - internal sealed class Join : LimitedQuery, IJoinOn + internal sealed class QueryJoin : LimitedQuery, IJoinOn { #region Properties @@ -39,20 +39,20 @@ internal sealed class Join : LimitedQuery, IJoinOn #region Constructors - internal Join(IList joins) + internal QueryJoin(IList joins) { _joins = joins; JoinImpl = this; } - internal Join(XQuery source, IList joins) + internal QueryJoin(XQuery source, IList joins) { Copy(source); _joins = joins; JoinImpl = this; } - internal Join(string joinType, IDataSource dataSource) + internal QueryJoin(string joinType, IDataSource dataSource) { _joinType = joinType; _source = dataSource; @@ -64,14 +64,14 @@ public object ToJSON() { if (_joins != null) { var obj = new List(); - foreach (var o in _joins.OfType()) { + foreach (var o in _joins.OfType()) { obj.Add(o.ToJSON()); } return obj; } - var asObj = (_source as DataSource)?.ToJSON() as Dictionary; + var asObj = (_source as QueryDataSource)?.ToJSON() as Dictionary; if (asObj == null) { throw new InvalidOperationException("Missing AS clause for JOIN"); } diff --git a/src/Couchbase.Lite/Query/QueryGroupBy.cs b/src/Couchbase.Lite/Query/QueryGroupBy.cs index c3fb9d518..c6b2ce8bb 100644 --- a/src/Couchbase.Lite/Query/QueryGroupBy.cs +++ b/src/Couchbase.Lite/Query/QueryGroupBy.cs @@ -27,22 +27,21 @@ namespace Couchbase.Lite.Internal.Query internal sealed class QueryGroupBy : LimitedQuery, IGroupBy { #region Variables - - private readonly IExpression _expression; - private readonly IList _groupings; + + private readonly IList _expressions; #endregion #region Constructors - internal QueryGroupBy(IList groupBy) + internal QueryGroupBy(IList expressions) { - _groupings = groupBy; + _expressions = expressions; GroupByImpl = this; } - internal QueryGroupBy(XQuery query, IList groupBy) - : this(groupBy) + internal QueryGroupBy(XQuery query, IList expressions) + : this(expressions) { Copy(query); GroupByImpl = this; @@ -50,7 +49,7 @@ internal QueryGroupBy(XQuery query, IList groupBy) internal QueryGroupBy(IExpression expression) { - _expression = expression; + _expressions = new[] {expression}; GroupByImpl = this; } @@ -60,14 +59,13 @@ internal QueryGroupBy(IExpression expression) public object ToJSON() { - var exp = _expression as QueryExpression; - if (exp != null) { - return exp.ConvertToJSON(); + if (_expressions.Count == 1) { + return (_expressions.First() as QueryExpression)?.ConvertToJSON(); } - + var obj = new List(); - foreach (var o in _groupings.OfType()) { - obj.Add(o.ToJSON()); + foreach (var o in _expressions.OfType()) { + obj.Add(o.ConvertToJSON()); } return obj; diff --git a/src/Couchbase.Lite/Query/QueryOrdering.cs b/src/Couchbase.Lite/Query/QueryOrdering.cs index 13056401c..ce6f60af7 100644 --- a/src/Couchbase.Lite/Query/QueryOrdering.cs +++ b/src/Couchbase.Lite/Query/QueryOrdering.cs @@ -38,14 +38,14 @@ internal class QueryOrdering : LimitedQuery, IOrdering internal QueryOrdering(IList orderBy) { Orders = orderBy; - OrderingImpl = this; + OrderByImpl = this; } internal QueryOrdering(XQuery query, IList orderBy) : this(orderBy) { Copy(query); - OrderingImpl = this; + OrderByImpl = this; } #endregion diff --git a/src/Couchbase.Lite/Query/Select.cs b/src/Couchbase.Lite/Query/Select.cs index be189e3f8..bbeed8a93 100644 --- a/src/Couchbase.Lite/Query/Select.cs +++ b/src/Couchbase.Lite/Query/Select.cs @@ -66,9 +66,9 @@ public IFrom From(IDataSource dataSource) #region IJoinRouter - public IJoin Join(params IJoin[] @join) + public IJoin Joins(params IJoin[] joins) { - return new Join(this, join); + return new QueryJoin(this, joins); } #endregion diff --git a/src/Couchbase.Lite/Query/Where.cs b/src/Couchbase.Lite/Query/Where.cs index 5171f6e62..09340a8de 100644 --- a/src/Couchbase.Lite/Query/Where.cs +++ b/src/Couchbase.Lite/Query/Where.cs @@ -29,16 +29,16 @@ internal sealed class Where : LimitedQuery, IWhere public Where(XQuery query, IExpression expression) { Copy(query); - WhereImpl = expression; + WhereImpl = expression as QueryExpression; } #endregion #region IGroupByRouter - public IGroupBy GroupBy(params IGroupBy[] groupBy) + public IGroupBy GroupBy(params IExpression[] expressions) { - return new QueryGroupBy(this, groupBy); + return new QueryGroupBy(this, expressions); } #endregion diff --git a/src/Couchbase.Lite/Query/XQuery.cs b/src/Couchbase.Lite/Query/XQuery.cs index 603b6de3b..2e962b573 100644 --- a/src/Couchbase.Lite/Query/XQuery.cs +++ b/src/Couchbase.Lite/Query/XQuery.cs @@ -20,21 +20,21 @@ internal unsafe class XQuery : IQuery, IQueryInternal public IParameters Parameters { get; } = new QueryParameters(); - protected ISelect SelectImpl { get; set; } + protected Select SelectImpl { get; set; } protected bool Distinct { get; set; } - protected IDataSource FromImpl { get; set; } + protected QueryDataSource FromImpl { get; set; } - protected IExpression WhereImpl { get; set; } + protected QueryExpression WhereImpl { get; set; } - protected IOrdering OrderingImpl { get; set; } + protected QueryOrdering OrderByImpl { get; set; } - protected IJoin JoinImpl { get; set; } + protected QueryJoin JoinImpl { get; set; } - protected IGroupBy GroupByImpl { get; set; } + protected QueryGroupBy GroupByImpl { get; set; } - protected IHaving HavingImpl { get; set; } + protected Having HavingImpl { get; set; } protected object SkipValue { get; set; } @@ -81,7 +81,7 @@ public ILiveQuery ToLive() Distinct = Distinct, FromImpl = FromImpl, WhereImpl = WhereImpl, - OrderingImpl = OrderingImpl, + OrderByImpl = OrderByImpl, JoinImpl = JoinImpl, GroupByImpl = GroupByImpl, HavingImpl = HavingImpl, @@ -97,7 +97,7 @@ protected void Copy(XQuery source) Distinct = source.Distinct; FromImpl = source.FromImpl; WhereImpl = source.WhereImpl; - OrderingImpl = source.OrderingImpl; + OrderByImpl = source.OrderByImpl; JoinImpl = source.JoinImpl; GroupByImpl = source.GroupByImpl; HavingImpl = source.HavingImpl; @@ -129,11 +129,8 @@ private void Check() private string EncodeAsJSON() { var parameters = new Dictionary(); - var where = WhereImpl as QueryExpression; - if (where != null) { - parameters["WHERE"] = where.ConvertToJSON(); - } else if (WhereImpl != null) { - throw new NotSupportedException("Custom IWhere not supported"); + if (WhereImpl != null) { + parameters["WHERE"] = WhereImpl.ConvertToJSON(); } if (Distinct) { @@ -147,55 +144,36 @@ private string EncodeAsJSON() if (SkipValue != null) { parameters["OFFSET"] = SkipValue; } - - var orderBy = OrderingImpl as QueryOrdering; - if (orderBy != null) { - parameters["ORDER_BY"] = orderBy.ToJSON(); - } else if (OrderingImpl != null) { - throw new NotSupportedException("Custom IOrdering not supported"); +; + if (OrderByImpl != null) { + parameters["ORDER_BY"] = OrderByImpl.ToJSON(); } - var select = SelectImpl as Select; - if (select != null) { - var selectParam = select.ToJSON(); - if (selectParam != null) { - parameters["WHAT"] = selectParam; - } - } else { - throw new NotSupportedException("Custom ISelect not supported"); + var selectParam = SelectImpl?.ToJSON(); + if (selectParam != null) { + parameters["WHAT"] = selectParam; } - - var join = JoinImpl as Join; - var from = FromImpl as DataSource; - if (join != null) { - var fromJson = from?.ToJSON(); + + if (JoinImpl != null) { + var fromJson = FromImpl?.ToJSON(); if (fromJson == null) { throw new InvalidOperationException( "The default database must have an alias in order to use a JOIN statement" + " (Make sure your data source uses the As() function)"); } - var joinJson = join.ToJSON() as IList; + var joinJson = JoinImpl.ToJSON() as IList; Debug.Assert(joinJson != null); joinJson.Insert(0, fromJson); parameters["FROM"] = joinJson; - } else if(JoinImpl != null) { - throw new NotSupportedException("Custom IJoin not supported"); } - - var groupBy = GroupByImpl as QueryGroupBy; - if (groupBy != null) { - parameters["GROUP_BY"] = groupBy.ToJSON(); - } else if (GroupByImpl != null) { - throw new NotSupportedException("Custom IGroupBy not supported"); - } - - var having = HavingImpl as Having; - if (having != null) { - parameters["HAVING"] = having.ToJSON(); + + if (GroupByImpl != null) { + parameters["GROUP_BY"] = GroupByImpl.ToJSON(); } - else if (HavingImpl != null) { - throw new NotSupportedException("Custom IHaving not supported"); + + if (HavingImpl != null) { + parameters["HAVING"] = HavingImpl.ToJSON(); } return JsonConvert.SerializeObject(parameters);