Search in sources :

Example 1 with FaultFailureException

use of org.apache.cayenne.FaultFailureException in project cayenne by apache.

the class DataContextLocalObjectIT method testLocalObject_FFE_InvalidID.

@Test
public void testLocalObject_FFE_InvalidID() throws Exception {
    tArtist.insert(777, "AA");
    final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 777);
    Artist a3 = context2.localObject(a1);
    assertEquals(PersistenceState.HOLLOW, a3.getPersistenceState());
    context1.invalidateObjects(a1);
    tArtist.deleteAll();
    assertEquals(PersistenceState.HOLLOW, a3.getPersistenceState());
    try {
        a3.getArtistName();
        fail("FaultFailureException wasn't thrown on attempt to " + "resolve HOLLOW object with no backing DB row");
    } catch (FaultFailureException e) {
    // expected
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) FaultFailureException(org.apache.cayenne.FaultFailureException) Test(org.junit.Test)

Example 2 with FaultFailureException

use of org.apache.cayenne.FaultFailureException in project cayenne by apache.

the class DataContextLocalObjectIT method testLocalObject_TempId.

@Test
public void testLocalObject_TempId() throws Exception {
    final Artist a1 = context1.newObject(Artist.class);
    interceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            Artist a = context2.localObject(a1);
            assertNotNull(a);
            assertEquals(a1.getObjectId(), a.getObjectId());
            // FFE mist be thrown on attempt to read non-existing temp ID
            try {
                a.getArtistName();
                fail("FaultFailureException wasn't thrown on attempt to " + "resolve HOLLOW object with temp id");
            } catch (FaultFailureException e) {
            // expected
            }
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) FaultFailureException(org.apache.cayenne.FaultFailureException) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 3 with FaultFailureException

use of org.apache.cayenne.FaultFailureException in project cayenne by apache.

the class PersistentObjectHolder method resolve.

/**
 * Reads an object from the database.
 */
protected synchronized void resolve() {
    if (!fault) {
        return;
    }
    // TODO: should build a HOLLOW object instead of running a query if relationship
    // is required and thus expected to be not null.
    List<E> objects = resolveFromDB();
    if (objects.size() == 0) {
        this.value = null;
    } else if (objects.size() == 1) {
        this.value = objects.get(0);
    } else {
        throw new FaultFailureException("Expected either no objects or a single object, instead fault query resolved to " + objects.size() + " objects.");
    }
    fault = false;
}
Also used : FaultFailureException(org.apache.cayenne.FaultFailureException)

Aggregations

FaultFailureException (org.apache.cayenne.FaultFailureException)3 Artist (org.apache.cayenne.testdo.testmap.Artist)2 Test (org.junit.Test)2 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)1