CouchDBQueryInterpreter interpreter = new CouchDBQueryInterpreter(getColumns(getKunderaQuery().getResult(), m),
getMaxResults(), m);
MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
m.getPersistenceUnit());
EntityType entity = metaModel.entity(m.getEntityClazz());
// If there is no clause present, means we might need to scan complete
// table.
/**
* TODOOOO: Create a sorted set with table name. and add row key as
* score and value on persist. delete it out as well on delete call.
*/
for (Object clause : clauseQueue)
{
if (clause.getClass().isAssignableFrom(FilterClause.class))
{
Object value = ((FilterClause) clause).getValue().get(0);
String condition = ((FilterClause) clause).getCondition();
String columnName = ((FilterClause) clause).getProperty();
int indexOfDot = columnName.indexOf(".");
if (indexOfDot >= 0)
{
EmbeddableType embeddableType = metaModel.embeddable(m.getIdAttribute().getBindableJavaType());
String embeddedeFieldName = columnName.substring(0, indexOfDot);
if (embeddedeFieldName.equals(((AbstractAttribute) m.getIdAttribute()).getName()))
{
interpreter.setQueryOnCompositeKey(true);
interpreter.setKeyName(embeddedeFieldName);
String colName = columnName.substring(indexOfDot + 1);
Attribute attribute = embeddableType.getAttribute(colName);
interpreter.setIdQuery(true);
interpreter.setKeyValues(
colName,
PropertyAccessorHelper.fromSourceToTargetClass(attribute.getJavaType(),
value.getClass(), value));
}
else
{
log.error("Query on embedded column/any field of embedded column, is not supported in CouchDB");
throw new QueryHandlerException(
"Query on embedded column/any field of embedded column, is not supported in CouchDB");
}
}
else
{
Attribute col = entity.getAttribute(m.getFieldName(columnName));
interpreter.setKeyValues(columnName,
PropertyAccessorHelper.fromSourceToTargetClass(col.getJavaType(), value.getClass(), value));
interpreter.setKeyName(columnName);
if (columnName.equals(((AbstractAttribute) m.getIdAttribute()).getJPAColumnName()))
{