Package org.apache.cayenne

Examples of org.apache.cayenne.CayenneContext


                false,
                new MockEventManager(),
                false);

        this.list = new RemoteIncrementalFaultList(
                new CayenneContext(clientChannel),
                query);
    }
View Full Code Here


                connection,
                false,
                new MockEventManager(),
                false);

        CayenneContext context = new CayenneContext(channel);
        ObjEntity entity = new ObjEntity("test_entity");
        entity.setClassName(MockPersistentObject.class.getName());

        DataMap dataMap = new DataMap("test");
        dataMap.addObjEntity(entity);
        Collection<DataMap> entities = Collections.singleton(dataMap);
        context.setEntityResolver(new EntityResolver(entities));

        QueryResponse response = channel.onQuery(context, new SelectQuery("test_entity"));
        assertNotNull(response);
        List<?> list = response.firstList();
        assertNotNull(list);
        assertEquals(1, list.size());
        Persistent o1_1 = (Persistent) list.get(0);

        assertEquals(o1.getObjectId(), o1_1.getObjectId());

        // ObjectContext must be injected
        assertEquals(context, o1_1.getObjectContext());
        assertSame(o1_1, context.getGraphManager().getNode(oid1));
    }
View Full Code Here

        DataMap dataMap = new DataMap("test");
        dataMap.addObjEntity(entity);
        Collection<DataMap> entities = Collections.singleton(dataMap);
        EntityResolver resolver = new EntityResolver(entities);

        CayenneContext context = new CayenneContext();
        context.setEntityResolver(resolver);

        ObjectId oid = new ObjectId("test_entity", "x", "y");

        MockPersistentObject o1 = new MockPersistentObject(oid);
        context.getGraphManager().registerNode(oid, o1);
        assertSame(o1, context.getGraphManager().getNode(oid));

        // another object with the same GID ... we must merge it with cached and return
        // cached object instead of the one fetched
        MockPersistentObject o2 = new MockPersistentObject(oid);

        MockClientConnection connection = new MockClientConnection(new GenericResponse(
                Arrays.asList(o2)));

        ClientChannel channel = new ClientChannel(
                connection,
                false,
                new MockEventManager(),
                false);

        context.setChannel(channel);
        QueryResponse response = channel.onQuery(context, new SelectQuery("test_entity"));
        assertNotNull(response);

        List<?> list = response.firstList();
        assertNotNull(list);
        assertEquals(1, list.size());
        assertTrue("Expected cached object, got: " + list, list.contains(o1));
        assertSame(o1, context.getGraphManager().getNode(oid));
    }
View Full Code Here

        entity.setClassName(MockPersistentObject.class.getName());
        DataMap dataMap = new DataMap("test");
        dataMap.addObjEntity(entity);
        Collection<DataMap> entities = Collections.singleton(dataMap);
        EntityResolver resolver = new EntityResolver(entities);
        CayenneContext context = new CayenneContext();
        context.setEntityResolver(resolver);

        ObjectId oid = new ObjectId("test_entity", "x", "y");

        MockPersistentObject o1 = new MockPersistentObject(oid);
        o1.setPersistenceState(PersistenceState.MODIFIED);
        context.getGraphManager().registerNode(oid, o1);
        assertSame(o1, context.getGraphManager().getNode(oid));

        // another object with the same GID ... we must merge it with cached and return
        // cached object instead of the one fetched
        MockPersistentObject o2 = new MockPersistentObject(oid);
        MockClientConnection connection = new MockClientConnection(new GenericResponse(
                Arrays.asList(o2)));

        ClientChannel channel = new ClientChannel(
                connection,
                false,
                new MockEventManager(),
                false);

        context.setChannel(channel);
        QueryResponse response = channel.onQuery(context, new SelectQuery("test_entity"));
        assertNotNull(response);
        assertEquals(1, response.size());
        List<?> list = response.firstList();
        assertNotNull(list);
        assertEquals(1, list.size());
        assertTrue("Expected cached object, got: " + list, list.contains(o1));
        assertSame(o1, context.getGraphManager().getNode(oid));
    }
View Full Code Here

        boolean lifecycleEvents = properties.getBoolean(
                ClientModule.CONTEXT_LIFECYCLE_EVENTS,
                false);

        CayenneContext context = new CayenneContext(parent, changeEvents, lifecycleEvents);
        context.setQueryCache(injector.getInstance(Key.get(
                QueryCache.class,
                BaseContext.QUERY_CACHE_INJECTION_KEY)));
        return context;
    }
View Full Code Here

        ClientChannel channel = new ClientChannel(connection, false,
        // we want events, but we don't want thread eaks, so creating single threaded EM.
                // TODO: replace with container managed ClientCase.
                new DefaultEventManager(0),
                false);
        CayenneContext context = new CayenneContext(channel, true, true);
        context.setQueryCache(new MapQueryCache(10));
        return context;
    }
View Full Code Here

        boolean lifecycleEvents = properties.getBoolean(
                ClientModule.CONTEXT_LIFECYCLE_EVENTS,
                false);

        CayenneContext context = new CayenneContext(parent, changeEvents, lifecycleEvents);
        context.setQueryCache(new NestedQueryCache(queryCache));
        return context;
    }
View Full Code Here

        serverChannel = new ClientServerChannel(getDomain());
        LocalConnection connector = new LocalConnection(
                serverChannel,
                LocalConnection.HESSIAN_SERIALIZATION);

        context = new CayenneContext(new ClientChannel(connector));
    }
View Full Code Here

        assertNotNull(context);
        assertTrue(context instanceof CayenneContext);
        assertNotSame("ObjectContext must not be a singleton", context, runtime
                .newContext());

        CayenneContext clientContext = (CayenneContext) context;
        assertNotNull(clientContext.getChannel());
        assertSame(runtime.getChannel(), clientContext.getChannel());
    }
View Full Code Here

        ClientChannel channel = new ClientChannel(connection, false,
        // we want events, but we don't want thread leaks, so creating single threaded EM.
        // TODO: replace with container managed ClientCase.
                new DefaultEventManager(0),
                false);
        CayenneContext context = new CayenneContext(channel, true, true);
        context.setQueryCache(new MapQueryCache(10));
        return context;
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.CayenneContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.