Repository: ignite
Updated Branches:
  refs/heads/ignite-5027 [created] b9883ce0c


Fixed.


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

Branch: refs/heads/ignite-5027
Commit: b9883ce0c3818db0f95d1a0b1cf37342f14734c3
Parents: 2ded758
Author: devozerov <[email protected]>
Authored: Wed Apr 19 13:50:54 2017 +0300
Committer: devozerov <[email protected]>
Committed: Wed Apr 19 13:50:54 2017 +0300

----------------------------------------------------------------------
 .../configuration/CacheConfiguration.java       | 17 ++--
 .../index/DuplicateKeyValueClassesSelfTest.java | 94 ++++++++++++++++++++
 .../IgniteCacheQuerySelfTestSuite.java          |  4 +
 3 files changed, 109 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b9883ce0/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
 
b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index a2f7cc8..d378343 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -2145,7 +2145,7 @@ public class CacheConfiguration<K, V> extends 
MutableConfiguration<K, V> {
                     // properties override will happen properly (first parent, 
then children).
                     type.addProperty(prop, key, true);
 
-                    processAnnotation(key, sqlAnn, txtAnn, field.getType(), 
prop, type);
+                    processAnnotation(key, sqlAnn, txtAnn, cls, c, 
field.getType(), prop, type);
                 }
             }
 
@@ -2171,7 +2171,7 @@ public class CacheConfiguration<K, V> extends 
MutableConfiguration<K, V> {
                     // properties override will happen properly (first parent, 
then children).
                     type.addProperty(prop, key, true);
 
-                    processAnnotation(key, sqlAnn, txtAnn, 
mtd.getReturnType(), prop, type);
+                    processAnnotation(key, sqlAnn, txtAnn, cls, c, 
mtd.getReturnType(), prop, type);
                 }
             }
         }
@@ -2183,20 +2183,25 @@ public class CacheConfiguration<K, V> extends 
MutableConfiguration<K, V> {
      * @param key If given class relates to key.
      * @param sqlAnn SQL annotation, can be {@code null}.
      * @param txtAnn H2 text annotation, can be {@code null}.
-     * @param cls Class of field or return type for method.
+     * @param cls Entity class.
+     * @param curCls Current entity class.
+     * @param fldCls Class of field or return type for method.
      * @param prop Current property.
      * @param desc Class description.
      */
     private static void processAnnotation(boolean key, QuerySqlField sqlAnn, 
QueryTextField txtAnn,
-        Class<?> cls, ClassProperty prop, TypeDescriptor desc) {
+        Class<?> cls, Class<?> curCls, Class<?> fldCls, ClassProperty prop, 
TypeDescriptor desc) {
         if (sqlAnn != null) {
-            processAnnotationsInClass(key, cls, desc, prop);
+            processAnnotationsInClass(key, fldCls, desc, prop);
 
             if (!sqlAnn.name().isEmpty())
                 prop.alias(sqlAnn.name());
 
             if (sqlAnn.index()) {
-                String idxName = prop.alias() + "_idx";
+                String idxName = curCls.getSimpleName() + "_" + prop.alias() + 
"_idx";
+
+                if (cls != curCls)
+                    idxName = cls.getSimpleName() + "_" + idxName;
 
                 desc.addIndex(idxName, QueryUtils.isGeometryClass(prop.type()) 
?
                     QueryIndexType.GEOSPATIAL : QueryIndexType.SORTED);

http://git-wip-us.apache.org/repos/asf/ignite/blob/b9883ce0/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DuplicateKeyValueClassesSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DuplicateKeyValueClassesSelfTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DuplicateKeyValueClassesSelfTest.java
new file mode 100644
index 0000000..4ee884f
--- /dev/null
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/index/DuplicateKeyValueClassesSelfTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+
+package org.apache.ignite.internal.processors.cache.index;
+
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.UUID;
+
+/**
+ * Make sure that cache can start with multiple key-value classes of the same 
type.
+ */
+@SuppressWarnings("unchecked")
+public class DuplicateKeyValueClassesSelfTest extends GridCommonAbstractTest {
+    /** Cache name. */
+    private static final String CACHE_NAME = "cache";
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        startGrid(0);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        grid(0).destroyCache(CACHE_NAME);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * Test duplicate key class.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDuplicateKeyClass() throws Exception {
+        CacheConfiguration ccfg = new CacheConfiguration()
+            .setName(CACHE_NAME)
+            .setIndexedTypes(UUID.class, Clazz1.class, UUID.class, 
Clazz2.class);
+
+        grid(0).createCache(ccfg);
+    }
+
+    /**
+     * Test duplicate value class.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDuplicateValueClass() throws Exception {
+        CacheConfiguration ccfg = new CacheConfiguration()
+            .setName(CACHE_NAME)
+            .setIndexedTypes(UUID.class, Clazz1.class, String.class, 
Clazz1.class);
+
+        grid(0).createCache(ccfg);
+    }
+
+    /**
+     * Class 1.
+     */
+    private static class Clazz1 {
+        /** ID. */
+        @QuerySqlField(index = true)
+        int id;
+    }
+
+    /**
+     * Class 2.
+     */
+    private static class Clazz2 {
+        /** ID. */
+        @QuerySqlField(index = true)
+        int id;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/b9883ce0/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
 
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
index b61affe..405e1f6 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheQuerySelfTestSuite.java
@@ -81,6 +81,7 @@ import 
org.apache.ignite.internal.processors.cache.distributed.replicated.Ignite
 import 
org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedFieldsQuerySelfTest;
 import 
org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQueryP2PDisabledSelfTest;
 import 
org.apache.ignite.internal.processors.cache.distributed.replicated.IgniteCacheReplicatedQuerySelfTest;
+import 
org.apache.ignite.internal.processors.cache.index.DuplicateKeyValueClassesSelfTest;
 import 
org.apache.ignite.internal.processors.cache.index.H2DynamicIndexAtomicPartitionedNearSelfTest;
 import 
org.apache.ignite.internal.processors.cache.index.H2DynamicIndexAtomicPartitionedSelfTest;
 import 
org.apache.ignite.internal.processors.cache.index.H2DynamicIndexAtomicReplicatedSelfTest;
@@ -128,6 +129,9 @@ public class IgniteCacheQuerySelfTestSuite extends 
TestSuite {
     public static TestSuite suite() throws Exception {
         IgniteTestSuite suite = new IgniteTestSuite("Ignite Cache Queries Test 
Suite");
 
+        // Misc tests.
+        suite.addTest(new TestSuite(DuplicateKeyValueClassesSelfTest.class));
+
         // Dynamic index create/drop tests.
         suite.addTest(new TestSuite(SchemaExchangeSelfTest.class));
 

Reply via email to