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);
}