Search in sources :

Example 1 with Fault

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

the class ObjectDiff method getArcSnapshotValue.

ObjectId getArcSnapshotValue(String propertyName) {
    Object value = arcSnapshot != null ? arcSnapshot.get(propertyName) : null;
    if (value instanceof Fault) {
        Persistent target = (Persistent) ((Fault) value).resolveFault(object, propertyName);
        value = target != null ? target.getObjectId() : null;
        arcSnapshot.put(propertyName, value);
    }
    return (ObjectId) value;
}
Also used : ObjectId(org.apache.cayenne.ObjectId) Fault(org.apache.cayenne.Fault) Persistent(org.apache.cayenne.Persistent)

Example 2 with Fault

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

the class FlattenedRelationshipInContextIT method testIsToOneTargetModifiedFlattenedFault1.

@Test
public void testIsToOneTargetModifiedFlattenedFault1() throws Exception {
    createFlattenedTestDataSet();
    // fetch
    List<?> ft3s = context.performQuery(new SelectQuery(FlattenedTest3.class));
    assertEquals(1, ft3s.size());
    FlattenedTest3 ft3 = (FlattenedTest3) ft3s.get(0);
    // mark as dirty for the purpose of the test...
    ft3.setPersistenceState(PersistenceState.MODIFIED);
    assertTrue(ft3.readPropertyDirectly("toFT1") instanceof Fault);
    // test that checking for modifications does not trigger a fault, and generally
    // works well
    ClassDescriptor d = context.getEntityResolver().getClassDescriptor("FlattenedTest3");
    ArcProperty flattenedRel = (ArcProperty) d.getProperty("toFT1");
    ObjectDiff diff = context.getObjectStore().registerDiff(ft3.getObjectId(), null);
    assertFalse(DataRowUtils.isToOneTargetModified(flattenedRel, ft3, diff));
    assertTrue(ft3.readPropertyDirectly("toFT1") instanceof Fault);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) ArcProperty(org.apache.cayenne.reflect.ArcProperty) ClassDescriptor(org.apache.cayenne.reflect.ClassDescriptor) Fault(org.apache.cayenne.Fault) Test(org.junit.Test)

Example 3 with Fault

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

the class ColumnSelectIT method testObjectWithDisjointByIdPrefetch.

@Test
public void testObjectWithDisjointByIdPrefetch() {
    List<Artist> result = ObjectSelect.query(Artist.class).column(Property.createSelf(Artist.class)).prefetch(Artist.PAINTING_ARRAY.disjointById()).select(context);
    assertEquals(20, result.size());
    for (Artist artist : result) {
        assertEquals(PersistenceState.COMMITTED, artist.getPersistenceState());
        Object paintingsArr = artist.readPropertyDirectly(Artist.PAINTING_ARRAY.getName());
        assertFalse(paintingsArr instanceof Fault);
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Fault(org.apache.cayenne.Fault) Test(org.junit.Test)

Example 4 with Fault

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

the class ColumnSelectIT method checkAggregatePrefetchResults.

private void checkAggregatePrefetchResults(List<Object[]> result) {
    assertEquals(5, result.size());
    for (Object[] next : result) {
        assertTrue(next[0] instanceof Artist);
        assertTrue(next[1] instanceof Long);
        Artist artist = (Artist) next[0];
        assertEquals(PersistenceState.COMMITTED, artist.getPersistenceState());
        Object paintingsArr = artist.readPropertyDirectly(Artist.PAINTING_ARRAY.getName());
        assertFalse(paintingsArr instanceof Fault);
        assertTrue(((List) paintingsArr).size() == (long) next[1]);
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Fault(org.apache.cayenne.Fault) List(java.util.List)

Example 5 with Fault

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

the class ColumnSelectIT method checkPrefetchResults.

private void checkPrefetchResults(List<Object[]> result) {
    assertEquals(21, result.size());
    for (Object[] next : result) {
        assertTrue(next[0] instanceof Artist);
        assertTrue(next[1] instanceof java.util.Date);
        assertTrue(next[2] instanceof String);
        Artist artist = (Artist) next[0];
        assertEquals(PersistenceState.COMMITTED, artist.getPersistenceState());
        Object paintingsArr = artist.readPropertyDirectly(Artist.PAINTING_ARRAY.getName());
        assertFalse(paintingsArr instanceof Fault);
        assertTrue(((List) paintingsArr).size() > 0);
    }
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Date(java.util.Date) Fault(org.apache.cayenne.Fault) List(java.util.List)

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