Search in sources :

Example 66 with EntityResolver

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

the class SyncMessageTest method testHessianSerialization.

@Test
public void testHessianSerialization() throws Exception {
    // id must be a serializable object; source doesn't have to be
    ObjectContext source = mock(ObjectContext.class);
    GraphDiff diff = new NodeCreateOperation("id-string");
    SyncMessage message = new SyncMessage(source, DataChannel.FLUSH_NOCASCADE_SYNC, diff);
    Object d = HessianUtil.cloneViaClientServerSerialization(message, new EntityResolver());
    assertNotNull(d);
    assertTrue(d instanceof SyncMessage);
    SyncMessage ds = (SyncMessage) d;
    assertNull(ds.getSource());
    assertEquals(message.getType(), ds.getType());
    assertNotNull(ds.getSenderChanges());
}
Also used : NodeCreateOperation(org.apache.cayenne.graph.NodeCreateOperation) GraphDiff(org.apache.cayenne.graph.GraphDiff) ObjectContext(org.apache.cayenne.ObjectContext) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 67 with EntityResolver

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

the class BatchActionGeneratedIT method testHasGeneratedKeys1.

@Test
public void testHasGeneratedKeys1() throws Exception {
    EntityResolver resolver = runtime.getChannel().getEntityResolver();
    // test with adapter that supports keys
    JdbcAdapter adapter = buildAdapter(true);
    InsertBatchQuery batch1 = new InsertBatchQuery(resolver.getObjEntity(GeneratedColumnTestEntity.class).getDbEntity(), 5);
    DataNode node = new DataNode();
    node.setAdapter(adapter);
    node.setEntityResolver(resolver);
    node.setRowReaderFactory(mock(RowReaderFactory.class));
    assertTrue(new BatchAction(batch1, node, false).hasGeneratedKeys());
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) DataNode(org.apache.cayenne.access.DataNode) RowReaderFactory(org.apache.cayenne.access.jdbc.reader.RowReaderFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 68 with EntityResolver

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

the class BatchActionIT method testHasGeneratedKeys1.

@Test
public void testHasGeneratedKeys1() throws Exception {
    EntityResolver resolver = runtime.getChannel().getEntityResolver();
    // test with adapter that supports keys
    JdbcAdapter adapter = buildAdapter(true);
    DataNode node = new DataNode();
    node.setAdapter(adapter);
    node.setEntityResolver(resolver);
    node.setRowReaderFactory(mock(RowReaderFactory.class));
    InsertBatchQuery batch2 = new InsertBatchQuery(resolver.getObjEntity(Artist.class).getDbEntity(), 5);
    assertFalse(new BatchAction(batch2, node, false).hasGeneratedKeys());
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) DataNode(org.apache.cayenne.access.DataNode) RowReaderFactory(org.apache.cayenne.access.jdbc.reader.RowReaderFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 69 with EntityResolver

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

the class BatchActionIT method testHasGeneratedKeys2.

@Test
public void testHasGeneratedKeys2() throws Exception {
    EntityResolver resolver = runtime.getChannel().getEntityResolver();
    // test with adapter that does not support keys...
    JdbcAdapter adapter = buildAdapter(false);
    DataNode node = new DataNode();
    node.setAdapter(adapter);
    node.setEntityResolver(resolver);
    node.setRowReaderFactory(mock(RowReaderFactory.class));
    InsertBatchQuery batch2 = new InsertBatchQuery(resolver.getObjEntity(Artist.class).getDbEntity(), 5);
    assertFalse(new BatchAction(batch2, node, false).hasGeneratedKeys());
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) DataNode(org.apache.cayenne.access.DataNode) RowReaderFactory(org.apache.cayenne.access.jdbc.reader.RowReaderFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 70 with EntityResolver

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

the class CayenneGeneratorMapLoaderAction method getMainDataMap.

DataMap getMainDataMap() throws MalformedURLException {
    if (mainDataMap == null) {
        DataMapLoader loader = createLoader();
        DataMap mainDataMap = loadDataMap(loader, mainDataMapFile);
        if (additionalDataMapFiles != null) {
            EntityResolver entityResolver = new EntityResolver();
            entityResolver.addDataMap(mainDataMap);
            mainDataMap.setNamespace(entityResolver);
            for (File additionalDataMapFile : additionalDataMapFiles) {
                DataMap dataMap = loadDataMap(loader, additionalDataMapFile);
                entityResolver.addDataMap(dataMap);
                dataMap.setNamespace(entityResolver);
            }
        }
        this.mainDataMap = mainDataMap;
    }
    return mainDataMap;
}
Also used : DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) EntityResolver(org.apache.cayenne.map.EntityResolver) File(java.io.File) DataMap(org.apache.cayenne.map.DataMap)

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