ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptupit...@apache.org
Subject ignite git commit: IGNITE-3709 .NET: Support primitive type names in QueryEntity
Date Fri, 19 Aug 2016 15:26:34 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 4b87830da -> f0c3b343e


IGNITE-3709 .NET: Support primitive type names in QueryEntity


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

Branch: refs/heads/master
Commit: f0c3b343e4870ee6cbc2e150ffc2afe9e5ce29af
Parents: 4b87830
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Fri Aug 19 18:26:26 2016 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Fri Aug 19 18:26:26 2016 +0300

----------------------------------------------------------------------
 .../Binary/JavaTypeMappingTest.cs               | 18 +++++++-
 .../Cache/Query/CacheQueriesTest.cs             | 45 ++++++++++----------
 .../Config/cache-query.xml                      | 38 +++++++++++------
 .../Apache.Ignite.Core/Impl/Binary/JavaTypes.cs | 19 ++++++++-
 4 files changed, 82 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f0c3b343/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/JavaTypeMappingTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/JavaTypeMappingTest.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/JavaTypeMappingTest.cs
index 35d9a2e..10f7cb7 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/JavaTypeMappingTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Binary/JavaTypeMappingTest.cs
@@ -83,14 +83,30 @@ namespace Apache.Ignite.Core.Tests.Binary
         public void TestJavaToDotNetMapping()
         {
             Assert.AreEqual(typeof(bool), JavaTypes.GetDotNetType("java.lang.Boolean"));
+            Assert.AreEqual(typeof(bool), JavaTypes.GetDotNetType("boolean"));
+
             Assert.AreEqual(typeof(byte), JavaTypes.GetDotNetType("java.lang.Byte"));
+            Assert.AreEqual(typeof(byte), JavaTypes.GetDotNetType("byte"));
+
             Assert.AreEqual(typeof(short), JavaTypes.GetDotNetType("java.lang.Short"));
+            Assert.AreEqual(typeof(short), JavaTypes.GetDotNetType("short"));
+
             Assert.AreEqual(typeof(int), JavaTypes.GetDotNetType("java.lang.Integer"));
+            Assert.AreEqual(typeof(int), JavaTypes.GetDotNetType("int"));
+
             Assert.AreEqual(typeof(long), JavaTypes.GetDotNetType("java.lang.Long"));
+            Assert.AreEqual(typeof(long), JavaTypes.GetDotNetType("long"));
+
             Assert.AreEqual(typeof(float), JavaTypes.GetDotNetType("java.lang.Float"));
+            Assert.AreEqual(typeof(float), JavaTypes.GetDotNetType("float"));
+
             Assert.AreEqual(typeof(double), JavaTypes.GetDotNetType("java.lang.Double"));
-            Assert.AreEqual(typeof(decimal), JavaTypes.GetDotNetType("java.math.BigDecimal"));
+            Assert.AreEqual(typeof(double), JavaTypes.GetDotNetType("double"));
+
             Assert.AreEqual(typeof(char), JavaTypes.GetDotNetType("java.lang.Character"));
+            Assert.AreEqual(typeof(char), JavaTypes.GetDotNetType("char"));
+
+            Assert.AreEqual(typeof(decimal), JavaTypes.GetDotNetType("java.math.BigDecimal"));
             Assert.AreEqual(typeof(string), JavaTypes.GetDotNetType("java.lang.String"));
             Assert.AreEqual(typeof(DateTime), JavaTypes.GetDotNetType("java.sql.Timestamp"));
             Assert.AreEqual(typeof(Guid), JavaTypes.GetDotNetType("java.util.UUID"));

http://git-wip-us.apache.org/repos/asf/ignite/blob/f0c3b343/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs
b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs
index a8ffe13..9d6f8fb 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheQueriesTest.cs
@@ -123,32 +123,20 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         }
 
         /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="idx"></param>
-        /// <returns></returns>
-        private IIgnite GetIgnite(int idx)
-        {
-            return Ignition.GetIgnite("grid-" + idx);
-        }
-
-        /// <summary>
-        /// 
+        /// Gets the ignite.
         /// </summary>
-        /// <param name="idx"></param>
-        /// <returns></returns>
-        private ICache<int, QueryPerson> Cache(int idx)
+        private static IIgnite GetIgnite()
         {
-            return GetIgnite(idx).GetCache<int, QueryPerson>(CacheName);
+            return Ignition.GetIgnite("grid-0");
         }
 
         /// <summary>
         /// 
         /// </summary>
         /// <returns></returns>
-        private ICache<int, QueryPerson> Cache()
+        private static ICache<int, QueryPerson> Cache()
         {
-            return Cache(0);
+            return GetIgnite().GetCache<int, QueryPerson>(CacheName);
         }
 
         /// <summary>
@@ -236,8 +224,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
             Cache().Put(4, new QueryPerson("Unknown", 60));
 
             // 1. Empty result set.
-            using (
-                IQueryCursor<ICacheEntry<int, QueryPerson>> cursor =
+            using (IQueryCursor<ICacheEntry<int, QueryPerson>> cursor =
                     Cache().Query(new SqlQuery(typeof(QueryPerson), "age = 100")))
             {
                 IEnumerator<ICacheEntry<int, QueryPerson>> e = cursor.GetEnumerator();
@@ -251,6 +238,8 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
                     { ICacheEntry<int, QueryPerson> entry = e.Current; });
 
                 Assert.Throws<NotSupportedException>(() => e.Reset());
+
+                e.Dispose();
             }
 
             SqlQuery qry = new SqlQuery(typeof (QueryPerson), "age < 60");
