Search in sources :

Example 1 with LocalConnection

use of org.apache.cayenne.remote.service.LocalConnection 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 LocalConnection

use of org.apache.cayenne.remote.service.LocalConnection 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)

Example 3 with LocalConnection

use of org.apache.cayenne.remote.service.LocalConnection in project cayenne by apache.

the class LocalConnectionTest method testConstructors.

@Test
public void testConstructors() {
    DataChannel handler1 = new MockDataChannel();
    LocalConnection connector1 = new LocalConnection(handler1);
    assertFalse(connector1.isSerializingMessages());
    assertSame(handler1, connector1.getChannel());
    DataChannel handler2 = new MockDataChannel();
    LocalConnection connector2 = new LocalConnection(handler2, LocalConnection.JAVA_SERIALIZATION);
    assertTrue(connector2.isSerializingMessages());
    assertSame(handler2, connector2.getChannel());
}
Also used : MockDataChannel(org.apache.cayenne.MockDataChannel) DataChannel(org.apache.cayenne.DataChannel) LocalConnection(org.apache.cayenne.remote.service.LocalConnection) MockDataChannel(org.apache.cayenne.MockDataChannel) Test(org.junit.Test)

Aggregations

LocalConnection (org.apache.cayenne.remote.service.LocalConnection)3 DataChannel (org.apache.cayenne.DataChannel)2 ClientServerChannel (org.apache.cayenne.access.ClientServerChannel)2 Test (org.junit.Test)2 Collection (java.util.Collection)1 MockDataChannel (org.apache.cayenne.MockDataChannel)1 ObjectContext (org.apache.cayenne.ObjectContext)1 DataContext (org.apache.cayenne.access.DataContext)1 ObjectContextFactory (org.apache.cayenne.configuration.ObjectContextFactory)1 DIBootstrap (org.apache.cayenne.di.DIBootstrap)1 Module (org.apache.cayenne.di.Module)1 ClientConnection (org.apache.cayenne.remote.ClientConnection)1 Assert (org.junit.Assert)1 Mockito.mock (org.mockito.Mockito.mock)1