public BasicDBObject createSubMongoQuery(EntityMetadata m, Queue filterClauseQueue)
{
BasicDBObject query = new BasicDBObject();
BasicDBObject compositeColumns = new BasicDBObject();
MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
m.getPersistenceUnit());
for (Object object : filterClauseQueue)
{
boolean isCompositeColumn = false;
boolean isSubCondition = false;
if (object instanceof FilterClause)
{
FilterClause filter = (FilterClause) object;
String property = filter.getProperty();
String condition = filter.getCondition();
Object value = filter.getValue().get(0);
// value is string but field.getType is different, then get
// value using
Field f = null;
// if alias is still present .. means it is an enclosing
// document search.
if (((AbstractAttribute) m.getIdAttribute()).getJPAColumnName().equalsIgnoreCase(property))
{
property = "_id";
f = (Field) m.getIdAttribute().getJavaMember();
if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType())
&& value.getClass().isAssignableFrom(f.getType()))
{
EmbeddableType compoundKey = metaModel.embeddable(m.getIdAttribute().getBindableJavaType());
compositeColumns = MongoDBUtils.getCompoundKeyColumns(m, value, compoundKey);
isCompositeColumn = true;
continue;
}
}
else if (metaModel.isEmbeddable(m.getIdAttribute().getBindableJavaType())
&& StringUtils.contains(property, '.'))
{
// Means it is a case of composite column.
property = property.substring(property.indexOf(".") + 1);
isCompositeColumn = true;
} /*
* if a composite key. "." assuming "." is part of property in
* case of embeddable only
*/
else if (StringUtils.contains(property, '.'))
{
EntityType entity = metaModel.entity(m.getEntityClazz());
StringTokenizer tokenizer = new StringTokenizer(property, ".");
String embeddedAttributeAsStr = tokenizer.nextToken();
String embeddableAttributeAsStr = tokenizer.nextToken();
Attribute embeddedAttribute = entity.getAttribute(embeddedAttributeAsStr);
EmbeddableType embeddableEntity = metaModel.embeddable(((AbstractAttribute) embeddedAttribute)
.getBindableJavaType());
f = (Field) embeddableEntity.getAttribute(embeddableAttributeAsStr).getJavaMember();
property = ((AbstractAttribute) embeddedAttribute).getJPAColumnName()
+ "."
+ ((AbstractAttribute) embeddableEntity.getAttribute(embeddableAttributeAsStr))
.getJPAColumnName();
}
else
{
EntityType entity = metaModel.entity(m.getEntityClazz());
String discriminatorColumn = ((AbstractManagedType) entity).getDiscriminatorColumn();
if (!property.equals(discriminatorColumn))
{
String fieldName = m.getFieldName(property);