You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by as...@apache.org on 2022/01/18 14:00:25 UTC

[ignite-extensions] branch master updated: IGNITE-16124 change signature in method deleteAllById in spring data 2.2 (#94)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 84bda12  IGNITE-16124 change signature in method deleteAllById in spring data 2.2 (#94)
84bda12 is described below

commit 84bda12f11da9215883ee6da9c937222d8cab8ba
Author: Andrey Belyaev <48...@users.noreply.github.com>
AuthorDate: Tue Jan 18 16:58:11 2022 +0300

    IGNITE-16124 change signature in method deleteAllById in spring data 2.2 (#94)
    
    * IGNITE-16124 change signature in method deleteAllById in spring data 2.2
---
 .../springdata22/repository/IgniteRepository.java  |  2 +-
 .../repository/support/IgniteRepositoryImpl.java   |  2 +-
 .../IgniteSpringDataCompoundExtendedKeyTest.java   | 80 ++++++++++++++++++++++
 .../IgniteSpringDataCompoundKeyTest.java           | 38 +++++++++-
 .../ignite/springdata/compoundkey/CityKeyExt.java  | 63 +++++++++++++++++
 .../testsuites/IgniteSpringData22TestSuite.java    |  2 +
 6 files changed, 182 insertions(+), 5 deletions(-)

diff --git a/modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/IgniteRepository.java b/modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/IgniteRepository.java
index a8c8c6f..9a4e793 100644
--- a/modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/IgniteRepository.java
+++ b/modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/IgniteRepository.java
@@ -104,6 +104,6 @@ public interface IgniteRepository<V, K extends Serializable> extends CrudReposit
      *
      * @param ids List of ids to delete.
      */
-    public void deleteAllById(Iterable<K> ids);
+    public void deleteAllById(Iterable<? extends K> ids);
 
 }
diff --git a/modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryImpl.java b/modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryImpl.java
index 5bc5c3a..67a5b98 100644
--- a/modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryImpl.java
+++ b/modules/spring-data-2.2-ext/src/main/java/org/apache/ignite/springdata22/repository/support/IgniteRepositoryImpl.java
@@ -210,7 +210,7 @@ public class IgniteRepositoryImpl<V, K extends Serializable> implements IgniteRe
     }
 
     /** {@inheritDoc} */
