Search in sources :

Example 6 with Fault

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"));
}
Also used : ObjectId(org.apache.cayenne.ObjectId) Exhibit(org.apache.cayenne.testdo.testmap.Exhibit) Fault(org.apache.cayenne.Fault) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) DataRow(org.apache.cayenne.DataRow) Test(org.junit.Test)

Example 7 with Fault

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);
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Fault(org.apache.cayenne.Fault) List(java.util.List) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 8 with Fault

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);
    }
}
Also used : Fault(org.apache.cayenne.Fault) ValueHolder(org.apache.cayenne.ValueHolder)

Example 9 with Fault

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;
    }
}
Also used : ToManyMapFault(org.apache.cayenne.access.ToManyMapFault) ToManyListFault(org.apache.cayenne.access.ToManyListFault) ToManyMapFault(org.apache.cayenne.access.ToManyMapFault) ToOneFault(org.apache.cayenne.access.ToOneFault) Fault(org.apache.cayenne.Fault) ToManySetFault(org.apache.cayenne.access.ToManySetFault)

Example 10 with 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);
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Gallery(org.apache.cayenne.testdo.testmap.Gallery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Fault(org.apache.cayenne.Fault) List(java.util.List) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Aggregations

Fault (org.apache.cayenne.Fault)15 Test (org.junit.Test)8 Artist (org.apache.cayenne.testdo.testmap.Artist)7 List (java.util.List)4 Persistent (org.apache.cayenne.Persistent)4 ObjectId (org.apache.cayenne.ObjectId)3 DataRow (org.apache.cayenne.DataRow)2 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)2 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)2 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)2 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)2 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)2 Gallery (org.apache.cayenne.testdo.testmap.Gallery)2 Painting (org.apache.cayenne.testdo.testmap.Painting)2 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 DataObject (org.apache.cayenne.DataObject)1