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:49:58 UTC

[29/50] [abbrv] ignite git commit: IGNITE-4870 .NET: QueryEntity.TableName

IGNITE-4870 .NET: QueryEntity.TableName


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/738bb122
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/738bb122
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/738bb122

Branch: refs/heads/ignite-3477-master
Commit: 738bb1224737ec6368ee944cb8a3bafb67d7b151
Parents: 58b31b9
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Tue Mar 28 11:49:45 2017 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Tue Mar 28 11:49:45 2017 +0300

----------------------------------------------------------------------
 .../platform/utils/PlatformConfigurationUtils.java       |  2 ++
 .../Cache/CacheConfigurationTest.cs                      |  2 ++
 .../Cache/Query/CacheLinqTest.cs                         | 11 +++++++++--
 .../Cache/Query/CacheQueriesCodeConfigurationTest.cs     |  7 +++++++
 .../Cache/Configuration/QueryEntity.cs                   |  8 ++++++++
 .../Apache.Ignite.Linq/Impl/CacheFieldsQueryProvider.cs  | 10 +++++++++-
 6 files changed, 37 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/738bb122/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
index bce3735..b2926e3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
@@ -469,6 +469,7 @@ public class PlatformConfigurationUtils {
 
         res.setKeyType(in.readString());
         res.setValueType(in.readString());
+        res.setTableName(in.readString());
 
         // Fields
         int cnt = in.readInt();
@@ -899,6 +900,7 @@ public class PlatformConfigurationUtils {
 
         writer.writeString(queryEntity.getKeyType());
         writer.writeString(queryEntity.getValueType());
+        writer.writeString(queryEntity.getTableName());
 
         // Fields
         LinkedHashMap<String, String> fields = queryEntity.getFields();

http://git-wip-us.apache.org/repos/asf/ignite/blob/738bb122/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
index 7a30780..1e02399 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
@@ -356,6 +356,7 @@ namespace Apache.Ignite.Core.Tests.Cache
 
             Assert.AreEqual(x.KeyTypeName, y.KeyTypeName);
             Assert.AreEqual(x.ValueTypeName, y.ValueTypeName);
+            Assert.AreEqual(x.TableName, y.TableName);
 
             AssertConfigsAreEqual(x.Fields, y.Fields);
             AssertConfigsAreEqual(x.Aliases, y.Aliases);
@@ -630,6 +631,7 @@ namespace Apache.Ignite.Core.Tests.Cache
                     {
                         KeyTypeName = "Integer",
                         ValueTypeName = "java.lang.String",
+                        TableName = "MyTable",
                         Fields = new[]
                         {
                             new QueryField("length", typeof(int)), 

http://git-wip-us.apache.org/repos/asf/ignite/blob/738bb122/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 7897ea7..6d7ddc4 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
@@ -1456,8 +1456,15 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         private static ICache<int, Person> GetSecondPersonCache()
         {
             return Ignition.GetIgnite()
-                .GetOrCreateCache<int, Person>(new CacheConfiguration(PersonSecondCacheName,
-                    new QueryEntity(typeof (int), typeof (Person))) {CacheMode = CacheMode.Replicated});
+                .GetOrCreateCache<int, Person>(
+                    new CacheConfiguration(PersonSecondCacheName,
+                        new QueryEntity(typeof(int), typeof(Person))
+                        {
+                            TableName = "CustomPersons"
+                        })
+                    {
+                        CacheMode = CacheMode.Replicated
+                    });
         }
 
         /// <summary>

http://git-wip-us.apache.org/repos/asf/ignite/blob/738bb122/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs
index 22088d6..8157a56 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesCodeConfigurationTest.cs
@@ -49,6 +49,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
                 {
                     new CacheConfiguration(CacheName, new QueryEntity(typeof (int), typeof (QueryPerson))
                     {
+                        TableName = "CustomTableName",
                         Fields = new[]
                         {
                             new QueryField("Name", typeof (string)),
@@ -78,6 +79,12 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
                     Assert.AreEqual(2, cursor.GetAll().Single().Key);
                 }
 
+                using (var cursor = cache.QueryFields(new SqlFieldsQuery(
+                    "select _key from CustomTableName where age > ? and birthday < ?", 10, DateTime.UtcNow)))
+                {
+                    Assert.AreEqual(2, cursor.GetAll().Single()[0]);
+                }
+
                 using (var cursor = cache.Query(new TextQuery(typeof (QueryPerson), "Ar*")))
                 {
                     Assert.AreEqual(1, cursor.GetAll().Single().Key);

http://git-wip-us.apache.org/repos/asf/ignite/blob/738bb122/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
index 2cd0295..b67f206 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/QueryEntity.cs
@@ -148,6 +148,12 @@ namespace Apache.Ignite.Core.Cache.Configuration
         }
 
         /// <summary>
+        /// Gets or sets the name of the SQL table.
+        /// When not set, value type name is used.
+        /// </summary>
+        public string TableName { get; set; }
+
+        /// <summary>
         /// Gets or sets query fields, a map from field name to Java type name. 
         /// The order of fields defines the order of columns returned by the 'select *' queries.
         /// </summary>
@@ -176,6 +182,7 @@ namespace Apache.Ignite.Core.Cache.Configuration
         {
             KeyTypeName = reader.ReadString();
             ValueTypeName = reader.ReadString();
+            TableName = reader.ReadString();
 
             var count = reader.ReadInt();
             Fields = count == 0
@@ -199,6 +206,7 @@ namespace Apache.Ignite.Core.Cache.Configuration
         {
             writer.WriteString(KeyTypeName);
             writer.WriteString(ValueTypeName);
+            writer.WriteString(TableName);
 
             if (Fields != null)
             {

http://git-wip-us.apache.org/repos/asf/ignite/blob/738bb122/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryProvider.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryProvider.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryProvider.cs
index 3f5fe34..e909575 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryProvider.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheFieldsQueryProvider.cs
@@ -187,7 +187,7 @@ namespace Apache.Ignite.Linq.Impl
             // Split on '.' to throw away Java type namespace
             var validTableNames = _cacheConfiguration.QueryEntities == null
                 ? null
-                : _cacheConfiguration.QueryEntities.Select(e => e.ValueTypeName.Split('.').Last()).ToArray();
+                : _cacheConfiguration.QueryEntities.Select(GetTableName).ToArray();
 
             if (validTableNames == null || !validTableNames.Any())
                 throw new CacheException(string.Format("Queries are not configured for cache '{0}'",
@@ -197,6 +197,14 @@ namespace Apache.Ignite.Linq.Impl
         }
 
         /// <summary>
+        /// Gets the name of the SQL table.
+        /// </summary>
+        private static string GetTableName(QueryEntity e)
+        {
+            return e.TableName ?? e.ValueTypeName.Split('.').Last();
+        }
+
+        /// <summary>
         /// Infers the name of the table from cache configuration.
         /// </summary>
         /// <param name="cacheValueType"></param>