@@ -446,7 +435,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         [Test]
         public void TestIndexingDisabledError()
         {
-            var cache = GetIgnite(0).GetOrCreateCache<int, QueryPerson>("nonindexed_cache");
+            var cache = GetIgnite().GetOrCreateCache<int, QueryPerson>("nonindexed_cache");
 
             var queries = new QueryBase[]
             {
@@ -552,14 +541,14 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         [Test]
         public void TestDistributedJoins()
         {
-            var cache = GetIgnite(0).GetOrCreateCache<int, QueryPerson>(
+            var cache = GetIgnite().GetOrCreateCache<int, QueryPerson>(
                 new CacheConfiguration("replicatedCache")
                 {
                     QueryEntities = new[]
                     {
                         new QueryEntity(typeof(int), typeof(QueryPerson))
                         {
-                            Fields = new[] {new QueryField("age", typeof(int))}
+                            Fields = new[] {new QueryField("age", "int")}
                         }
                     }
                 });
@@ -585,6 +574,18 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
         }
 
         /// <summary>
+        /// Tests the get configuration.
+        /// </summary>
+        [Test]
+        public void TestGetConfiguration()
+        {
+            var entity = Cache().GetConfiguration().QueryEntities.Single();
+
+            Assert.AreEqual(typeof(int), entity.Fields.Single(x => x.Name == "age").FieldType);
+            Assert.AreEqual(typeof(string), entity.Fields.Single(x => x.Name == "name").FieldType);
+        }
+
+        /// <summary>
         /// Validates the query results.
         /// </summary>
         /// <param name="cache">Cache.</param>

http://git-wip-us.apache.org/repos/asf/ignite/blob/f0c3b343/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-query.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-query.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-query.xml
index b0dc48f..dd5d4d9 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-query.xml
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/cache-query.xml
@@ -57,24 +57,34 @@
                     <property name="atomicityMode" value="TRANSACTIONAL"/>
                     <property name="writeSynchronizationMode" value="FULL_SYNC"/>
 
-                    <property name="typeMetadata">
+                    <property name="queryEntities">
                         <list>
-                            <bean class="org.apache.ignite.cache.CacheTypeMetadata">
+                            <bean class="org.apache.ignite.cache.QueryEntity">
                                 <property name="valueType" value="QueryPerson"/>
-                                <property name="ascendingFields">
-                                    <map>
-                                        <entry key="age" value="java.lang.Integer"/>
-                                    </map>
+                                <property name="fields">
+                                    <util:map map-class="java.util.LinkedHashMap">
+                                        <entry key="age" value="int" />
+                                        <entry key="name" value="java.lang.String" />
+                                    </util:map>
                                 </property>
-                                <property name="queryFields">
-                                    <map>
-                                        <entry key="name" value="java.lang.String"/>
-                                        <entry key="age" value="java.lang.Integer"/>
-                                    </map>
-                                </property>
-                                <property name="textFields">
+                                <property name="indexes">
                                     <list>
-                                        <value>name</value>
+                                        <bean class="org.apache.ignite.cache.QueryIndex">
+                                            <property name="fields">
+                                                <map>
+                                                    <entry key="name" value="true"/>
+                                                </map>
+                                            </property>
+                                            <property name="indexType" value="FULLTEXT"/>
+                                        </bean>
+                                        <bean class="org.apache.ignite.cache.QueryIndex">
+                                            <property name="fields">
+                                                <map>
+                                                    <entry key="age" value="true"/>
+                                                </map>
+                                            </property>
+                                            <property name="indexType" value="SORTED"/>
+                                        </bean>
                                     </list>
                                 </property>
                             </bean>

http://git-wip-us.apache.org/repos/asf/ignite/blob/f0c3b343/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs
index 7d71280..d1395d2 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Binary/JavaTypes.cs
@@ -61,6 +61,19 @@ namespace Apache.Ignite.Core.Impl.Binary
         private static readonly Dictionary<string, Type> JavaToNet =
             NetToJava.GroupBy(x => x.Value).ToDictionary(g => g.Key, g => g.First().Key);
 
+        /** */
+        private static readonly Dictionary<string, string> JavaPrimitiveToType = new
Dictionary<string, string>
+        {
+            {"boolean", "java.lang.Boolean"},
+            {"byte", "java.lang.Byte"},
+            {"short", "java.lang.Short"},
+            {"char", "java.lang.Character"},
+            {"int", "java.lang.Integer"},
+            {"long", "java.lang.Long"},
+            {"float", "java.lang.Float"},
+            {"double", "java.lang.Double"},
+        };
+
         /// <summary>
         /// Gets the corresponding Java type name.
         /// </summary>
@@ -119,9 +132,13 @@ namespace Apache.Ignite.Core.Impl.Binary
             if (string.IsNullOrEmpty(javaTypeName))
                 return null;
 
+            string fullJavaTypeName;
+
+            JavaPrimitiveToType.TryGetValue(javaTypeName, out fullJavaTypeName);
+
             Type res;
 
-            return JavaToNet.TryGetValue(javaTypeName, out res) ? res : null;
+            return JavaToNet.TryGetValue(fullJavaTypeName ?? javaTypeName, out res) ? res
: null;
         }
     }
 }


Mime
View raw message