use of org.apache.cayenne.Fault in project cayenne by apache.
the class DataContextIT method testCurrentSnapshotWithToOneFault.
/**
* Testing snapshot with to-one fault. This was a bug CAY-96.
*/
@Test
public void testCurrentSnapshotWithToOneFault() throws Exception {
createGalleriesAndExhibitsDataSet();
// Exhibit with Gallery as Fault must still include Gallery
// Artist and Exhibit (Exhibit has unresolved to-one to gallery as in
// the
// CAY-96 bug report)
ObjectId eId = new ObjectId("Exhibit", Exhibit.EXHIBIT_ID_PK_COLUMN, 2);
Exhibit e = (Exhibit) context.performQuery(new ObjectIdQuery(eId)).get(0);
assertTrue(e.readPropertyDirectly(Exhibit.TO_GALLERY.getName()) instanceof Fault);
DataRow snapshot = context.currentSnapshot(e);
// assert that after taking a snapshot, we have FK in, but the
// relationship
// is still a Fault
assertTrue(e.readPropertyDirectly(Exhibit.TO_GALLERY.getName()) instanceof Fault);
assertEquals(new Integer(33002), snapshot.get("GALLERY_ID"));
}
use of org.apache.cayenne.Fault in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetchWithLocalCache.
/**
* This test and next one is the result of CAY-2349 fix
*/
@Test
public void testPrefetchWithLocalCache() throws Exception {
tArtist.deleteAll();
tGallery.deleteAll();
tPainting.deleteAll();
tArtist.insert(1, "artist1");
tGallery.insert(1, "gallery1");
tPainting.insert(1, "painting1", 1, 100, 1);
List<Painting> paintings = ObjectSelect.query(Painting.class).localCache("g1").select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Fault);
paintings = ObjectSelect.query(Painting.class).prefetch(Painting.TO_ARTIST.joint()).localCache("g1").select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<Painting> paintings = ObjectSelect.query(Painting.class).prefetch(Painting.TO_ARTIST.joint()).localCache("g1").select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
}
});
}
use of org.apache.cayenne.Fault 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.Fault in project cayenne by apache.
the class SingletonFaultFactory method getMapFault.
public Fault getMapFault(Accessor mapKeyAccessor) {
synchronized (mapFaults) {
Fault fault = mapFaults.get(mapKeyAccessor);
if (fault == null) {
fault = new ToManyMapFault(mapKeyAccessor);
mapFaults.put(mapKeyAccessor, fault);
}
return fault;
}
}
use of org.apache.cayenne.Fault in project cayenne by apache.
the class DataContextPrefetchIT method testPrefetchWithSharedCache.
@Test
public void testPrefetchWithSharedCache() throws Exception {
tArtist.deleteAll();
tGallery.deleteAll();
tPainting.deleteAll();
tArtist.insert(1, "artist1");
tGallery.insert(1, "gallery1");
tPainting.insert(1, "painting1", 1, 100, 1);
final ObjectSelect<Painting> s1 = ObjectSelect.query(Painting.class).sharedCache("g1");
final ObjectSelect<Painting> s2 = ObjectSelect.query(Painting.class).prefetch(Painting.TO_ARTIST.disjoint()).sharedCache("g1");
final ObjectSelect<Painting> s3 = ObjectSelect.query(Painting.class).prefetch(Painting.TO_GALLERY.joint()).sharedCache("g1");
final ObjectSelect<Painting> s4 = ObjectSelect.query(Painting.class).prefetch(Painting.TO_ARTIST.disjoint()).prefetch(Painting.TO_GALLERY.joint()).sharedCache("g1");
// first iteration select from DB and cache
List<Painting> paintings = s1.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Fault);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Fault);
paintings = s2.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Fault);
paintings = s3.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Fault);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Gallery);
paintings = s4.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Gallery);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
// select from cache
List<Painting> paintings = s2.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Fault);
paintings = s3.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Fault);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Gallery);
paintings = s4.select(context);
assertEquals(1, paintings.size());
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_ARTIST.getName()) instanceof Artist);
assertTrue(paintings.get(0).readPropertyDirectly(Painting.TO_GALLERY.getName()) instanceof Gallery);
}
});
}
Aggregations