String enclosingDocumentName = null;
MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
m.getPersistenceUnit());
EntityType entityType = metaModel.entity(m.getEntityClazz());
EmbeddableType superColumn = null;
Set<Attribute> columns = null;
Attribute attrib = null;
try
{
attrib = entityType.getAttribute(columnName);
Map<String, EmbeddableType> embeddables = metaModel.getEmbeddables(m.getEntityClazz());
for (String key : embeddables.keySet())
{
superColumn = embeddables.get(key);
columns = superColumn.getAttributes();
for (Attribute column : columns)
{
if (((AbstractAttribute) column).getJPAColumnName().equals(columnName))
{
enclosingDocumentName = key;
break;
}
}
}
}
catch (IllegalArgumentException iax)
{
if (log.isWarnEnabled())
{
log.warn("No column found for: " + columnName);
}
}
// Query for fetching entities based on user specified criteria
DBCursor cursor = orderBy != null ? dbCollection.find(mongoQuery, keys).sort(orderBy) : dbCollection.find(
mongoQuery, keys).limit(maxResult).skip(firstResult);;
if (superColumn != null)
{
Field superColumnField = (Field) attrib.getJavaMember();
while (cursor.hasNext())
{
DBObject fetchedDocument = cursor.next();
Object embeddedDocumentObject = fetchedDocument.get(superColumnField.getName());
if (embeddedDocumentObject != null)
{
if (embeddedDocumentObject instanceof BasicDBList)
{
Class embeddedObjectClass = PropertyAccessorHelper.getGenericClass(superColumnField);
for (Object dbObj : (BasicDBList) embeddedDocumentObject)
{
Object obj = embeddedObjectClass.newInstance();
Object embeddedObject = new DocumentObjectMapper().getObjectFromDocument(metaModel,
(BasicDBObject) dbObj, superColumn.getAttributes(), obj);
Object fieldValue = PropertyAccessorHelper.getObject(embeddedObject, columnName);
}
}
else if (embeddedDocumentObject instanceof BasicDBObject)
{
Object obj = superColumn.getJavaType().newInstance();
Object embeddedObject = DocumentObjectMapper.getObjectFromDocument(metaModel,
(BasicDBObject) embeddedDocumentObject, superColumn.getAttributes(), obj);
list.add(embeddedObject);
}
else
{
throw new PersistenceException("Can't retrieve embedded object from MONGODB document coz "