-    @Override public void deleteAllById(Iterable<K> ids) {
+    @Override public void deleteAllById(Iterable<? extends K> ids) {
         if (ids instanceof Set) {
             cache.removeAll((Set<K>)ids);
             return;
diff --git a/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCompoundExtendedKeyTest.java b/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCompoundExtendedKeyTest.java
new file mode 100644
index 0000000..f9c2878
--- /dev/null
+++ b/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCompoundExtendedKeyTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.springdata;
+
+import org.apache.ignite.springdata.compoundkey.City;
+import org.apache.ignite.springdata.compoundkey.CityKeyExt;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * Test with using ext compound key in spring-data.
+ */
+public class IgniteSpringDataCompoundExtendedKeyTest extends IgniteSpringDataCompoundKeyTest {
+
+    /**
+     * Cities count.
+     */
+    private static final int TOTAL_COUNT = 6;
+
+    /**
+     * Test city Harare.
+     */
+    private static final City HARARE = new City("Harare", "Harare", 3120917);
+
+    /**
+     * Load data.
+     */
+    public void loadData() {
+        repo.save(new CityKeyExt(1, "AFG", 11), new City("Kabul", "Kabol", 1780000));
+        repo.save(new CityKeyExt(2, "AFG", 12), new City("Qandahar", "Qandahar", 237500));
+        repo.save(new CityKeyExt(3, "AFG", 13), new City("Herat", "Herat", 186800));
+        repo.save(new CityKeyExt(4, "AFG", 14), new City("Mazar-e-Sharif", "Balkh", 127800));
+        repo.save(new CityKeyExt(5, "NLD", 25), new City("Amsterdam", "Noord-Holland", 731200));
+        repo.save(new CityKeyExt(6, "ZW", 36), new City("Harare", "Harare", 3120917));
+    }
+
+    /** Test. */
+    @Test
+    public void test() {
+        assertEquals(Optional.of(KABUL), repo.findById(new CityKeyExt(1, "AFG", 11)));
+        assertEquals(Optional.of(HARARE), repo.findById(new CityKeyExt(6, "ZW", 36)));
+    }
+
+    /** Test. */
+    @Test
+    public void deleteAllById() {
+        Set<CityKeyExt> keys = new HashSet<>();
+        keys.add(new CityKeyExt(1, "AFG", 11));
+        keys.add(new CityKeyExt(2, "AFG", 12));
+        keys.add(new CityKeyExt(3, "AFG", 13));
+        keys.add(new CityKeyExt(4, "AFG", 14));
+        keys.add(new CityKeyExt(5, "NLD", 25));
+        keys.add(new CityKeyExt(6, "ZW", 36));
+
+        repo.deleteAllById(keys);
+        assertEquals(0, repo.count());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int getTotalCount() {
+        return TOTAL_COUNT;
+    }
+}
diff --git a/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCompoundKeyTest.java b/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCompoundKeyTest.java
index 3a65f29..d3ccf5e 100644
--- a/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCompoundKeyTest.java
+++ b/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/springdata/IgniteSpringDataCompoundKeyTest.java
@@ -19,7 +19,9 @@ package org.apache.ignite.springdata;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.Statement;
+import java.util.HashSet;
 import java.util.Optional;
+import java.util.Set;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.springdata.compoundkey.City;
 import org.apache.ignite.springdata.compoundkey.CityKey;
@@ -60,7 +62,7 @@ public class IgniteSpringDataCompoundKeyTest extends GridCommonAbstractTest {
     private static final String AFG = "AFG";
 
     /** test city Kabul */
-    private static final City KABUL = new City("Kabul", "Kabol", 1780000);
+    protected static final City KABUL = new City("Kabul", "Kabol", 1780000);
 
     /** test city Quandahar */
     private static final City QUANDAHAR = new City("Qandahar","Qandahar", 237500);
@@ -86,7 +88,18 @@ public class IgniteSpringDataCompoundKeyTest extends GridCommonAbstractTest {
 
         loadData();
 
-        assertEquals(TOTAL_COUNT, repo.count());
+        assertEquals(getTotalCount(), repo.count());
+    }
+
+    /**
+     * Clear data
+     * */
+    @Override protected void afterTest() throws Exception {
+        repo.deleteAll();
+
+        assertEquals(0, repo.count());
+
+        super.afterTest();
     }
 
     /**
@@ -96,7 +109,7 @@ public class IgniteSpringDataCompoundKeyTest extends GridCommonAbstractTest {
         ctx.close();
     }
 
-    /** load data*/
+    /** Load data. */
     public void loadData() throws Exception {
         Ignite ignite = ignite();
 
@@ -125,8 +138,27 @@ public class IgniteSpringDataCompoundKeyTest extends GridCommonAbstractTest {
         assertEquals(QUANDAHAR, repo.findById(QUANDAHAR_ID));
     }
 
+    /** Test. */
+    @Test
+    public void deleteAllById() {
+        Set<CityKey> keys = new HashSet<>();
+        keys.add(new CityKey(1, "AFG"));
+        keys.add(new CityKey(2, "AFG"));
+        keys.add(new CityKey(3, "AFG"));
+        keys.add(new CityKey(4, "AFG"));
+        keys.add(new CityKey(5, "NLD"));
+
+        repo.deleteAllById(keys);
+        assertEquals(0, repo.count());
+    }
+
     /** */
     protected Ignite ignite() {
         return ctx.getBean(Ignite.class);
     }
+
+    /** Total count of entries after load data. */
+    protected int getTotalCount() {
+        return TOTAL_COUNT;
+    }
 }
diff --git a/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/springdata/compoundkey/CityKeyExt.java b/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/springdata/compoundkey/CityKeyExt.java
new file mode 100644
index 0000000..1e716ae
--- /dev/null
+++ b/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/springdata/compoundkey/CityKeyExt.java
@@ -0,0 +1,63 @@
+/*
+ * 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.springdata.compoundkey;
+
+import java.util.Objects;
+
+/** Extended city compound key. */
+public class CityKeyExt extends CityKey {
+
+    /** City extended identifier. */
+    private long idExt;
+
+    /**
+     * @param id city identifier
+     * @param countryCode city countrycode
+     * @param idExt city extended identifier
+     * */
+    public CityKeyExt(int id, String countryCode, long idExt) {
+        super(id, countryCode);
+        this.idExt = idExt;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        if (!super.equals(o))
+            return false;
+
+        CityKeyExt that = (CityKeyExt) o;
+
+        return idExt == that.idExt;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return Objects.hash(super.hashCode(), idExt);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return idExt + "|" + super.toString();
+    }
+}
diff --git a/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/testsuites/IgniteSpringData22TestSuite.java b/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/testsuites/IgniteSpringData22TestSuite.java
index 899118b..86f97b2 100644
--- a/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/testsuites/IgniteSpringData22TestSuite.java
+++ b/modules/spring-data-2.2-ext/src/test/java/org/apache/ignite/testsuites/IgniteSpringData22TestSuite.java
@@ -20,6 +20,7 @@ package org.apache.ignite.testsuites;
 import org.apache.ignite.springdata.IgniteClientSpringDataCompoundKeyTest;
 import org.apache.ignite.springdata.IgniteClientSpringDataCrudSelfTest;
 import org.apache.ignite.springdata.IgniteClientSpringDataQueriesSelfTest;
+import org.apache.ignite.springdata.IgniteSpringDataCompoundExtendedKeyTest;
 import org.apache.ignite.springdata.IgniteSpringDataCompoundKeyTest;
 import org.apache.ignite.springdata.IgniteSpringDataConnectionConfigurationTest;
 import org.apache.ignite.springdata.IgniteSpringDataCrudSelfExpressionTest;
@@ -37,6 +38,7 @@ import org.junit.runners.Suite;
     IgniteSpringDataQueriesSelfTest.class,
     IgniteSpringDataCrudSelfExpressionTest.class,
     IgniteSpringDataCompoundKeyTest.class,
+    IgniteSpringDataCompoundExtendedKeyTest.class,
     IgniteSpringDataConnectionConfigurationTest.class,
     IgniteClientSpringDataCrudSelfTest.class,
     IgniteClientSpringDataQueriesSelfTest.class,