Search in sources :

Example 11 with DataContext

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

the class DataContextFactory method createdFromDataDomain.

protected ObjectContext createdFromDataDomain(DataDomain parent) {
    // for new dataRowStores use the same name for all stores
    // it makes it easier to track the event subject
    DataRowStore snapshotCache = (parent.isSharedCacheEnabled()) ? parent.getSharedSnapshotCache() : dataRowStoreFactory.createDataRowStore(parent.getName());
    DataContext context = newInstance(parent, objectStoreFactory.createObjectStore(snapshotCache));
    context.setValidatingObjectsOnCommit(parent.isValidatingObjectsOnCommit());
    context.setQueryCache(new NestedQueryCache(queryCache));
    context.setTransactionFactory(transactionFactory);
    return context;
}
Also used : DataContext(org.apache.cayenne.access.DataContext) NestedQueryCache(org.apache.cayenne.cache.NestedQueryCache) DataRowStore(org.apache.cayenne.access.DataRowStore)

Example 12 with DataContext

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

the class ClientLocalRuntimeTest method testGetConnection.

@Test
public void testGetConnection() {
    final DataContext serverContext = mock(DataContext.class);
    Module serverModule = binder -> binder.bind(ObjectContextFactory.class).toInstance(new ObjectContextFactory() {

        public ObjectContext createContext(DataChannel parent) {
            return null;
        }

        public ObjectContext createContext() {
            return serverContext;
        }
    });
    ClientRuntime runtime = ClientRuntime.builder().local(DIBootstrap.createInjector(serverModule)).build();
    ClientConnection connection = runtime.getConnection();
    assertNotNull(connection);
    assertTrue(connection instanceof LocalConnection);
    LocalConnection localConnection = (LocalConnection) connection;
    assertTrue(localConnection.getChannel() instanceof ClientServerChannel);
    ClientServerChannel clientServerChannel = (ClientServerChannel) localConnection.getChannel();
    assertSame(serverContext, clientServerChannel.getParentChannel());
}
Also used : ObjectContext(org.apache.cayenne.ObjectContext) DataContext(org.apache.cayenne.access.DataContext) Collection(java.util.Collection) Module(org.apache.cayenne.di.Module) Test(org.junit.Test) DataChannel(org.apache.cayenne.DataChannel) ClientServerChannel(org.apache.cayenne.access.ClientServerChannel) ClientConnection(org.apache.cayenne.remote.ClientConnection) LocalConnection(org.apache.cayenne.remote.service.LocalConnection) ObjectContextFactory(org.apache.cayenne.configuration.ObjectContextFactory) DIBootstrap(org.apache.cayenne.di.DIBootstrap) Assert(org.junit.Assert) Mockito.mock(org.mockito.Mockito.mock) DataContext(org.apache.cayenne.access.DataContext) DataChannel(org.apache.cayenne.DataChannel) LocalConnection(org.apache.cayenne.remote.service.LocalConnection) ClientConnection(org.apache.cayenne.remote.ClientConnection) ClientServerChannel(org.apache.cayenne.access.ClientServerChannel) ObjectContext(org.apache.cayenne.ObjectContext) Module(org.apache.cayenne.di.Module) ObjectContextFactory(org.apache.cayenne.configuration.ObjectContextFactory) Test(org.junit.Test)

Aggregations

DataContext (org.apache.cayenne.access.DataContext)12 Test (org.junit.Test)8 Module (org.apache.cayenne.di.Module)4 Assert (org.junit.Assert)4 Collections (java.util.Collections)3 NestedQueryCache (org.apache.cayenne.cache.NestedQueryCache)3 ObjectContextFactory (org.apache.cayenne.configuration.ObjectContextFactory)3 DIBootstrap (org.apache.cayenne.di.DIBootstrap)3 EventManager (org.apache.cayenne.event.EventManager)3 TransactionFactory (org.apache.cayenne.tx.TransactionFactory)3 Collection (java.util.Collection)2 DataChannel (org.apache.cayenne.DataChannel)2 ObjectContext (org.apache.cayenne.ObjectContext)2 ClientServerChannel (org.apache.cayenne.access.ClientServerChannel)2 DataDomain (org.apache.cayenne.access.DataDomain)2 DataRowStore (org.apache.cayenne.access.DataRowStore)2 DataRowStoreFactory (org.apache.cayenne.access.DataRowStoreFactory)2 DefaultDataRowStoreFactory (org.apache.cayenne.access.DefaultDataRowStoreFactory)2 DefaultObjectMapRetainStrategy (org.apache.cayenne.access.DefaultObjectMapRetainStrategy)2 ObjectMapRetainStrategy (org.apache.cayenne.access.ObjectMapRetainStrategy)2