Package org.apache.cayenne.lifecycle.uuid

Examples of org.apache.cayenne.lifecycle.uuid.UuidCoder


     * {@link ObjectContext}.
     */
    public Object getReferenceable(ObjectContext context, String uuid) {

        String entityName = UuidCoder.getEntityName(uuid);
        UuidCoder coder = getCoder(entityName);
        ObjectId oid = coder.toObjectId(uuid);
        return Cayenne.objectForPK(context, oid);
    }
View Full Code Here


        if (referenceable instanceof Persistent) {

            ObjectId id = ((Persistent) referenceable).getObjectId();

            UuidCoder coder = getCoder(id.getEntityName());
            return coder.toUuid(id);
        }
        else {
            throw new IllegalArgumentException("Object is not a DataObject: "
                    + referenceable.getClass().getName());
        }
View Full Code Here

                    + referenceable.getClass().getName());
        }
    }

    protected UuidCoder getCoder(String entityName) {
        UuidCoder coder = coders.get(entityName);
        if (coder == null) {

            // TODO: check @Referenceable annotation?
            ObjEntity entity = entityResolver.getObjEntity(entityName);
            if (entity == null) {
                throw new IllegalArgumentException("Entity '"
                        + entityName
                        + "' is not a known referenceable");
            }

            coder = new UuidCoder(entity);
            coders.put(entity.getName(), coder);
        }

        return coder;
View Full Code Here

            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);
            }
            else {
                query = queriesByEntity.get(entityName);
            }

            ObjectId id = coder.toObjectId(uuid);
            Expression idExp = ExpressionFactory.matchAllDbExp(
                    id.getIdSnapshot(),
                    Expression.EQUAL_TO);
            query.orQualifier(idExp);
        }

        int capacity = (int) Math.ceil(sources.size() / 0.75d);
        Map<String, Object> results = new HashMap<String, Object>(capacity);

        for (SelectQuery query : queriesByEntity.values()) {

            UuidCoder coder = codersByEntity.get(query.getRoot());
            List<DataObject> objects = context.performQuery(query);
            for (DataObject object : objects) {
                String uuid = coder.toUuid(object.getObjectId());
                results.put(uuid, object);
            }
        }

        return results;
View Full Code Here

        when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
        when(entity.getDbEntity()).thenReturn(dbEntity);

        ObjectId id = new ObjectId("x", "ID", 3);

        UuidCoder coder = new UuidCoder(entity);
        assertEquals("x:3", coder.toUuid(id));

        ObjectId parsedId = coder.toObjectId("x:3");
        assertEquals(id, parsedId);
    }
View Full Code Here

        when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
        when(entity.getDbEntity()).thenReturn(dbEntity);

        ObjectId id = new ObjectId("x", "ID", 3l);

        UuidCoder coder = new UuidCoder(entity);
        assertEquals("x:3", coder.toUuid(id));

        ObjectId parsedId = coder.toObjectId("x:3");
        assertEquals(id, parsedId);
    }
View Full Code Here

        ObjEntity entity = mock(ObjEntity.class);
        when(entity.getName()).thenReturn("x");
        when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
        when(entity.getDbEntity()).thenReturn(dbEntity);

        UuidCoder coder = new UuidCoder(entity);

        ObjectId id = new ObjectId("x", "ID", "AbC");
        assertEquals("x:AbC", coder.toUuid(id));

        ObjectId parsedId = coder.toObjectId("x:AbC");
        assertEquals(id, parsedId);
    }
View Full Code Here

        ObjEntity entity = mock(ObjEntity.class);
        when(entity.getName()).thenReturn("x");
        when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
        when(entity.getDbEntity()).thenReturn(dbEntity);

        UuidCoder coder = new UuidCoder(entity);

        ObjectId id = new ObjectId("x", "ID", "Ab:C");
        assertEquals("x:Ab%3AC", coder.toUuid(id));

        ObjectId parsedId = coder.toObjectId("x:Ab%3AC");
        assertEquals(id, parsedId);
    }
View Full Code Here

        ObjEntity entity = mock(ObjEntity.class);
        when(entity.getName()).thenReturn("x");
        when(entity.getDbEntityName()).thenReturn(dbEntity.getName());
        when(entity.getDbEntity()).thenReturn(dbEntity);

        UuidCoder coder = new UuidCoder(entity);

        Map<String, Object> idMap = new HashMap<String, Object>();
        idMap.put("ID", "X;Y");
        idMap.put("ABC", 6783463l);
        idMap.put("ZZZ", "'_'");
        ObjectId id = new ObjectId("x", idMap);
        assertEquals("x:6783463:X%3BY:%27_%27", coder.toUuid(id));

        ObjectId parsedId = coder.toObjectId("x:6783463:X%3BY:%27_%27");
        assertEquals(id, parsedId);
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.lifecycle.uuid.UuidCoder

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.