Search in sources :

Example 1 with PersistentObjectList

use of org.apache.cayenne.util.PersistentObjectList in project cayenne by apache.

the class ProtostuffPersistentObjectCollectionsTest method testPersistentObjectList.

@Test
public void testPersistentObjectList() throws IOException {
    PersistentObjectList list = new PersistentObjectList(object1, "test");
    list.add(object2);
    byte[] bytes = serializationService.serialize(list);
    PersistentObjectList list0 = serializationService.deserialize(bytes, PersistentObjectList.class);
    assertNotNull(list0);
    assertEquals(list.getRelationshipName(), list0.getRelationshipName());
    assertEquals(list.getRelationshipOwner(), list0.getRelationshipOwner());
    Object object0 = list0.get(0);
    assertEquals(object2, object0);
}
Also used : PersistentObjectList(org.apache.cayenne.util.PersistentObjectList) PersistentObject(org.apache.cayenne.PersistentObject) Test(org.junit.Test)

Example 2 with PersistentObjectList

use of org.apache.cayenne.util.PersistentObjectList in project cayenne by apache.

the class ClientServerChannelQueryIT method testSelectQueryPrefetchToMany.

@Test
public void testSelectQueryPrefetchToMany() throws Exception {
    createTwoMtTable1sAnd2sDataSet();
    SelectQuery q = new SelectQuery(ClientMtTable1.class, ExpressionFactory.exp("globalAttribute1 = 'g1'"));
    q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
    List<?> results = context.performQuery(q);
    assertEquals(1, results.size());
    ClientMtTable1 result = (ClientMtTable1) results.get(0);
    List<?> holder = result.getTable2ArrayDirect();
    assertNotNull(holder);
    assertTrue(holder instanceof PersistentObjectList);
    PersistentObjectList objectHolder = (PersistentObjectList) holder;
    assertFalse(objectHolder.isFault());
    assertEquals(2, objectHolder.size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) PersistentObjectList(org.apache.cayenne.util.PersistentObjectList) Test(org.junit.Test)

Example 3 with PersistentObjectList

use of org.apache.cayenne.util.PersistentObjectList in project cayenne by apache.

the class ProtostuffPersistentObjectCollectionsTest method testPersistentObjectListWithWrapper.

@Test
public void testPersistentObjectListWithWrapper() throws IOException {
    PersistentObjectList list = new PersistentObjectList(object1, "test");
    list.add(object2);
    byte[] bytes = serializationService.serialize(new ListWrapper(list));
    ListWrapper lw = serializationService.deserialize(bytes, ListWrapper.class);
    assertNotNull(lw.object);
    assertTrue(lw.object instanceof PersistentObjectList);
    PersistentObjectList list0 = (PersistentObjectList) lw.object;
    assertEquals(list.getRelationshipName(), list0.getRelationshipName());
    assertEquals(list.getRelationshipOwner(), list0.getRelationshipOwner());
    Object object0 = list0.get(0);
    assertEquals(object2, object0);
}
Also used : PersistentObjectList(org.apache.cayenne.util.PersistentObjectList) PersistentObject(org.apache.cayenne.PersistentObject) Test(org.junit.Test)

Aggregations

PersistentObjectList (org.apache.cayenne.util.PersistentObjectList)3 Test (org.junit.Test)3 PersistentObject (org.apache.cayenne.PersistentObject)2 SelectQuery (org.apache.cayenne.query.SelectQuery)1 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)1