You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2017/03/30 11:50:09 UTC
[40/50] [abbrv] ignite git commit: IGNITE-3539 .NET: Remove
deprecated code
IGNITE-3539 .NET: Remove deprecated code
CacheEvent.LockId removed, CompiledQuery removed, CompiledQuery2 renamed to CompiledQuery
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3f8f4bd2
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3f8f4bd2
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3f8f4bd2
Branch: refs/heads/ignite-3477-master
Commit: 3f8f4bd2f27a973978f6ebab7857e6dab371de8b
Parents: 6f1e970
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Wed Mar 29 13:05:33 2017 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Wed Mar 29 13:05:33 2017 +0300
----------------------------------------------------------------------
.../Cache/Query/CacheLinqTest.cs | 113 ++------
.../Apache.Ignite.Core.Tests/EventsTest.cs | 1 -
.../Apache.Ignite.Core/Events/CacheEvent.cs | 8 -
.../Apache.Ignite.Linq.csproj | 1 -
.../dotnet/Apache.Ignite.Linq/CompiledQuery.cs | 112 +++++---
.../dotnet/Apache.Ignite.Linq/CompiledQuery2.cs | 257 -------------------
.../Datagrid/LinqExample.cs | 2 +-
7 files changed, 106 insertions(+), 388 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/3f8f4bd2/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
index 6d7ddc4..8acf89c 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
@@ -814,7 +814,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
Assert.AreEqual(subSelectCheckCount, subSelectCount, "subselecting another CacheQueryable failed");
var ex = Assert.Throws<NotSupportedException>(() =>
- CompiledQuery2.Compile((int[] k) => cache.Where(x => k.Contains(x.Key))));
+ CompiledQuery.Compile((int[] k) => cache.Where(x => k.Contains(x.Key))));
Assert.AreEqual("'Contains' clause coming from compiled query parameter is not supported.", ex.Message);
}
@@ -995,21 +995,21 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
var roles = GetRoleCache().AsCacheQueryable();
// Embedded args
- var qry0 = CompiledQuery2.Compile(() => persons.Where(x => x.Key < 3 && x.Value.Name.Contains("son")));
+ var qry0 = CompiledQuery.Compile(() => persons.Where(x => x.Key < 3 && x.Value.Name.Contains("son")));
Assert.AreEqual(3, qry0().Count());
// Lambda args
- var qry1 = CompiledQuery2.Compile((int minKey, int take, int skip) => persons.Where(x => x.Key > minKey)
+ var qry1 = CompiledQuery.Compile((int minKey, int take, int skip) => persons.Where(x => x.Key > minKey)
.Take(take).Skip(skip));
Assert.AreEqual(3, qry1(-1, 3, 1).GetAll().Count);
- qry1 = CompiledQuery2.Compile((int skip, int take, int minKey) => persons.Where(x => x.Key > minKey)
+ qry1 = CompiledQuery.Compile((int skip, int take, int minKey) => persons.Where(x => x.Key > minKey)
.Take(take).Skip(skip));
Assert.AreEqual(5, qry1(2, 5, 20).GetAll().Count);
// Mixed args
- var qry2 = CompiledQuery2.Compile((int maxKey, int minKey) =>
+ var qry2 = CompiledQuery.Compile((int maxKey, int minKey) =>
persons.Where(x => x.Key < maxKey
&& x.Value.Name.Contains("er")
&& x.Value.Age < maxKey
@@ -1018,13 +1018,13 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
Assert.AreEqual(6, qry2(10, 1).Count());
// Join
- var qry3 = CompiledQuery2.Compile(() =>
+ var qry3 = CompiledQuery.Compile(() =>
roles.Join(persons, r => r.Key.Foo, p => p.Key, (r, p) => r.Value.Name));
Assert.AreEqual(RoleCount, qry3().Count());
// Join with subquery
- var qry4 = CompiledQuery2.Compile(
+ var qry4 = CompiledQuery.Compile(
(int a, int b, string sep) =>
roles
.Where(x => x.Key.Bar > a)
@@ -1039,12 +1039,12 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
Assert.AreEqual(new[] { " Person_2 =Role_2|", " Person_3 =|"}, qry4(1, PersonCount, "=").ToArray());
// Union
- var qry5 = CompiledQuery2.Compile(() => roles.Select(x => -x.Key.Foo).Union(persons.Select(x => x.Key)));
+ var qry5 = CompiledQuery.Compile(() => roles.Select(x => -x.Key.Foo).Union(persons.Select(x => x.Key)));
Assert.AreEqual(RoleCount + PersonCount, qry5().Count());
// Projection
- var qry6 = CompiledQuery2.Compile((int minAge) => persons
+ var qry6 = CompiledQuery.Compile((int minAge) => persons
.Select(x => x.Value)
.Where(x => x.Age >= minAge)
.Select(x => new {x.Name, x.Age})
@@ -1065,57 +1065,57 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
var cache = GetPersonCache().AsCacheQueryable();
// const args are allowed
- Assert.AreEqual(5, CompiledQuery2.Compile(() => cache.Where(x => x.Key < 5))().GetAll().Count);
+ Assert.AreEqual(5, CompiledQuery.Compile(() => cache.Where(x => x.Key < 5))().GetAll().Count);
// 0 arg
- var qry0 = CompiledQuery2.Compile(() => cache.Select(x => x.Value.Name));
+ var qry0 = CompiledQuery.Compile(() => cache.Select(x => x.Value.Name));
Assert.AreEqual(PersonCount, qry0().ToArray().Length);
// 1 arg
- var qry1 = CompiledQuery2.Compile((int k) => cache.Where(x => x.Key < k));
+ var qry1 = CompiledQuery.Compile((int k) => cache.Where(x => x.Key < k));
Assert.AreEqual(3, qry1(3).ToArray().Length);
// 1 arg twice
- var qry1T = CompiledQuery2.Compile((int k) => cache.Where(x => x.Key < k && x.Value.Age < k));
+ var qry1T = CompiledQuery.Compile((int k) => cache.Where(x => x.Key < k && x.Value.Age < k));
Assert.AreEqual(3, qry1T(3).ToArray().Length);
// 2 arg
var qry2 =
- CompiledQuery2.Compile((int i, string s) => cache.Where(x => x.Key < i && x.Value.Name.StartsWith(s)));
+ CompiledQuery.Compile((int i, string s) => cache.Where(x => x.Key < i && x.Value.Name.StartsWith(s)));
Assert.AreEqual(5, qry2(5, " Pe").ToArray().Length);
// Changed param order
var qry2R =
- CompiledQuery2.Compile((string s, int i) => cache.Where(x => x.Key < i && x.Value.Name.StartsWith(s)));
+ CompiledQuery.Compile((string s, int i) => cache.Where(x => x.Key < i && x.Value.Name.StartsWith(s)));
Assert.AreEqual(5, qry2R(" Pe", 5).ToArray().Length);
// 3 arg
- var qry3 = CompiledQuery2.Compile((int i, string s, double d) =>
+ var qry3 = CompiledQuery.Compile((int i, string s, double d) =>
cache.Where(x => x.Value.Address.Zip > d && x.Key < i && x.Value.Name.Contains(s)));
Assert.AreEqual(5, qry3(5, "son", -10).ToArray().Length);
// 4 arg
- var qry4 = CompiledQuery2.Compile((int a, int b, int c, int d) =>
+ var qry4 = CompiledQuery.Compile((int a, int b, int c, int d) =>
cache.Select(x => x.Key).Where(k => k > a && k > b && k > c && k < d));
Assert.AreEqual(new[] {3, 4}, qry4(0, 1, 2, 5).ToArray());
// 5 arg
- var qry5 = CompiledQuery2.Compile((int a, int b, int c, int d, int e) =>
+ var qry5 = CompiledQuery.Compile((int a, int b, int c, int d, int e) =>
cache.Select(x => x.Key).Where(k => k > a && k > b && k > c && k < d && k < e));
Assert.AreEqual(new[] {3, 4}, qry5(0, 1, 2, 5, 6).ToArray());
// 6 arg
- var qry6 = CompiledQuery2.Compile((int a, int b, int c, int d, int e, int f) =>
+ var qry6 = CompiledQuery.Compile((int a, int b, int c, int d, int e, int f) =>
cache.Select(x => x.Key).Where(k => k > a && k > b && k > c && k < d && k < e && k < f));
Assert.AreEqual(new[] {3, 4}, qry6(0, 1, 2, 5, 6, 7).ToArray());
// 7 arg
- var qry7 = CompiledQuery2.Compile((int a, int b, int c, int d, int e, int f, int g) =>
+ var qry7 = CompiledQuery.Compile((int a, int b, int c, int d, int e, int f, int g) =>
cache.Select(x => x.Key).Where(k => k > a && k > b && k > c && k < d && k < e && k < f && k < g));
Assert.AreEqual(new[] {3, 4}, qry7(0, 1, 2, 5, 6, 7, 8).ToArray());
// 8 arg
- var qry8 = CompiledQuery2.Compile((int a, int b, int c, int d, int e, int f, int g, int h) =>
+ var qry8 = CompiledQuery.Compile((int a, int b, int c, int d, int e, int f, int g, int h) =>
cache.Select(x => x.Key).Where(k => k > a && k > b && k > c && k < d && k < e && k < f && k < g && k < h));
Assert.AreEqual(new[] {3, 4}, qry8(0, 1, 2, 5, 6, 7, 8, 9).ToArray());
}
@@ -1131,19 +1131,19 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
var qry = cache.Where(x => x.Key < 5);
// Simple
- var compiled = CompiledQuery2.Compile(qry);
+ var compiled = CompiledQuery.Compile(qry);
Assert.AreEqual(5, compiled(5).Count());
Assert.AreEqual(6, compiled(6).Count());
// Select
- var compiledSelect = CompiledQuery2.Compile(qry.Select(x => x.Value.Name).OrderBy(x => x));
+ var compiledSelect = CompiledQuery.Compile(qry.Select(x => x.Value.Name).OrderBy(x => x));
Assert.AreEqual(3, compiledSelect(3).Count());
Assert.AreEqual(" Person_0 ", compiledSelect(1).Single());
// Join
- var compiledJoin = CompiledQuery2.Compile(qry.Join(
+ var compiledJoin = CompiledQuery.Compile(qry.Join(
GetOrgCache().AsCacheQueryable().Where(x => x.Value.Name.StartsWith("Org")),
p => p.Value.OrganizationId, o => o.Value.Id, (p, o) => o.Key));
@@ -1156,74 +1156,11 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
.Where(x => x.Value.Address.Zip > 0)
.Where(x => x.Value.Age == 7);
- var compiled2 = CompiledQuery2.Compile(qry2);
+ var compiled2 = CompiledQuery.Compile(qry2);
Assert.AreEqual(17, compiled2(18, 16, "ers", 13, 17).Single().Key);
}
-#pragma warning disable 618 // obsolete class
- /// <summary>
- /// Tests the old, deprecated compiled query.
- /// </summary>
- [Test]
- public void TestCompiledQueryOld()
- {
- var cache = GetPersonCache().AsCacheQueryable();
-
- // const args are not allowed
- Assert.Throws<InvalidOperationException>(() => CompiledQuery.Compile(() => cache.Where(x => x.Key < 5)));
-
- // 0 arg
- var qry0 = CompiledQuery.Compile(() => cache.Select(x => x.Value.Name));
- Assert.AreEqual(PersonCount, qry0().ToArray().Length);
-
- // 1 arg
- var qry1 = CompiledQuery.Compile((int k) => cache.Where(x => x.Key < k));
- Assert.AreEqual(3, qry1(3).ToArray().Length);
-
- // 2 arg
- var qry2 =
- CompiledQuery.Compile((int i, string s) => cache.Where(x => x.Key < i && x.Value.Name.StartsWith(s)));
- Assert.AreEqual(5, qry2(5, " Pe").ToArray().Length);
-
- // Changed param order
- var qry2R =
- CompiledQuery.Compile((string s, int i) => cache.Where(x => x.Key < i && x.Value.Name.StartsWith(s)));
- Assert.AreEqual(5, qry2R(" Pe", 5).ToArray().Length);
-
- // 3 arg
- var qry3 = CompiledQuery.Compile((int i, string s, double d) =>
- cache.Where(x => x.Value.Address.Zip > d && x.Key < i && x.Value.Name.Contains(s)));
- Assert.AreEqual(5, qry3(5, "son", -10).ToArray().Length);
-
- // 4 arg
- var keys = cache.Select(x => x.Key);
- var qry4 = CompiledQuery.Compile((int a, int b, int c, int d) =>
- keys.Where(k => k > a && k > b && k > c && k < d));
- Assert.AreEqual(new[] { 3, 4 }, qry4(0, 1, 2, 5).ToArray());
-
- // 5 arg
- var qry5 = CompiledQuery.Compile((int a, int b, int c, int d, int e) =>
- keys.Where(k => k > a && k > b && k > c && k < d && k < e));
- Assert.AreEqual(new[] { 3, 4 }, qry5(0, 1, 2, 5, 6).ToArray());
-
- // 6 arg
- var qry6 = CompiledQuery.Compile((int a, int b, int c, int d, int e, int f) =>
- keys.Where(k => k > a && k > b && k > c && k < d && k < e && k < f));
- Assert.AreEqual(new[] { 3, 4 }, qry6(0, 1, 2, 5, 6, 7).ToArray());
-
- // 7 arg
- var qry7 = CompiledQuery.Compile((int a, int b, int c, int d, int e, int f, int g) =>
- keys.Where(k => k > a && k > b && k > c && k < d && k < e && k < f && k < g));
- Assert.AreEqual(new[] { 3, 4 }, qry7(0, 1, 2, 5, 6, 7, 8).ToArray());
-
- // 8 arg
- var qry8 = CompiledQuery.Compile((int a, int b, int c, int d, int e, int f, int g, int h) =>
- keys.Where(k => k > a && k > b && k > c && k < d && k < e && k < f && k < g && k < h));
- Assert.AreEqual(new[] { 3, 4 }, qry8(0, 1, 2, 5, 6, 7, 8, 9).ToArray());
- }
-#pragma warning restore 618
-
/// <summary>
/// Tests the cache of primitive types.
/// </summary>
http://git-wip-us.apache.org/repos/asf/ignite/blob/3f8f4bd2/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs
index cc21490..994b334 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/EventsTest.cs
@@ -525,7 +525,6 @@ namespace Apache.Ignite.Core.Tests
Assert.AreEqual(true, cacheEvent.IsNear);
Assert.AreEqual(2, cacheEvent.Key);
Assert.AreEqual(expectedGridGuid, cacheEvent.Xid);
- Assert.AreEqual(null, cacheEvent.LockId);
Assert.AreEqual(4, cacheEvent.NewValue);
Assert.AreEqual(true, cacheEvent.HasNewValue);
Assert.AreEqual(5, cacheEvent.OldValue);
http://git-wip-us.apache.org/repos/asf/ignite/blob/3f8f4bd2/modules/platforms/dotnet/Apache.Ignite.Core/Events/CacheEvent.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Events/CacheEvent.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Events/CacheEvent.cs
index 62687b9..089c04f 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Events/CacheEvent.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Events/CacheEvent.cs
@@ -18,7 +18,6 @@
namespace Apache.Ignite.Core.Events
{
using System;
- using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using Apache.Ignite.Core.Binary;
using Apache.Ignite.Core.Cluster;
@@ -120,13 +119,6 @@ namespace Apache.Ignite.Core.Events
public IgniteGuid? Xid { get { return _xid; } }
/// <summary>
- /// ID of the lock if held or null if no lock held.
- /// </summary>
- [Obsolete("LockId is no longer provided. This property is always null.")]
- [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Compatibility")]
- public object LockId { get { return null; } }
-
- /// <summary>
/// Gets new value for this event.
/// </summary>
public object NewValue { get { return _newValue; } }
http://git-wip-us.apache.org/repos/asf/ignite/blob/3f8f4bd2/modules/platforms/dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.csproj b/modules/platforms/dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.csproj
index 04b4916..a7ec402 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Apache.Ignite.Linq.csproj
@@ -52,7 +52,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CacheExtensions.cs" />
- <Compile Include="CompiledQuery2.cs" />
<Compile Include="CompiledQuery.cs" />
<Compile Include="ICacheQueryable.cs" />
<Compile Include="Impl\AliasDictionary.cs" />
http://git-wip-us.apache.org/repos/asf/ignite/blob/3f8f4bd2/modules/platforms/dotnet/Apache.Ignite.Linq/CompiledQuery.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/CompiledQuery.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/CompiledQuery.cs
index 817c423..e1e1f88 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/CompiledQuery.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/CompiledQuery.cs
@@ -21,14 +21,22 @@ namespace Apache.Ignite.Linq
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
+ using System.Linq.Expressions;
using Apache.Ignite.Core.Cache.Query;
using Apache.Ignite.Core.Impl.Common;
using Apache.Ignite.Linq.Impl;
/// <summary>
+ /// Delegate for compiled query with arbitrary number of arguments.
+ /// </summary>
+ /// <typeparam name="T">Result type.</typeparam>
+ /// <param name="args">The arguments.</param>
+ /// <returns>Query cursor.</returns>
+ public delegate IQueryCursor<T> CompiledQueryFunc<T>(params object[] args);
+
+ /// <summary>
/// Represents a compiled cache query.
/// </summary>
- [Obsolete("Use CompiledQuery2 class.")]
public static class CompiledQuery
{
/// <summary>
@@ -38,27 +46,55 @@ namespace Apache.Ignite.Linq
/// <returns>Delegate that represents the compiled cache query.</returns>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
Justification = "Invalid warning, validation is present.")]
- public static Func<IQueryCursor<T>> Compile<T>(Func<IQueryable<T>> query)
+ public static Func<IQueryCursor<T>> Compile<T>(Expression<Func<IQueryable<T>>> query)
{
IgniteArgumentCheck.NotNull(query, "query");
- var compiledQuery = GetCompiledQuery(query(), query);
+ var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
return () => compiledQuery(new object[0]);
}
/// <summary>
+ /// Creates a new delegate that represents the compiled cache query with any number of arguments.
+ /// <para />
+ /// This method differs from other Compile methods in that it takes in <see cref="ICacheQueryable"/> directly,
+ /// and returns a delegate that takes an array of parameters.
+ /// It is up to the user to provide query arguments in correct order.
+ /// <para />
+ /// This method also imposes no restrictions on where the query comes from (in contrary to other methods).
+ /// </summary>
+ /// <param name="query">The query to compile.</param>
+ /// <returns>Delegate that represents the compiled cache query.</returns>
+ [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
+ Justification = "Invalid warning, validation is present.")]
+ public static CompiledQueryFunc<T> Compile<T>(IQueryable<T> query)
+ {
+ IgniteArgumentCheck.NotNull(query, "query");
+
+ var cacheQueryable = query as ICacheQueryableInternal;
+
+ if (cacheQueryable == null)
+ throw GetInvalidQueryException(query);
+
+ var compileQuery = cacheQueryable.CompileQuery<T>();
+
+ // Special delegate is required to allow params[].
+ return args => compileQuery(args);
+ }
+
+ /// <summary>
/// Creates a new delegate that represents the compiled cache query.
/// </summary>
/// <param name="query">The query to compile.</param>
/// <returns>Delegate that represents the compiled cache query.</returns>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
Justification = "Invalid warning, validation is present.")]
- public static Func<T1, IQueryCursor<T>> Compile<T, T1>(Func<T1, IQueryable<T>> query)
+ public static Func<T1, IQueryCursor<T>> Compile<T, T1>(Expression<Func<T1, IQueryable<T>>> query)
{
IgniteArgumentCheck.NotNull(query, "query");
- var compiledQuery = GetCompiledQuery(query(default(T1)), query);
+ var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
return x => compiledQuery(new object[] {x});
}
@@ -70,12 +106,12 @@ namespace Apache.Ignite.Linq
/// <returns>Delegate that represents the compiled cache query.</returns>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
Justification = "Invalid warning, validation is present.")]
- public static Func<T1, T2, IQueryCursor<T>> Compile<T, T1, T2>(Func<T1, T2,
- IQueryable<T>> query)
+ public static Func<T1, T2, IQueryCursor<T>> Compile<T, T1, T2>(Expression<Func<T1, T2,
+ IQueryable<T>>> query)
{
IgniteArgumentCheck.NotNull(query, "query");
- var compiledQuery = GetCompiledQuery(query(default(T1), default(T2)), query);
+ var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
return (x, y) => compiledQuery(new object[] {x, y});
}
@@ -87,12 +123,12 @@ namespace Apache.Ignite.Linq
/// <returns>Delegate that represents the compiled cache query.</returns>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
Justification = "Invalid warning, validation is present.")]
- public static Func<T1, T2, T3, IQueryCursor<T>> Compile<T, T1, T2, T3>(Func<T1, T2, T3,
- IQueryable<T>> query)
+ public static Func<T1, T2, T3, IQueryCursor<T>> Compile<T, T1, T2, T3>(Expression<Func<T1, T2, T3,
+ IQueryable<T>>> query)
{
IgniteArgumentCheck.NotNull(query, "query");
- var compiledQuery = GetCompiledQuery(query(default(T1), default(T2), default(T3)), query);
+ var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
return (x, y, z) => compiledQuery(new object[] {x, y, z});
}
@@ -104,12 +140,12 @@ namespace Apache.Ignite.Linq
/// <returns>Delegate that represents the compiled cache query.</returns>
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
Justification = "Invalid warning, validation is present.")]
- public static Func<T1, T2, T3, T4, IQueryCursor<T>> Compile<T, T1, T2, T3, T4>(Func<T1, T2, T3, T4,
- IQueryable<T>> query)
+ public static Func<T1, T2, T3, T4, IQueryCursor<T>> Compile<T, T1, T2, T3, T4>(Expression<Func<T1, T2, T3, T4,
+ IQueryable<T>>> query)
{
IgniteArgumentCheck.NotNull(query, "query");
- var compiledQuery = GetCompiledQuery(query(default(T1), default(T2), default(T3), default(T4)), query);
+ var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
return (x, y, z, a) => compiledQuery(new object[] {x, y, z, a});
}
@@ -122,12 +158,11 @@ namespace Apache.Ignite.Linq
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
Justification = "Invalid warning, validation is present.")]
public static Func<T1, T2, T3, T4, T5, IQueryCursor<T>> Compile<T, T1, T2, T3, T4, T5>(
- Func<T1, T2, T3, T4, T5, IQueryable<T>> query)
+ Expression<Func<T1, T2, T3, T4, T5, IQueryable<T>>> query)
{
IgniteArgumentCheck.NotNull(query, "query");
- var compiledQuery =
- GetCompiledQuery(query(default(T1), default(T2), default(T3), default(T4), default(T5)), query);
+ var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
return (x, y, z, a, b) => compiledQuery(new object[] {x, y, z, a, b});
}
@@ -140,12 +175,11 @@ namespace Apache.Ignite.Linq
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
Justification = "Invalid warning, validation is present.")]
public static Func<T1, T2, T3, T4, T5, T6, IQueryCursor<T>> Compile<T, T1, T2, T3, T4, T5, T6>(
- Func<T1, T2, T3, T4, T5, T6, IQueryable<T>> query)
+ Expression<Func<T1, T2, T3, T4, T5, T6, IQueryable<T>>> query)
{
IgniteArgumentCheck.NotNull(query, "query");
- var compiledQuery = GetCompiledQuery(query(default(T1), default(T2), default(T3), default(T4),
- default(T5), default(T6)), query);
+ var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
return (x, y, z, a, b, c) => compiledQuery(new object[] {x, y, z, a, b, c});
}
@@ -158,12 +192,11 @@ namespace Apache.Ignite.Linq
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
Justification = "Invalid warning, validation is present.")]
public static Func<T1, T2, T3, T4, T5, T6, T7, IQueryCursor<T>> Compile<T, T1, T2, T3, T4, T5, T6, T7>(
- Func<T1, T2, T3, T4, T5, T6, T7, IQueryable<T>> query)
+ Expression<Func<T1, T2, T3, T4, T5, T6, T7, IQueryable<T>>> query)
{
IgniteArgumentCheck.NotNull(query, "query");
- var compiledQuery = GetCompiledQuery(query(default(T1), default(T2), default(T3), default(T4),
- default(T5), default(T6), default(T7)), query);
+ var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
return (x, y, z, a, b, c, d) => compiledQuery(new object[] {x, y, z, a, b, c, d});
}
@@ -176,12 +209,11 @@ namespace Apache.Ignite.Linq
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
Justification = "Invalid warning, validation is present.")]
public static Func<T1, T2, T3, T4, T5, T6, T7, T8, IQueryCursor<T>> Compile<T, T1, T2, T3, T4, T5, T6, T7, T8>(
- Func<T1, T2, T3, T4, T5, T6, T7, T8, IQueryable<T>> query)
+ Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, IQueryable<T>>> query)
{
IgniteArgumentCheck.NotNull(query, "query");
- var compiledQuery = GetCompiledQuery(query(default(T1), default(T2), default(T3), default(T4),
- default(T5), default(T6), default(T7), default(T8)), query);
+ var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
return (x, y, z, a, b, c, d, e) => compiledQuery(new object[] {x, y, z, a, b, c, d, e});
}
@@ -189,21 +221,37 @@ namespace Apache.Ignite.Linq
/// <summary>
/// Gets the compiled query.
/// </summary>
- private static Func<object[], IQueryCursor<T>> GetCompiledQuery<T>(IQueryable<T> queryable,
+ private static Func<object[], IQueryCursor<T>> GetCompiledQuery<T>(LambdaExpression expression,
Delegate queryCaller)
{
+ Debug.Assert(expression != null);
Debug.Assert(queryCaller != null);
+ // Get default parameter values.
+ var paramValues = expression.Parameters
+ .Select(x => x.Type)
+ .Select(x => x.IsValueType ? Activator.CreateInstance(x) : null)
+ .ToArray();
+
+ // Invoke the delegate to obtain the cacheQueryable.
+ var queryable = queryCaller.DynamicInvoke(paramValues);
+
var cacheQueryable = queryable as ICacheQueryableInternal;
if (cacheQueryable == null)
- throw new ArgumentException(
- string.Format("{0} can only compile cache queries produced by AsCacheQueryable method. " +
- "Provided query is not valid: '{1}'", typeof (CompiledQuery).FullName, queryable));
+ throw GetInvalidQueryException(queryable);
- Debug.WriteLine(queryable);
+ return cacheQueryable.CompileQuery<T>(expression);
+ }
- return cacheQueryable.CompileQuery<T>(queryCaller);
+ /// <summary>
+ /// Gets the invalid query exception.
+ /// </summary>
+ private static ArgumentException GetInvalidQueryException(object queryable)
+ {
+ return new ArgumentException(
+ string.Format("{0} can only compile cache queries produced by AsCacheQueryable method. " +
+ "Provided query is not valid: '{1}'", typeof(CompiledQuery).FullName, queryable));
}
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/3f8f4bd2/modules/platforms/dotnet/Apache.Ignite.Linq/CompiledQuery2.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/CompiledQuery2.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/CompiledQuery2.cs
deleted file mode 100644
index 4131992..0000000
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/CompiledQuery2.cs
+++ /dev/null
@@ -1,257 +0,0 @@
-\ufeff/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-namespace Apache.Ignite.Linq
-{
- using System;
- using System.Diagnostics;
- using System.Diagnostics.CodeAnalysis;
- using System.Linq;
- using System.Linq.Expressions;
- using Apache.Ignite.Core.Cache.Query;
- using Apache.Ignite.Core.Impl.Common;
- using Apache.Ignite.Linq.Impl;
-
- /// <summary>
- /// Delegate for compiled query with arbitrary number of arguments.
- /// </summary>
- /// <typeparam name="T">Result type.</typeparam>
- /// <param name="args">The arguments.</param>
- /// <returns>Query cursor.</returns>
- public delegate IQueryCursor<T> CompiledQueryFunc<T>(params object[] args);
-
- /// <summary>
- /// Represents a compiled cache query.
- /// </summary>
- public static class CompiledQuery2
- {
- /// <summary>
- /// Creates a new delegate that represents the compiled cache query.
- /// </summary>
- /// <param name="query">The query to compile.</param>
- /// <returns>Delegate that represents the compiled cache query.</returns>
- [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
- Justification = "Invalid warning, validation is present.")]
- public static Func<IQueryCursor<T>> Compile<T>(Expression<Func<IQueryable<T>>> query)
- {
- IgniteArgumentCheck.NotNull(query, "query");
-
- var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
-
- return () => compiledQuery(new object[0]);
- }
-
- /// <summary>
- /// Creates a new delegate that represents the compiled cache query with any number of arguments.
- /// <para />
- /// This method differs from other Compile methods in that it takes in <see cref="ICacheQueryable"/> directly,
- /// and returns a delegate that takes an array of parameters.
- /// It is up to the user to provide query arguments in correct order.
- /// <para />
- /// This method also imposes no restrictions on where the query comes from (in contrary to other methods).
- /// </summary>
- /// <param name="query">The query to compile.</param>
- /// <returns>Delegate that represents the compiled cache query.</returns>
- [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
- Justification = "Invalid warning, validation is present.")]
- public static CompiledQueryFunc<T> Compile<T>(IQueryable<T> query)
- {
- IgniteArgumentCheck.NotNull(query, "query");
-
- var cacheQueryable = query as ICacheQueryableInternal;
-
- if (cacheQueryable == null)
- throw GetInvalidQueryException(query);
-
- var compileQuery = cacheQueryable.CompileQuery<T>();
-
- // Special delegate is required to allow params[].
- return args => compileQuery(args);
- }
-
- /// <summary>
- /// Creates a new delegate that represents the compiled cache query.
- /// </summary>
- /// <param name="query">The query to compile.</param>
- /// <returns>Delegate that represents the compiled cache query.</returns>
- [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
- Justification = "Invalid warning, validation is present.")]
- public static Func<T1, IQueryCursor<T>> Compile<T, T1>(Expression<Func<T1, IQueryable<T>>> query)
- {
- IgniteArgumentCheck.NotNull(query, "query");
-
- var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
-
- return x => compiledQuery(new object[] {x});
- }
-
- /// <summary>
- /// Creates a new delegate that represents the compiled cache query.
- /// </summary>
- /// <param name="query">The query to compile.</param>
- /// <returns>Delegate that represents the compiled cache query.</returns>
- [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
- Justification = "Invalid warning, validation is present.")]
- public static Func<T1, T2, IQueryCursor<T>> Compile<T, T1, T2>(Expression<Func<T1, T2,
- IQueryable<T>>> query)
- {
- IgniteArgumentCheck.NotNull(query, "query");
-
- var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
-
- return (x, y) => compiledQuery(new object[] {x, y});
- }
-
- /// <summary>
- /// Creates a new delegate that represents the compiled cache query.
- /// </summary>
- /// <param name="query">The query to compile.</param>
- /// <returns>Delegate that represents the compiled cache query.</returns>
- [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
- Justification = "Invalid warning, validation is present.")]
- public static Func<T1, T2, T3, IQueryCursor<T>> Compile<T, T1, T2, T3>(Expression<Func<T1, T2, T3,
- IQueryable<T>>> query)
- {
- IgniteArgumentCheck.NotNull(query, "query");
-
- var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
-
- return (x, y, z) => compiledQuery(new object[] {x, y, z});
- }
-
- /// <summary>
- /// Creates a new delegate that represents the compiled cache query.
- /// </summary>
- /// <param name="query">The query to compile.</param>
- /// <returns>Delegate that represents the compiled cache query.</returns>
- [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
- Justification = "Invalid warning, validation is present.")]
- public static Func<T1, T2, T3, T4, IQueryCursor<T>> Compile<T, T1, T2, T3, T4>(Expression<Func<T1, T2, T3, T4,
- IQueryable<T>>> query)
- {
- IgniteArgumentCheck.NotNull(query, "query");
-
- var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
-
- return (x, y, z, a) => compiledQuery(new object[] {x, y, z, a});
- }
-
- /// <summary>
- /// Creates a new delegate that represents the compiled cache query.
- /// </summary>
- /// <param name="query">The query to compile.</param>
- /// <returns>Delegate that represents the compiled cache query.</returns>
- [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
- Justification = "Invalid warning, validation is present.")]
- public static Func<T1, T2, T3, T4, T5, IQueryCursor<T>> Compile<T, T1, T2, T3, T4, T5>(
- Expression<Func<T1, T2, T3, T4, T5, IQueryable<T>>> query)
- {
- IgniteArgumentCheck.NotNull(query, "query");
-
- var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
-
- return (x, y, z, a, b) => compiledQuery(new object[] {x, y, z, a, b});
- }
-
- /// <summary>
- /// Creates a new delegate that represents the compiled cache query.
- /// </summary>
- /// <param name="query">The query to compile.</param>
- /// <returns>Delegate that represents the compiled cache query.</returns>
- [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
- Justification = "Invalid warning, validation is present.")]
- public static Func<T1, T2, T3, T4, T5, T6, IQueryCursor<T>> Compile<T, T1, T2, T3, T4, T5, T6>(
- Expression<Func<T1, T2, T3, T4, T5, T6, IQueryable<T>>> query)
- {
- IgniteArgumentCheck.NotNull(query, "query");
-
- var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
-
- return (x, y, z, a, b, c) => compiledQuery(new object[] {x, y, z, a, b, c});
- }
-
- /// <summary>
- /// Creates a new delegate that represents the compiled cache query.
- /// </summary>
- /// <param name="query">The query to compile.</param>
- /// <returns>Delegate that represents the compiled cache query.</returns>
- [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
- Justification = "Invalid warning, validation is present.")]
- public static Func<T1, T2, T3, T4, T5, T6, T7, IQueryCursor<T>> Compile<T, T1, T2, T3, T4, T5, T6, T7>(
- Expression<Func<T1, T2, T3, T4, T5, T6, T7, IQueryable<T>>> query)
- {
- IgniteArgumentCheck.NotNull(query, "query");
-
- var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
-
- return (x, y, z, a, b, c, d) => compiledQuery(new object[] {x, y, z, a, b, c, d});
- }
-
- /// <summary>
- /// Creates a new delegate that represents the compiled cache query.
- /// </summary>
- /// <param name="query">The query to compile.</param>
- /// <returns>Delegate that represents the compiled cache query.</returns>
- [SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0",
- Justification = "Invalid warning, validation is present.")]
- public static Func<T1, T2, T3, T4, T5, T6, T7, T8, IQueryCursor<T>> Compile<T, T1, T2, T3, T4, T5, T6, T7, T8>(
- Expression<Func<T1, T2, T3, T4, T5, T6, T7, T8, IQueryable<T>>> query)
- {
- IgniteArgumentCheck.NotNull(query, "query");
-
- var compiledQuery = GetCompiledQuery<T>(query, query.Compile());
-
- return (x, y, z, a, b, c, d, e) => compiledQuery(new object[] {x, y, z, a, b, c, d, e});
- }
-
- /// <summary>
- /// Gets the compiled query.
- /// </summary>
- private static Func<object[], IQueryCursor<T>> GetCompiledQuery<T>(LambdaExpression expression,
- Delegate queryCaller)
- {
- Debug.Assert(expression != null);
- Debug.Assert(queryCaller != null);
-
- // Get default parameter values.
- var paramValues = expression.Parameters
- .Select(x => x.Type)
- .Select(x => x.IsValueType ? Activator.CreateInstance(x) : null)
- .ToArray();
-
- // Invoke the delegate to obtain the cacheQueryable.
- var queryable = queryCaller.DynamicInvoke(paramValues);
-
- var cacheQueryable = queryable as ICacheQueryableInternal;
-
- if (cacheQueryable == null)
- throw GetInvalidQueryException(queryable);
-
- return cacheQueryable.CompileQuery<T>(expression);
- }
-
- /// <summary>
- /// Gets the invalid query exception.
- /// </summary>
- private static ArgumentException GetInvalidQueryException(object queryable)
- {
- return new ArgumentException(
- string.Format("{0} can only compile cache queries produced by AsCacheQueryable method. " +
- "Provided query is not valid: '{1}'", typeof(CompiledQuery2).FullName, queryable));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ignite/blob/3f8f4bd2/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/LinqExample.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/LinqExample.cs b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/LinqExample.cs
index 7af8569..1f8b71b 100644
--- a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/LinqExample.cs
+++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/LinqExample.cs
@@ -127,7 +127,7 @@ namespace Apache.Ignite.Examples.Datagrid
// Compile cache query to eliminate LINQ overhead on multiple runs.
Func<int, IQueryCursor<ICacheEntry<int, Employee>>> qry =
- CompiledQuery2.Compile((int z) => cache0.Where(emp => emp.Value.Address.Zip == z));
+ CompiledQuery.Compile((int z) => cache0.Where(emp => emp.Value.Address.Zip == z));
Console.WriteLine();
Console.WriteLine(">>> Employees with zipcode {0} using compiled query:", zip);