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);
f = (Field) entity.getAttribute(fieldName).getJavaMember();
}
}
if (value.getClass().isAssignableFrom(String.class) && f != null
&& !f.getType().equals(value.getClass()))
{
value = PropertyAccessorFactory.getPropertyAccessor(f).fromString(f.getType().getClass(),
value.toString());
}
value = MongoDBUtils.populateValue(value, value.getClass());
// Property, if doesn't exist in entity, may be there in a
// document embedded within it, so we have to check that
// TODO: Query should actually be in a format
// documentName.embeddedDocumentName.column, remove below if
// block once this is decided
// Query could be geospatial in nature
if (f != null && f.getType().equals(Point.class))
{
GeospatialQuery geospatialQueryimpl = GeospatialQueryFactory.getGeospatialQueryImplementor(
condition, value);
query = (BasicDBObject) geospatialQueryimpl.createGeospatialQuery(property, value, query);
}
else
{
if (isCompositeColumn)
{
property = new StringBuffer("_id.").append(property).toString();
}
if (condition.equals("="))
{
query.append(property, value);
}
else if (condition.equalsIgnoreCase("like"))
{
if (query.containsField(property))
{
query.get(property);
query.put(property, ((BasicDBObject) query.get(property)).append("$regex",
createLikeRegex((String) value)));
}
else
{
query.append(property, new BasicDBObject("$regex", createLikeRegex((String) value)));
}
}
else if (condition.equalsIgnoreCase(">"))
{
if (query.containsField(property))
{
query.get(property);
query.put(property, ((BasicDBObject) query.get(property)).append("$gt", value));
}
else
{
query.append(property, new BasicDBObject("$gt", value));
}
}
else if (condition.equalsIgnoreCase(">="))
{
if (query.containsField(property))
{
query.get(property);
query.put(property, ((BasicDBObject) query.get(property)).append("$gte", value));
}
else
{
query.append(property, new BasicDBObject("$gte", value));
}
}
else if (condition.equalsIgnoreCase("<"))
{
if (query.containsField(property))
{
query.get(property);
query.put(property, ((BasicDBObject) query.get(property)).append("$lt", value));
}
else
{
query.append(property, new BasicDBObject("$lt", value));
}
}
else if (condition.equalsIgnoreCase("<="))
{
if (query.containsField(property))
{
query.get(property);
query.put(property, ((BasicDBObject) query.get(property)).append("$lte", value));
}
else
{
query.append(property, new BasicDBObject("$lte", value));
}
}
else if (condition.equalsIgnoreCase("in"))
{
if (query.containsField(property))
{
query.get(property);
query.put(property, ((BasicDBObject) query.get(property)).append("$in", filter.getValue()));
}
else
{
query.append(property, new BasicDBObject("$in", filter.getValue()));
}
}
else if (condition.equalsIgnoreCase("not in"))
{
if (query.containsField(property))
{
query.get(property);
query.put(property, ((BasicDBObject) query.get(property)).append("$nin", filter.getValue()));
}
else
{
query.append(property, new BasicDBObject("$nin", filter.getValue()));
}
}
else if (condition.equalsIgnoreCase("<>"))
{