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;