Search in sources :

Example 1 with EntityResolver

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

the class SelectByIdTest method testSerializabilityWithHessian.

@Test
public void testSerializabilityWithHessian() throws Exception {
    SelectById<Artist> o = SelectById.query(Artist.class, 5);
    Object clone = HessianUtil.cloneViaClientServerSerialization(o, new EntityResolver());
    assertTrue(clone instanceof SelectById);
    SelectById<?> c1 = (SelectById<?>) clone;
    assertNotSame(o, c1);
    assertEquals(o.entityType, c1.entityType);
    assertEquals(o.singleId, c1.singleId);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 2 with EntityResolver

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

the class LifecycleCallbackEventHandlerTest method testDefaultListeners.

@Test
public void testDefaultListeners() {
    LifecycleCallbackEventHandler map = new LifecycleCallbackEventHandler(new EntityResolver());
    L1 l1 = new L1();
    map.addDefaultListener(l1, "callback");
    C1 c1 = new C1();
    c1.setObjectId(new ObjectId("bogus"));
    assertEquals(0, l1.entities.size());
    map.performCallbacks(c1);
    assertEquals(1, l1.entities.size());
    assertTrue(l1.entities.contains(c1));
}
Also used : ObjectId(org.apache.cayenne.ObjectId) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 3 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 4 with EntityResolver

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

the class OsgiDataDomainProvider method get.

@Override
public DataDomain get() throws ConfigurationException {
    // here goes the class loading hack, temporarily setting application
    // bundle ClassLoader to be a thread ClassLoader for runtime to start.
    Thread thread = Thread.currentThread();
    ClassLoader activeCl = thread.getContextClassLoader();
    try {
        // using fake package name... as long as it is not
        // org.apache.cayenne, this do the right trick
        thread.setContextClassLoader(classLoaderManager.getClassLoader("com/"));
        DataDomain domain = super.get();
        EntityResolver entityResolver = domain.getEntityResolver();
        for (ObjEntity e : entityResolver.getObjEntities()) {
            // it is not enough to just call 'getObjectClass()' on
            // ClassDescriptor - there's an optimization that prevents full
            // descriptor resolving... so calling some other method...
            entityResolver.getClassDescriptor(e.getName()).getProperty("__dummy__");
            entityResolver.getCallbackRegistry();
        }
        // this triggers callbacks initialization using thread class loader
        entityResolver.getCallbackRegistry();
        return domain;
    } finally {
        thread.setContextClassLoader(activeCl);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DataDomain(org.apache.cayenne.access.DataDomain) EntityResolver(org.apache.cayenne.map.EntityResolver)

Example 5 with EntityResolver

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

the class DefaultUpgradeService method loadProject.

protected ConfigurationTree<DataChannelDescriptor> loadProject(Resource resource) {
    // Load Model back from the update XML
    ConfigurationTree<DataChannelDescriptor> configurationTree = loader.load(resource);
    // link all datamaps, or else we will lose cross-datamaps relationships
    EntityResolver resolver = new EntityResolver();
    for (DataMap dataMap : configurationTree.getRootNode().getDataMaps()) {
        resolver.addDataMap(dataMap);
        dataMap.setNamespace(resolver);
    }
    return configurationTree;
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) EntityResolver(org.apache.cayenne.map.EntityResolver) 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