*/
public static String getLuceneQueryFromJPAQuery(final KunderaQuery kunderaQuery,
final KunderaMetadata kunderaMetadata)
{
LuceneQueryBuilder queryBuilder = new LuceneQueryBuilder();
EntityMetadata metadata = kunderaQuery.getEntityMetadata();
MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
metadata.getPersistenceUnit());
Class valueClazz = null;
EntityType entity = metaModel.entity(metadata.getEntityClazz());
for (Object object : kunderaQuery.getFilterClauseQueue())
{
if (object instanceof FilterClause)
{
FilterClause filter = (FilterClause) object;
String property = filter.getProperty();
String condition = filter.getCondition();
String valueAsString = filter.getValue().get(0).toString();
String fieldName = metadata.getFieldName(property);
boolean isEmbeddedId = metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType());
String idColumn = ((AbstractAttribute) metadata.getIdAttribute()).getJPAColumnName();
valueClazz = getValueType(entity, fieldName);
if (isEmbeddedId)
{
if (idColumn.equals(property))
{
valueAsString = prepareCompositeKey(metadata, metaModel, filter.getValue().get(0));
queryBuilder.appendIndexName(metadata.getIndexName()).appendPropertyName(idColumn)
.buildQuery(condition, valueAsString, valueClazz);
}
else
{
valueClazz = metadata.getIdAttribute().getBindableJavaType();
property = property.substring(property.indexOf(".") + 1);
queryBuilder.appendIndexName(metadata.getIndexName())
.appendPropertyName(getPropertyName(metadata, property, kunderaMetadata))
.buildQuery(condition, valueAsString, valueClazz);
}
}
else
{
queryBuilder.appendIndexName(metadata.getIndexName())
.appendPropertyName(getPropertyName(metadata, property, kunderaMetadata))
.buildQuery(condition, valueAsString, valueClazz);
}
}
else
{
queryBuilder.buildQuery(object.toString(), object.toString(), String.class);
}
}
queryBuilder.appendEntityName(kunderaQuery.getEntityClass().getCanonicalName().toLowerCase());
return queryBuilder.getQuery();
}