Skip to content
Permalink
Browse files
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
  • Loading branch information
andreybell91 committed Jan 18, 2022
1 parent f664082 commit 84bda12f11da9215883ee6da9c937222d8cab8ba
Showing 6 changed files with 182 additions and 5 deletions.
@@ -104,6 +104,6 @@
*
* @param ids List of ids to delete.
*/
public void deleteAllById(Iterable<K> ids);
public void deleteAllById(Iterable<? extends K> ids);

}
@@ -210,7 +210,7 @@ public IgniteRepositoryImpl(IgniteProxy ignite, IgniteCacheProxy<K, V> cache) {
}

/** {@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;
@@ -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;
}
}
@@ -19,7 +19,9 @@
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 void test() {
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;
}
}
@@ -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();
}
}
@@ -20,6 +20,7 @@
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 @@
IgniteSpringDataQueriesSelfTest.class,
IgniteSpringDataCrudSelfExpressionTest.class,
IgniteSpringDataCompoundKeyTest.class,
IgniteSpringDataCompoundExtendedKeyTest.class,
IgniteSpringDataConnectionConfigurationTest.class,
IgniteClientSpringDataCrudSelfTest.class,
IgniteClientSpringDataQueriesSelfTest.class,

0 comments on commit 84bda12

Please sign in to comment.