Search in sources :

Example 61 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class GenericResponseTest method testSerializationWithHessian.

@Test
public void testSerializationWithHessian() throws Exception {
    List<Object> list = new ArrayList<>();
    list.add(new HashMap());
    GenericResponse r = new GenericResponse();
    r.addBatchUpdateCount(new int[] { 1, 2, 3 });
    r.addResultList(list);
    GenericResponse sr = (GenericResponse) HessianUtil.cloneViaClientServerSerialization(r, new EntityResolver());
    assertNotNull(sr);
    assertEquals(2, sr.size());
    assertTrue(sr.next());
    assertFalse(sr.isList());
    int[] srInt = sr.currentUpdateCount();
    assertEquals(3, srInt.length);
    assertEquals(2, srInt[1]);
    assertTrue(sr.next());
    assertTrue(sr.isList());
    assertEquals(list, sr.currentList());
    assertFalse(sr.next());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 62 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class ObjectDetachOperationIT method testDetachHollow.

@Test
public void testDetachHollow() throws Exception {
    tMtTable1.insert(4, "g1", "s1");
    EntityResolver serverResover = serverContext.getEntityResolver();
    EntityResolver clientResolver = serverResover.getClientEntityResolver();
    ObjectDetachOperation op = new ObjectDetachOperation(clientResolver);
    ObjectId oid = ObjectId.of("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 4);
    MtTable1 so = new MtTable1();
    so.setObjectId(oid);
    so.setPersistenceState(PersistenceState.HOLLOW);
    so.setObjectContext(serverContext);
    serverContext.getGraphManager().registerNode(oid, so);
    Object detached = op.detach(so, serverResover.getClassDescriptor("MtTable1"), null);
    assertNotNull(detached);
    assertNotSame(so, detached);
    assertTrue(detached instanceof ClientMtTable1);
    ClientMtTable1 co = (ClientMtTable1) detached;
    assertEquals(oid, co.getObjectId());
    assertEquals("g1", co.getGlobalAttribute1());
    assertEquals(PersistenceState.TRANSIENT, co.getPersistenceState());
    assertNull(co.getObjectContext());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) MtTable1(org.apache.cayenne.testdo.mt.MtTable1) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ObjectId(org.apache.cayenne.ObjectId) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 63 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class NodeDiffTest method testHessianSerialization.

@Test
public void testHessianSerialization() throws Exception {
    // id must be a serializable object...
    String id = "abcd";
    NodeDiff diff = new ConcreteNodeDiff(id);
    Object d = HessianUtil.cloneViaClientServerSerialization(diff, new EntityResolver());
    assertNotNull(d);
    assertNotNull(((NodeDiff) d).getNodeId());
    assertEquals(id, ((NodeDiff) d).getNodeId());
}
Also used : EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 64 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class ObjectIdQueryTest method testSerializabilityWithHessian.

@Test
public void testSerializabilityWithHessian() throws Exception {
    ObjectId oid = ObjectId.of("test", "a", "b");
    ObjectIdQuery query = new ObjectIdQuery(oid);
    Object o = HessianUtil.cloneViaClientServerSerialization(query, new EntityResolver());
    assertNotNull(o);
    assertTrue(o instanceof ObjectIdQuery);
    assertEquals(oid, ((ObjectIdQuery) o).getObjectId());
}
Also used : ObjectId(org.apache.cayenne.ObjectId) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 65 with EntityResolver

use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.

the class SQLTemplateTest method testSerializabilityWithHessian.

@Test
public void testSerializabilityWithHessian() throws Exception {
    SQLTemplate o = new SQLTemplate("Test", "DO SQL");
    Object clone = HessianUtil.cloneViaClientServerSerialization(o, new EntityResolver());
    assertTrue(clone instanceof SQLTemplate);
    SQLTemplate c1 = (SQLTemplate) clone;
    assertNotSame(o, c1);
    assertEquals(o.getRoot(), c1.getRoot());
    assertEquals(o.getDefaultTemplate(), c1.getDefaultTemplate());
    // set immutable parameters ... query must recast them to mutable
    // version
    o.setParams(Collections.<String, Object>emptyMap());
    HessianUtil.cloneViaClientServerSerialization(o, new EntityResolver());
}
Also used : EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Aggregations

EntityResolver (org.apache.cayenne.map.EntityResolver)87 Test (org.junit.Test)57 ObjEntity (org.apache.cayenne.map.ObjEntity)17 ObjectId (org.apache.cayenne.ObjectId)14 DataMap (org.apache.cayenne.map.DataMap)14 DbEntity (org.apache.cayenne.map.DbEntity)10 ArrayList (java.util.ArrayList)7 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)7 HashMap (java.util.HashMap)6 QueryResponse (org.apache.cayenne.QueryResponse)6 DataNode (org.apache.cayenne.access.DataNode)6 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)6 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)6 MockEventManager (org.apache.cayenne.event.MockEventManager)5 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)5 GenericResponse (org.apache.cayenne.util.GenericResponse)5 List (java.util.List)4 MappingNamespace (org.apache.cayenne.map.MappingNamespace)4 Artist (org.apache.cayenne.testdo.testmap.Artist)4 Map (java.util.Map)3