Search in sources :

Example 16 with ValueHolder

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

Example 17 with ValueHolder

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

Example 18 with ValueHolder

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

Example 19 with ValueHolder

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());
            }
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Artist(org.apache.cayenne.testdo.testmap.Artist) Set(java.util.Set) HashSet(java.util.HashSet) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Example 20 with ValueHolder

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

Aggregations

ValueHolder (org.apache.cayenne.ValueHolder)35 Test (org.junit.Test)32 List (java.util.List)28 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)23 SelectQuery (org.apache.cayenne.query.SelectQuery)21 Artist (org.apache.cayenne.testdo.testmap.Artist)18 Painting (org.apache.cayenne.testdo.testmap.Painting)12 ArrayList (java.util.ArrayList)10 ArtistExhibit (org.apache.cayenne.testdo.testmap.ArtistExhibit)7 Gallery (org.apache.cayenne.testdo.testmap.Gallery)7 HashSet (java.util.HashSet)4 Iterator (java.util.Iterator)4 Set (java.util.Set)4 Expression (org.apache.cayenne.exp.Expression)4 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)4 ArtGroup (org.apache.cayenne.testdo.testmap.ArtGroup)4 Exhibit (org.apache.cayenne.testdo.testmap.Exhibit)3 Bag (org.apache.cayenne.testdo.things.Bag)3 Ball (org.apache.cayenne.testdo.things.Ball)3 Box (org.apache.cayenne.testdo.things.Box)3