Hi,
You can do deletes in batches without a deleteAll method. Below is a simple example to demonstrate 2 ways of doing delete-all. I'm using version 3.9.2.
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.query.EntryObject;
import com.hazelcast.query.PredicateBuilder;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import static java.util.Arrays.asList;
public class DeleteAll {
public static void main(String[] args) {
HazelcastInstance node = Hazelcast.newHazelcastInstance();
IMap<Integer, Integer> map = node.getMap("test");
map.put(1, 1);
map.put(2, 2);
map.put(3, 3);
deleteAllWithEntryProcessor(map);
// deleteAllWithPredicate(map);
int size = map.size();
if (size != 0) {
throw new AssertionError("Expected size is zero but found :" + size);
}
System.out.println("Map size is :" + size);
}
private static void deleteAllWithEntryProcessor(IMap<Integer, Integer> map) {
map.executeOnKeys(new HashSet<Integer>(asList(1, 2, 3)), new DeleteKeys());
}
public static final class DeleteKeys extends AbstractEntryProcessor<Integer, Integer> {
@Override
public Object process(Map.Entry<Integer, Integer> entry) {
return entry.setValue(null);
}
}
private static void deleteAllWithPredicate(IMap<Integer, Integer> map) {
PredicateBuilder predicateBuilder = new PredicateBuilder();
EntryObject entryObject = predicateBuilder.getEntryObject();
List<Integer> keysToRemove = asList(1, 2, 3);
Iterator<Integer> iterator = keysToRemove.iterator();
boolean isFirstKey = true;
while (iterator.hasNext()) {
Integer key = iterator.next();
if (isFirstKey) {
isFirstKey = false;
predicateBuilder = entryObject.key().equal(key);
} else {
predicateBuilder.or(entryObject.key().equal(key));
}
}
map.removeAll(predicateBuilder);
}
}
--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+unsubscribe@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at https://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/cf7b6c01-f1fe-49dd-b0e1-9844c437ab1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Hazelcast" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hazelcast/IxCeRprNVtw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hazelcast+unsubscribe@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at https://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/CAEb73hHD8gZ47%2ByzdbHFhiEyUrQ%3DDGHa56cZ13VK-Mk6uNTTbQ%40mail.gmail.com.