more efficient support for mutating operations of managed relationship set
This commit is contained in:
@@ -24,11 +24,11 @@ import org.springframework.data.graph.neo4j.support.DoReturn;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* TODO handle all mutating methods
|
||||
* @param <T>
|
||||
*/
|
||||
public class ManagedFieldAccessorSet<ENTITY,T> extends AbstractSet<T> {
|
||||
@@ -99,4 +99,37 @@ public class ManagedFieldAccessorSet<ENTITY,T> extends AbstractSet<T> {
|
||||
if (res) update();
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
if (delegate.removeAll(c)) {
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
if (delegate.remove(o)) {
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
if (delegate.retainAll(c)) {
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
delegate.clear();
|
||||
update();
|
||||
}
|
||||
}
|
||||
@@ -181,6 +181,37 @@ public class NodeEntityRelationshipTest {
|
||||
group.getPersons().remove(david);
|
||||
assertEquals(Collections.singleton(michael), group.getPersons());
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
public void testRemoveAllFromOneToManyRelationship() {
|
||||
Person michael = persistedPerson("Michael", 35);
|
||||
Person david = persistedPerson("David", 25);
|
||||
Group group = new Group().persist();
|
||||
group.setPersons(new HashSet<Person>(Arrays.asList(michael, david)));
|
||||
group.getPersons().removeAll(Collections.singleton(david));
|
||||
assertEquals(Collections.singleton(michael), group.getPersons());
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
public void testRetainAllFromOneToManyRelationship() {
|
||||
Person michael = persistedPerson("Michael", 35);
|
||||
Person david = persistedPerson("David", 25);
|
||||
Group group = new Group().persist();
|
||||
group.setPersons(new HashSet<Person>(Arrays.asList(michael, david)));
|
||||
group.getPersons().retainAll(Collections.singleton(david));
|
||||
assertEquals(Collections.singleton(david), group.getPersons());
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
public void testClearFromOneToManyRelationship() {
|
||||
Person michael = persistedPerson("Michael", 35);
|
||||
Person david = persistedPerson("David", 25);
|
||||
Group group = new Group().persist();
|
||||
group.setPersons(new HashSet<Person>(Arrays.asList(michael, david)));
|
||||
group.getPersons().clear();
|
||||
assertEquals(Collections.<Person>emptySet(), group.getPersons());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
|
||||
Reference in New Issue
Block a user