Search in sources :

Example 11 with EntityResolver

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

the class ObjectDetachOperationIT method testDetachCommitted.

@Test
public void testDetachCommitted() {
    EntityResolver serverResover = serverContext.getEntityResolver();
    EntityResolver clientResolver = serverResover.getClientEntityResolver();
    ObjectDetachOperation op = new ObjectDetachOperation(clientResolver);
    ObjectId oid = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 456);
    MtTable1 so = new MtTable1();
    so.setObjectId(oid);
    so.setGlobalAttribute1("gx");
    so.setPersistenceState(PersistenceState.COMMITTED);
    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("gx", 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 12 with EntityResolver

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

the class PersistentObjectListTest method testResolvedHessianSerialization.

@Test
public void testResolvedHessianSerialization() throws Exception {
    ClientMtTable1 owner = new ClientMtTable1();
    owner.setPersistenceState(PersistenceState.COMMITTED);
    owner.setGlobalAttribute1("a");
    PersistentObjectList list = new PersistentObjectList(owner, "x");
    List<Object> objects = new ArrayList<>();
    objects.add("a");
    objects.add("b");
    list.setObjectList(objects);
    assertFalse(list.isFault());
    Object deserialized = HessianUtil.cloneViaServerClientSerialization(list, new EntityResolver());
    assertNotNull(deserialized);
    assertTrue("Invalid deserialized: " + deserialized.getClass().getName(), deserialized instanceof PersistentObjectList);
    PersistentObjectList dlist = (PersistentObjectList) deserialized;
    assertFalse(dlist.isFault());
    assertNotNull(dlist.getRelationshipOwner());
    assertEquals("x", dlist.getRelationshipName());
    assertEquals(objects, dlist.objectList);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ArrayList(java.util.ArrayList) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 13 with EntityResolver

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

the class PersistentObjectListTest method testFaultHessianSerialization.

@Test
public void testFaultHessianSerialization() throws Exception {
    ClientMtTable1 owner = new ClientMtTable1();
    owner.setPersistenceState(PersistenceState.COMMITTED);
    owner.setGlobalAttribute1("a");
    PersistentObjectList list = new PersistentObjectList(owner, "x");
    assertTrue(list.isFault());
    Object deserialized = HessianUtil.cloneViaServerClientSerialization(list, new EntityResolver());
    // faults are writtens as nulls
    assertNull(deserialized);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 14 with EntityResolver

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

the class DefaultDbImportAction method existingTargetMap.

protected DataMap existingTargetMap(DbImportConfiguration configuration) throws IOException {
    File file = configuration.getTargetDataMap();
    if (file != null && file.exists() && file.canRead()) {
        URLResource configurationResource = new URLResource(file.toURI().toURL());
        DataMap dataMap = mapLoader.load(configurationResource);
        dataMap.setNamespace(new EntityResolver(Collections.singleton(dataMap)));
        dataMap.setConfigurationSource(configurationResource);
        return dataMap;
    }
    return null;
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) EntityResolver(org.apache.cayenne.map.EntityResolver) File(java.io.File) DataMap(org.apache.cayenne.map.DataMap)

Example 15 with EntityResolver

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

the class ProjectController method setProject.

public void setProject(Project currentProject) {
    if (this.project != currentProject) {
        this.project = currentProject;
        this.projectControllerPreferences = null;
        if (project == null) {
            this.entityResolver = null;
            if (fileChangeTracker != null) {
                fileChangeTracker.interrupt();
                fileChangeTracker = null;
            }
        } else {
            if (fileChangeTracker == null) {
                fileChangeTracker = new ProjectFileChangeTracker(this);
                fileChangeTracker.setDaemon(true);
                fileChangeTracker.start();
            }
            fileChangeTracker.reconfigure();
            entityResolver = new EntityResolver(((DataChannelDescriptor) currentProject.getRootNode()).getDataMaps());
            updateEntityResolver();
        }
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) EntityResolver(org.apache.cayenne.map.EntityResolver)

Aggregations

EntityResolver (org.apache.cayenne.map.EntityResolver)78 Test (org.junit.Test)53 ObjectId (org.apache.cayenne.ObjectId)13 ObjEntity (org.apache.cayenne.map.ObjEntity)13 DataMap (org.apache.cayenne.map.DataMap)11 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)7 DataNode (org.apache.cayenne.access.DataNode)6 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)6 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)6 DbEntity (org.apache.cayenne.map.DbEntity)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 QueryResponse (org.apache.cayenne.QueryResponse)5 MockEventManager (org.apache.cayenne.event.MockEventManager)5 SelectQuery (org.apache.cayenne.query.SelectQuery)5 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)5 GenericResponse (org.apache.cayenne.util.GenericResponse)5 MappingNamespace (org.apache.cayenne.map.MappingNamespace)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 List (java.util.List)3