List createAndExecuteQuery ( CouchDBQueryInterpreter interpreter ) { EntityMetadata m = interpreter . getMetadata ( ) ; List results = new ArrayList ( ) ; try { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; StringBuilder q = new StringBuilder ( ) ; String _id = CouchDBConstants . URL_SEPARATOR + m . getSchema ( ) . toLowerCase ( ) + CouchDBConstants . URL_SEPARATOR + CouchDBConstants . DESIGN + m . getTableName ( ) + CouchDBConstants . VIEW ; if ( ( interpreter . isIdQuery ( ) && ! interpreter . isRangeQuery ( ) && interpreter . getOperator ( ) == null ) || interpreter . isQueryOnCompositeKey ( ) ) { Object object = null ; if ( metaModel . isEmbeddable ( m . getIdAttribute ( ) . getBindableJavaType ( ) ) ) { EmbeddableType embeddableType = metaModel . embeddable ( m . getIdAttribute ( ) . getBindableJavaType ( ) ) ; if ( KunderaCoreUtils . countNonSyntheticFields ( m . getIdAttribute ( ) . getBindableJavaType ( ) ) == interpreter . getKeyValues ( ) . size ( ) ) { Object key = CouchDBObjectMapper . getObjectFromJson ( gson . toJsonTree ( interpreter . getKeyValues ( ) ) . getAsJsonObject ( ) , m . getIdAttribute ( ) . getBindableJavaType ( ) , embeddableType . getAttributes ( ) ) ; object = find ( m . getEntityClazz ( ) , key ) ; if ( object != null ) { results . add ( object ) ; } return results ; } else if ( m . getIdAttribute ( ) . getName ( ) . equals ( interpreter . getKeyName ( ) ) && interpreter . getKeyValues ( ) . size ( ) == 1 ) { object = find ( m . getEntityClazz ( ) , interpreter . getKeyValue ( ) ) ; if ( object != null ) { results . add ( object ) ; } return results ; } else { log . error ( "There should be each and every field of composite key." ) ; throw new QueryHandlerException ( "There should be each and every field of composite key." ) ; } } object = find ( m . getEntityClazz ( ) , interpreter . getKeyValue ( ) ) ; if ( object != null ) { results . add ( object ) ; } return results ; } // creating query. _id = createQuery ( interpreter , m , q , _id ) ; if ( interpreter . getLimit ( ) > 0 ) { q . append ( "&limit=" + interpreter . getLimit ( ) ) ; } if ( interpreter . isDescending ( ) ) { q . append ( "&descending=" + false ) ; } // execute query. executeQueryAndGetResults ( q , _id , m , results , interpreter ) ; } catch ( Exception e ) { log . error ( "Error while executing query, Caused by {}." , e ) ; throw new KunderaException ( e ) ; } return results ; }
Creates the and execute query .