You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by il...@apache.org on 2020/07/07 09:17:52 UTC

[ignite] branch master updated: IGNITE-13216 "Name" parameter of QuerySqlField annotation that was ignored during uniqueness validation of field's name - Fixes #7993.

This is an automated email from the ASF dual-hosted git repository.

ilyak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 48700d9  IGNITE-13216 "Name" parameter of QuerySqlField annotation that was ignored during uniqueness validation of field's name - Fixes #7993.
48700d9 is described below

commit 48700d96b3810603af0b1101e642ee1af927972b
Author: Evgeniy Rudenko <er...@gridgain.com>
AuthorDate: Tue Jul 7 12:15:05 2020 +0300

    IGNITE-13216 "Name" parameter of QuerySqlField annotation that was ignored during uniqueness validation of field's name - Fixes #7993.
    
    Signed-off-by: Ilya Kasnacheev <il...@gmail.com>
---
 .../java/org/apache/ignite/cache/QueryEntity.java  |  2 +-
 .../cache/query/QueryEntityTypeDescriptor.java     | 14 ++++-
 .../cache/index/QueryEntityValidationSelfTest.java | 68 ++++++++++++++++++++++
 3 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
index 249c249..affff27 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
@@ -826,7 +826,7 @@ public class QueryEntity implements Serializable {
                     // resulting parent column comes before columns corresponding to those
                     // nested properties in the resulting table - that way nested
                     // properties override will happen properly (first parent, then children).
-                    type.addProperty(prop, key, true);
+                    type.addProperty(prop, sqlAnn, key, true);
 
                     processAnnotation(key, sqlAnn, txtAnn, cls, c, field.getType(), prop, type);
                 }
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryEntityTypeDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryEntityTypeDescriptor.java
index acdcb20..d9c680b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryEntityTypeDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryEntityTypeDescriptor.java
@@ -26,9 +26,11 @@ import java.util.Set;
 import javax.cache.CacheException;
 import org.apache.ignite.cache.QueryIndex;
 import org.apache.ignite.cache.QueryIndexType;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
 import org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.jetbrains.annotations.NotNull;
 
@@ -162,12 +164,18 @@ public class QueryEntityTypeDescriptor {
      * Adds property to the type descriptor.
      *
      * @param prop Property.
+     * @param sqlAnn SQL annotation, can be {@code null}.
      * @param key Property ownership flag (key or not).
      * @param failOnDuplicate Fail on duplicate flag.
      */
-    public void addProperty(QueryEntityClassProperty prop, boolean key, boolean failOnDuplicate) {
-        if (props.put(prop.name(), prop) != null && failOnDuplicate) {
-            throw new CacheException("Property with name '" + prop.name() + "' already exists for " +
+    public void addProperty(QueryEntityClassProperty prop, QuerySqlField sqlAnn, boolean key, boolean failOnDuplicate) {
+        String propName = prop.name();
+
+        if (sqlAnn != null && !F.isEmpty(sqlAnn.name()))
+            propName = sqlAnn.name();
+
+        if (props.put(propName, prop) != null && failOnDuplicate) {
+            throw new CacheException("Property with name '" + propName + "' already exists for " +
                 (key ? "key" : "value") + ": " +
                 "QueryEntity [key=" + keyCls.getName() + ", value=" + valCls.getName() + ']');
         }
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/QueryEntityValidationSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/QueryEntityValidationSelfTest.java
index e72899c..4bcfd82 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/QueryEntityValidationSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/QueryEntityValidationSelfTest.java
@@ -200,4 +200,72 @@ public class QueryEntityValidationSelfTest extends AbstractIndexingCommonTest {
             }
         }, CacheException.class, "Property with name 'notUniqueId' already exists");
     }
+
+    /**
+     * Test class for sql queryable test key with unique annotation's name property.
+     */
+    private static class TestKeyWithUniqueName {
+        /** Non-unique id. */
+        @QuerySqlField(name = "Name1")
+        int notUniqueId;
+    }
+
+    /**
+     * Test class for sql queryable test value with unique annotation's name property.
+     */
+    private static class TestValueWithUniqueName {
+        /** Not unique id. */
+        @QuerySqlField(name = "Name2")
+        int notUniqueId;
+    }
+
+    /**
+     * Test to check validation of known fields names with unique QuerySqlField annotation's name properties
+     *
+     * Steps:
+     * 1) Create 2 classes with same field name, but with different name property for QuerySqlField annotation
+     * 2) Check that CacheConfiguration.setIndexedTypes() works correctly
+     */
+    @Test
+    public void testUniqueNameInAnnotation() {
+        final CacheConfiguration<TestKeyWithUniqueName, TestValueWithUniqueName> ccfg = new CacheConfiguration<TestKeyWithUniqueName, TestValueWithUniqueName>().setName(CACHE_NAME);
+
+        assertNotNull(ccfg.setIndexedTypes(TestKeyWithUniqueName.class, TestValueWithUniqueName.class));
+    }
+
+    /**
+     * Test class for sql queryable test key with not unique annotation's name property.
+     */
+    private static class TestKeyWithNotUniqueName {
+        /** Unique id. */
+        @QuerySqlField(name = "Name3")
+        int uniqueId1;
+    }
+
+    /**
+     * Test class for sql queryable test value with not unique annotation's name property.
+     */
+    private static class TestValueWithNotUniqueName {
+        /** Unique id. */
+        @QuerySqlField(name = "Name3")
+        int uniqueId2;
+    }
+
+    /**
+     * Test to check validation of known fields names with not unique QuerySqlField annotation's name properties
+     *
+     * Steps:
+     * 1) Create 2 classes with different field names and with same name property for QuerySqlField annotation
+     * 2) Check that CacheConfiguration.setIndexedTypes() fails with "Property with name ... already exists" exception
+     */
+    @Test
+    public void testNotUniqueNameInAnnotation() {
+        final CacheConfiguration<TestKeyWithNotUniqueName, TestValueWithNotUniqueName> ccfg = new CacheConfiguration<TestKeyWithNotUniqueName, TestValueWithNotUniqueName>().setName(CACHE_NAME);
+
+        GridTestUtils.assertThrows(log, (Callable<Void>)() -> {
+            ccfg.setIndexedTypes(TestKeyWithNotUniqueName.class, TestValueWithNotUniqueName.class);
+
+            return null;
+        }, CacheException.class, "Property with name 'Name3' already exists");
+    }
 }