Package org.apache.cayenne

Examples of org.apache.cayenne.CayenneContext


        "http://localhost:8080/cayenne-service", "cayenne-user",
        "secret", null);

    DataChannel channel = new ClientChannel(connection);

    ObjectContext context = new CayenneContext(channel);

    // cleans up all data, so that we start with empty database on each
    // tutorial run
    mappingQueriesChapter(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);
        return new CayenneContext(channel, true, true);
    }
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

        EntityResolver resolver = getDomain()
                .getEntityResolver()
                .getClientEntityResolver();

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

        ClientMtTable1 t1 = context.newObject(ClientMtTable1.class);
        ClientMtTable2 t2 = context.newObject(ClientMtTable2.class);

        t1.addToTable2Array(t2);
        assertEquals(1, t1.getTable2Array().size());
        assertSame(t1, t2.getTable1());
       
        // do it again to make sure action can handle series of changes
        ClientMtTable1 t3 = context.newObject(ClientMtTable1.class);
        ClientMtTable2 t4 = context.newObject(ClientMtTable2.class);

        t3.addToTable2Array(t4);
        assertEquals(1, t3.getTable2Array().size());
        assertSame(t3, t4.getTable1());
    }
View Full Code Here

        EntityResolver resolver = getDomain()
                .getEntityResolver()
                .getClientEntityResolver();

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

        ClientMtTable1 t1 = context.newObject(ClientMtTable1.class);
        ClientMtTable2 t2 = context.newObject(ClientMtTable2.class);

        t2.setTable1(t1);
        assertEquals(1, t1.getTable2Array().size());
        assertSame(t1, t2.getTable1());
    }
View Full Code Here

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

        return new CayenneContext(parent, changeEvents, lifecycleEvents);
    }
View Full Code Here

            // server side as well as the client
            ClientServerChannel clientServerChannel = new ClientServerChannel(
                    (DataContext) getContext());
            LocalConnection connection = new LocalConnection(clientServerChannel);
            ClientChannel channel = new ClientChannel(connection);
            clientContext = new CayenneContext(channel);
        }

        return clientContext;
    }
View Full Code Here

                serverDiff.apply(diffReader);
                return serverDiff;
            }
        };

        CayenneContext context = new CayenneContext(channel);
        context.newObject(ClientMtTable1.class);
        context.commitChanges();

        assertTrue(ids[0] instanceof ObjectId);
        assertTrue(((ObjectId) ids[0]).isTemporary());

        assertTrue(ids[1] instanceof ObjectId);
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.