Search in sources :

Example 1 with DataDomain

use of org.apache.cayenne.access.DataDomain 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 2 with DataDomain

use of org.apache.cayenne.access.DataDomain in project cayenne by apache.

the class ROPHessianServlet_ConfigModule method configure.

public void configure(Binder binder) {
    DataDomain domain = new DataDomain("x");
    binder.bind(DataChannel.class).toInstance(domain);
    binder.bind(DataDomain.class).toInstance(domain);
    binder.bind(RemoteService.class).to(MockRemoteService.class);
}
Also used : DataChannel(org.apache.cayenne.DataChannel) DataDomain(org.apache.cayenne.access.DataDomain) MockRemoteService(org.apache.cayenne.remote.MockRemoteService) RemoteService(org.apache.cayenne.remote.RemoteService)

Example 3 with DataDomain

use of org.apache.cayenne.access.DataDomain in project cayenne by apache.

the class SchemaBuilder method rebuildSchema.

/**
 * Completely rebuilds test schema.
 */
// TODO - this method changes the internal state of the object ... refactor
public void rebuildSchema() {
    // generate schema combining all DataMaps that require schema support.
    // Schema generation is done like that instead of per DataMap on demand
    // to avoid conflicts when dropping and generating PK objects.
    DataMap[] maps = new DataMap[MAPS_REQUIRING_SCHEMA_SETUP.length];
    for (int i = 0; i < maps.length; i++) {
        URL mapURL = getClass().getClassLoader().getResource(MAPS_REQUIRING_SCHEMA_SETUP[i]);
        maps[i] = loader.load(new URLResource(mapURL));
    }
    this.domain = new DataDomain("temp");
    domain.setEventManager(new DefaultEventManager(2));
    domain.setEntitySorter(new AshwoodEntitySorter());
    domain.setQueryCache(new MapQueryCache(50));
    try {
        for (DataMap map : maps) {
            initNode(map);
        }
        if ("true".equalsIgnoreCase(System.getProperty(SKIP_SCHEMA_KEY))) {
            logger.info("skipping schema generation... ");
        } else {
            dropSchema();
            dropPKSupport();
            createSchema();
            createPKSupport();
        }
    } catch (Exception e) {
        throw new RuntimeException("Error rebuilding schema", e);
    }
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataDomain(org.apache.cayenne.access.DataDomain) AshwoodEntitySorter(org.apache.cayenne.ashwood.AshwoodEntitySorter) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) MapQueryCache(org.apache.cayenne.cache.MapQueryCache) URL(java.net.URL) SQLException(java.sql.SQLException) DataMap(org.apache.cayenne.map.DataMap)

Example 4 with DataDomain

use of org.apache.cayenne.access.DataDomain in project cayenne by apache.

the class ServerCaseDataDomainProvider method createAndInitDataDomain.

@Override
protected DataDomain createAndInitDataDomain() throws Exception {
    DataDomain domain = super.createAndInitDataDomain();
    DataNode node = null;
    for (DataMap dataMap : domain.getDataMaps()) {
        // add nodes and DataSources dynamically...
        DataNodeDescriptor descriptor = new DataNodeDescriptor(dataMap.getName());
        node = dataNodeFactory.createDataNode(descriptor);
        node.addDataMap(dataMap);
        // tweak procedures for testing...
        for (Procedure proc : dataMap.getProcedures()) {
            unitDbAdapter.tweakProcedure(proc);
        }
        // customizations from SimpleAccessStackAdapter that are not yet
        // ported...
        // those can be done better now
        // node
        // .getAdapter()
        // .getExtendedTypes()
        // .registerType(new StringET1ExtendedType());
        // 
        domain.addNode(node);
    }
    if (domain.getDataMaps().size() == 1) {
        domain.setDefaultNode(node);
    }
    return domain;
}
Also used : DataDomain(org.apache.cayenne.access.DataDomain) DataNode(org.apache.cayenne.access.DataNode) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Procedure(org.apache.cayenne.map.Procedure) DataMap(org.apache.cayenne.map.DataMap)

Example 5 with DataDomain

use of org.apache.cayenne.access.DataDomain in project cayenne by apache.

the class CAY_743Test method testLoad2MapsWithCrossMapInheritance.

@Test
public void testLoad2MapsWithCrossMapInheritance() throws Exception {
    Injector injector = DIBootstrap.createInjector(new ServerModule() {

        @Override
        public void configure(Binder binder) {
            super.configure(binder);
            ServerModule.contributeProjectLocations(binder).add("cay743/cayenne-domain.xml");
        }
    });
    try {
        DataDomain domain = injector.getInstance(DataDomain.class);
        assertEquals(2, domain.getDataMaps().size());
        DataMap m1 = domain.getDataMap("map1");
        DataMap m2 = domain.getDataMap("map2");
        ObjEntity oe11 = m1.getObjEntity("Entity11");
        ObjEntity oe12 = m1.getObjEntity("Entity12");
        ObjEntity oe21 = m2.getObjEntity("Entity21");
        ObjEntity oe22 = m2.getObjEntity("Entity22");
        // this causes StackOverflow per CAY-743
        ObjEntity oe21Super = oe21.getSuperEntity();
        ObjEntity oe12Super = oe12.getSuperEntity();
        assertSame(oe12Super, oe22);
        assertSame(oe21Super, oe11);
    } finally {
        injector.shutdown();
    }
}
Also used : Binder(org.apache.cayenne.di.Binder) ObjEntity(org.apache.cayenne.map.ObjEntity) DataDomain(org.apache.cayenne.access.DataDomain) Injector(org.apache.cayenne.di.Injector) ServerModule(org.apache.cayenne.configuration.server.ServerModule) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Aggregations

DataDomain (org.apache.cayenne.access.DataDomain)14 DataNode (org.apache.cayenne.access.DataNode)6 DataMap (org.apache.cayenne.map.DataMap)6 DataRowStoreFactory (org.apache.cayenne.access.DataRowStoreFactory)5 EventManager (org.apache.cayenne.event.EventManager)5 Test (org.junit.Test)5 DefaultDataRowStoreFactory (org.apache.cayenne.access.DefaultDataRowStoreFactory)4 QueryCache (org.apache.cayenne.cache.QueryCache)4 DefaultRuntimeProperties (org.apache.cayenne.configuration.DefaultRuntimeProperties)4 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)4 Injector (org.apache.cayenne.di.Injector)4 EventBridge (org.apache.cayenne.event.EventBridge)4 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)4 Slf4jJdbcEventLogger (org.apache.cayenne.log.Slf4jJdbcEventLogger)4 Collections (java.util.Collections)3 DataChannel (org.apache.cayenne.DataChannel)3 DefaultObjectMapRetainStrategy (org.apache.cayenne.access.DefaultObjectMapRetainStrategy)3 ObjectMapRetainStrategy (org.apache.cayenne.access.ObjectMapRetainStrategy)3 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)3