IGNITE-4121 .NET: add ScanQuery example
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d5e15af7 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d5e15af7 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d5e15af7 Branch: refs/heads/ignite-2693 Commit: d5e15af76044cf65385672f8528d48ecdeca3cb6 Parents: 3a9cbed Author: Pavel Tupitsyn <[email protected]> Authored: Wed Nov 2 12:02:00 2016 +0300 Committer: Pavel Tupitsyn <[email protected]> Committed: Wed Nov 2 12:02:00 2016 +0300 ---------------------------------------------------------------------- .../Datagrid/QueryExample.cs | 24 +++++++++- .../Apache.Ignite.ExamplesDll.csproj | 1 + .../Datagrid/ScanQueryFilter.cs | 50 ++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/d5e15af7/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/QueryExample.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/QueryExample.cs b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/QueryExample.cs index 1c35149..98f9f50 100644 --- a/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/QueryExample.cs +++ b/modules/platforms/dotnet/examples/Apache.Ignite.Examples/Datagrid/QueryExample.cs @@ -19,13 +19,13 @@ namespace Apache.Ignite.Examples.Datagrid { using System; using System.Collections; - using System.Collections.Generic; using Apache.Ignite.Core; using Apache.Ignite.Core.Cache; using Apache.Ignite.Core.Cache.Affinity; using Apache.Ignite.Core.Cache.Configuration; using Apache.Ignite.Core.Cache.Query; using Apache.Ignite.ExamplesDll.Binary; + using Apache.Ignite.ExamplesDll.Datagrid; /// <summary> /// This example populates cache with sample data and runs several SQL and @@ -75,6 +75,9 @@ namespace Apache.Ignite.Examples.Datagrid PopulateCache(employeeCacheColocated); PopulateCache(organizationCache); + // Run scan query example. + ScanQueryExample(employeeCache); + // Run SQL query example. SqlQueryExample(employeeCache); @@ -102,6 +105,23 @@ namespace Apache.Ignite.Examples.Datagrid /// Queries employees that have provided ZIP code in address. /// </summary> /// <param name="cache">Cache.</param> + private static void ScanQueryExample(ICache<int, Employee> cache) + { + const int zip = 94109; + + var qry = cache.Query(new ScanQuery<int, Employee>(new ScanQueryFilter(zip))); + + Console.WriteLine(); + Console.WriteLine(">>> Employees with zipcode {0} (scan):", zip); + + foreach (var entry in qry) + Console.WriteLine(">>> " + entry.Value); + } + + /// <summary> + /// Queries employees that have provided ZIP code in address. + /// </summary> + /// <param name="cache">Cache.</param> private static void SqlQueryExample(ICache<int, Employee> cache) { const int zip = 94109; @@ -109,7 +129,7 @@ namespace Apache.Ignite.Examples.Datagrid var qry = cache.Query(new SqlQuery(typeof(Employee), "zip = ?", zip)); Console.WriteLine(); - Console.WriteLine(">>> Employees with zipcode " + zip + ":"); + Console.WriteLine(">>> Employees with zipcode {0} (SQL):", zip); foreach (var entry in qry) Console.WriteLine(">>> " + entry.Value); http://git-wip-us.apache.org/repos/asf/ignite/blob/d5e15af7/modules/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csproj ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csproj b/modules/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csproj index 41981d8..a41c2f4 100644 --- a/modules/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csproj +++ b/modules/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/Apache.Ignite.ExamplesDll.csproj @@ -49,6 +49,7 @@ <Compile Include="Datagrid\EmployeeStorePredicate.cs" /> <Compile Include="Datagrid\ContinuousQueryFilter.cs" /> <Compile Include="Datagrid\EmployeeStore.cs" /> + <Compile Include="Datagrid\ScanQueryFilter.cs" /> <Compile Include="Events\LocalListener.cs" /> <Compile Include="Messaging\LocalListener.cs" /> <Compile Include="Messaging\RemoteOrderedListener.cs" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/d5e15af7/modules/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/Datagrid/ScanQueryFilter.cs ---------------------------------------------------------------------- diff --git a/modules/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/Datagrid/ScanQueryFilter.cs b/modules/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/Datagrid/ScanQueryFilter.cs new file mode 100644 index 0000000..369b5d0 --- /dev/null +++ b/modules/platforms/dotnet/examples/Apache.Ignite.ExamplesDll/Datagrid/ScanQueryFilter.cs @@ -0,0 +1,50 @@ +/* + * 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.ExamplesDll.Datagrid +{ + using System; + using Apache.Ignite.Core.Cache; + using Apache.Ignite.ExamplesDll.Binary; + + /// <summary> + /// Filter for scan query example. + /// </summary> + [Serializable] + public class ScanQueryFilter : ICacheEntryFilter<int, Employee> + { + /** Zip code to filter on. */ + private readonly int _zipCode; + + /// <summary> + /// Initializes a new instance of the <see cref="ScanQueryFilter"/> class. + /// </summary> + /// <param name="zipCode">The zip code.</param> + public ScanQueryFilter(int zipCode) + { + _zipCode = zipCode; + } + + /// <summary> + /// Returns a value indicating whether provided cache entry satisfies this predicate. + /// </summary> + public bool Invoke(ICacheEntry<int, Employee> entry) + { + return entry.Value.Address.Zip == _zipCode; + } + } +}
