Search in sources :

Example 1 with ClientServerChannel

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

the class ClientServerChannelProvider method get.

public ClientServerChannel get() throws ConfigurationException {
    LocalConnection connection = (LocalConnection) clientRuntimeProvider.get().getConnection();
    ClientServerDataChannelDecorator channelDecorator = (ClientServerDataChannelDecorator) connection.getChannel();
    return (ClientServerChannel) channelDecorator.getDelegate();
}
Also used : LocalConnection(org.apache.cayenne.remote.service.LocalConnection) ClientServerChannel(org.apache.cayenne.access.ClientServerChannel)

Example 2 with ClientServerChannel

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

the class RemoteCayenneCase method createROPContext.

protected CayenneContext createROPContext() {
    ClientServerChannel clientServerChannel = new ClientServerChannel(serverContext);
    UnitLocalConnection connection = new UnitLocalConnection(clientServerChannel, serializationPolicy);
    ClientChannel channel = new ClientChannel(connection, false, // TODO: replace with container managed ClientCase.
    new DefaultEventManager(0), false);
    CayenneContext context = new CayenneContext(channel, true, true);
    context.setQueryCache(new MapQueryCache(10));
    return context;
}
Also used : UnitLocalConnection(org.apache.cayenne.unit.UnitLocalConnection) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) MapQueryCache(org.apache.cayenne.cache.MapQueryCache) ClientServerChannel(org.apache.cayenne.access.ClientServerChannel) CayenneContext(org.apache.cayenne.CayenneContext)

Example 3 with ClientServerChannel

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

the class LocalClientServerChannelProvider method get.

public DataChannel get() throws ConfigurationException {
    ObjectContextFactory factory = serverInjector.getInstance(ObjectContextFactory.class);
    // TODO: ugly cast
    DataContext serverContext = (DataContext) factory.createContext();
    return new ClientServerChannel(serverContext);
}
Also used : DataContext(org.apache.cayenne.access.DataContext) ClientServerChannel(org.apache.cayenne.access.ClientServerChannel) ObjectContextFactory(org.apache.cayenne.configuration.ObjectContextFactory)

Example 4 with ClientServerChannel

use of org.apache.cayenne.access.ClientServerChannel 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

ClientServerChannel (org.apache.cayenne.access.ClientServerChannel)4 DataContext (org.apache.cayenne.access.DataContext)2 ObjectContextFactory (org.apache.cayenne.configuration.ObjectContextFactory)2 LocalConnection (org.apache.cayenne.remote.service.LocalConnection)2 Collection (java.util.Collection)1 CayenneContext (org.apache.cayenne.CayenneContext)1 DataChannel (org.apache.cayenne.DataChannel)1 ObjectContext (org.apache.cayenne.ObjectContext)1 MapQueryCache (org.apache.cayenne.cache.MapQueryCache)1 DIBootstrap (org.apache.cayenne.di.DIBootstrap)1 Module (org.apache.cayenne.di.Module)1 DefaultEventManager (org.apache.cayenne.event.DefaultEventManager)1 ClientConnection (org.apache.cayenne.remote.ClientConnection)1 UnitLocalConnection (org.apache.cayenne.unit.UnitLocalConnection)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1 Mockito.mock (org.mockito.Mockito.mock)1