Package org.apache.cayenne.map

Examples of org.apache.cayenne.map.EntityResolver


        if (sources == null) {
            return Collections.EMPTY_MAP;
        }

        EntityResolver resolver = context.getEntityResolver();

        // simple case of one query, handle it separately for performance reasons
        if (sources.size() == 1) {

            String uuid = sources.get(0).getUuid();
            String entityName = UuidCoder.getEntityName(uuid);

            ObjEntity entity = resolver.getObjEntity(entityName);
            ObjectId id = new UuidCoder(entity).toObjectId(uuid);

            Object object = Cayenne.objectForQuery(context, new ObjectIdQuery(id));
            if (object == null) {
                return Collections.EMPTY_MAP;
            }
            else {
                return Collections.singletonMap(uuid, object);
            }
        }

        Map<String, SelectQuery> queriesByEntity = new HashMap<String, SelectQuery>();
        Map<String, UuidCoder> codersByEntity = new HashMap<String, UuidCoder>();

        for (UuidBatchSourceItem source : sources) {

            String uuid = source.getUuid();
            String entityName = UuidCoder.getEntityName(uuid);
            UuidCoder coder = codersByEntity.get(entityName);
            SelectQuery query;

            if (coder == null) {
                coder = new UuidCoder(resolver.getObjEntity(entityName));
                codersByEntity.put(entityName, coder);

                query = new SelectQuery(entityName);
                queriesByEntity.put(entityName, query);
            }
View Full Code Here


        entity.setClassName(MockPersistentObject.class.getName());

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

        // record change here to make it available to the anonymous connector method..
        diff.add(new NodeIdChangeOperation(object.getObjectId(), newObjectId));
View Full Code Here

        entity.setClassName(MockPersistentObject.class.getName());

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

        Persistent object = context.newObject(MockPersistentObject.class);
        assertNotNull(object);
        assertTrue(object instanceof MockPersistentObject);
        assertEquals(PersistenceState.NEW, object.getPersistenceState());
View Full Code Here

        entity.setClassName(MockPersistentObject.class.getName());

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

        // TRANSIENT ... should quietly ignore it
        Persistent transientObject = new MockPersistentObject();
        context.deleteObjects(transientObject);
        assertEquals(PersistenceState.TRANSIENT, transientObject.getPersistenceState());
View Full Code Here

                    public Object answer(InvocationOnMock invocation) {
                        ClientMessage arg = (ClientMessage) invocation.getArguments()[0];

                        if (arg instanceof BootstrapMessage) {
                            return new EntityResolver();
                        }
                        else {
                            return new GenericResponse(Arrays.asList(inflated));
                        }
                    }
View Full Code Here

                    public Object answer(InvocationOnMock invocation) {
                        ClientMessage arg = (ClientMessage) invocation.getArguments()[0];

                        if (arg instanceof BootstrapMessage) {
                            return new EntityResolver();
                        }
                        else {
                            return new GenericResponse(Arrays.asList(inflated));
                        }
                    }
View Full Code Here

        }

        // sort table list
        if (tables.size() > 1) {
            EntitySorter sorter = new AshwoodEntitySorter();
            sorter.setEntityResolver(new EntityResolver(Collections.singleton(map)));
            sorter.sortDbEntities(tables, false);
        }

        this.dbEntitiesInInsertOrder = tables;
        this.dbEntitiesRequiringAutoPK = tablesWithAutoPk;
View Full Code Here

    /**
     * Tests that all queries specified in prefetch are executed in a more complex
     * prefetch scenario.
     */
    public void testRouteWithPrefetches() {
        EntityResolver resolver = context.getEntityResolver();
        MockQueryRouter router = new MockQueryRouter();

        SelectQuery q = new SelectQuery(Artist.class, ExpressionFactory.matchExp(
                "artistName",
                "a"));
View Full Code Here

     * Tests that all queries specified in prefetch are executed in a more complex
     * prefetch scenario with no reverse obj relationships.
     */
    public void testRouteQueryWithPrefetchesNoReverse() {

        EntityResolver resolver = context.getEntityResolver();
        ObjEntity paintingEntity = resolver.lookupObjEntity(Painting.class);
        ObjEntity galleryEntity = resolver.lookupObjEntity(Gallery.class);
        ObjEntity artistExhibitEntity = resolver.lookupObjEntity(ArtistExhibit.class);
        ObjEntity exhibitEntity = resolver.lookupObjEntity(Exhibit.class);
        ObjRelationship paintingToArtistRel = (ObjRelationship) paintingEntity
                .getRelationship("toArtist");
        paintingEntity.removeRelationship("toArtist");

        ObjRelationship galleryToPaintingRel = (ObjRelationship) galleryEntity
View Full Code Here

        SelectQuery q = new SelectQuery(Painting.class, exp);
        q.addPrefetch("toArtist");

        // test how prefetches are resolved in this case - this was a stumbling block for
        // a while
        EntityResolver resolver = context.getEntityResolver();
        MockQueryRouter router = new MockQueryRouter();
        q.route(router, resolver, null);
        assertEquals(2, router.getQueryCount());
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.map.EntityResolver

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.