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 ( ) ) ; boolean partitionKeyCheck = true ; 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 . getIdAttribute ( ) , metaModel , filter . getValue ( ) . get ( 0 ) ) ; queryBuilder . appendIndexName ( metadata . getIndexName ( ) ) . appendPropertyName ( idColumn ) . buildQuery ( condition , valueAsString , valueClazz ) ; } else { valueClazz = metadata . getIdAttribute ( ) . getBindableJavaType ( ) ; if ( property . lastIndexOf ( ' ' ) != property . indexOf ( ' ' ) && partitionKeyCheck ) { isCompletePartitionKeyPresentInQuery ( kunderaQuery . getFilterClauseQueue ( ) , metaModel , metadata ) ; partitionKeyCheck = false ; } if ( metaModel . isEmbeddable ( filter . getValue ( ) . get ( 0 ) . getClass ( ) ) ) { prepareLuceneQueryForPartitionKey ( queryBuilder , filter . getValue ( ) . get ( 0 ) , metaModel , metadata . getIndexName ( ) , valueClazz ) ; } else { property = property . substring ( property . lastIndexOf ( "." ) + 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 ( ) ; }
Gets the lucene query from jpa query .