use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class BaseToManyProperty method writePropertyDirectly.
/**
* Wraps list in a value holder that performs lazy faulting.
*/
@Override
public void writePropertyDirectly(Object object, Object oldValue, Object newValue) throws PropertyException {
if (newValue instanceof Fault) {
super.writePropertyDirectly(object, null, newValue);
} else {
// must resolve value holder...
ValueHolder holder = (ValueHolder) readProperty(object);
holder.setValueDirectly(newValue);
}
}
use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class ValueHolderProperty method writePropertyDirectly.
@Override
public void writePropertyDirectly(Object object, Object oldValue, Object newValue) throws PropertyException {
ValueHolder holder = (ValueHolder) accessor.getValue(object);
if (holder == null) {
holder = createValueHolder(object);
accessor.setValue(object, holder);
}
holder.setValueDirectly(newValue);
}
use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class ValueHolderProperty method ensureValueHolderSet.
/**
* Checks that an object's ValueHolder field described by this property is set,
* injecting a ValueHolder if needed.
*/
protected ValueHolder ensureValueHolderSet(Object object) throws PropertyException {
ValueHolder holder = (ValueHolder) accessor.getValue(object);
if (holder == null) {
holder = createValueHolder(object);
accessor.setValue(object, holder);
}
return holder;
}
use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class FlattenedPrefetchIT method testManyToMany.
@Test
public void testManyToMany() throws Exception {
createPrefetchDataSet1();
SelectQuery q = new SelectQuery(Artist.class);
q.addPrefetch(Artist.GROUP_ARRAY.disjoint());
final List<Artist> objects = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(3, objects.size());
for (Artist a : objects) {
List<ArtGroup> list = a.getGroupArray();
assertNotNull(list);
assertFalse("artist's groups not resolved: " + a, ((ValueHolder) list).isFault());
assertTrue(list.size() > 0);
for (ArtGroup g : list) {
assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
}
// assert no duplicates
Set<ArtGroup> s = new HashSet<ArtGroup>(list);
assertEquals(s.size(), list.size());
}
}
});
}
use of org.apache.cayenne.ValueHolder in project cayenne by apache.
the class FlattenedPrefetchIT method testMultiPrefetch.
@Test
public void testMultiPrefetch() throws Exception {
createPrefetchDataSet2();
SelectQuery q = new SelectQuery(Painting.class);
q.addPrefetch(Painting.TO_ARTIST.disjoint());
q.addPrefetch(Painting.TO_ARTIST.dot(Artist.GROUP_ARRAY).disjoint());
final List<Painting> objects = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(3, objects.size());
for (Painting p : objects) {
Artist a = p.getToArtist();
assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
List<ArtGroup> list = a.getGroupArray();
assertNotNull(list);
assertFalse("artist's groups not resolved: " + a, ((ValueHolder) list).isFault());
assertTrue(list.size() > 0);
for (ArtGroup g : list) {
assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
}
// assert no duplicates
Set<ArtGroup> s = new HashSet<ArtGroup>(list);
assertEquals(s.size(), list.size());
}
}
});
}
Aggregations