/** * Internal and experimental! Creates a {@link CacheQuery}, filtered according to the given {@link HSQuery}. * * @param hSearchQuery {@link HSQuery} * @return the CacheQuery object which can be used to iterate through results */ public <E> CacheQuery<E> getQuery(HSQuery hSearchQuery) { if (timeoutExceptionFactory != null) { hSearchQuery.timeoutExceptionFactory(timeoutExceptionFactory); } Class<?>[] classes = hSearchQuery.getTargetedEntities().toPojosSet().toArray(new Class[hSearchQuery.getTargetedEntities().size()]); queryInterceptor.enableClasses(classes); return new CacheQueryImpl<>(hSearchQuery, cache, queryInterceptor.getKeyTransformationHandler()); }
private String toString(HSQuery query) { StringBuilder builder = new StringBuilder(); if ( StringHelper.isNotEmpty( description ) ) { builder.append( description ).append( " - " ); } builder.append( "<" ).append( query.getQueryString() ).append( ">" ) .append( " from <" ).append( query.getTargetedEntities() ).append( ">" ); String[] projected = query.getProjectedFields(); if ( projected != null && projected.length > 0 ) { builder.append( " with projections <" ).append( query.getProjectedFields() ).append( ">" ); } return builder.toString(); } }
/** * Internal and experimental! Creates a {@link CacheQuery}, filtered according to the given {@link HSQuery}. * * @param hSearchQuery {@link HSQuery} * @return the CacheQuery object which can be used to iterate through results */ public <E> CacheQuery<E> getQuery(HSQuery hSearchQuery, IndexedQueryMode queryMode) { if (timeoutExceptionFactory != null) { hSearchQuery.timeoutExceptionFactory(timeoutExceptionFactory); } Class<?>[] classes = hSearchQuery.getTargetedEntities().toPojosSet().toArray(new Class[hSearchQuery.getTargetedEntities().size()]); queryInterceptor.enableClasses(classes); if (queryMode == IndexedQueryMode.BROADCAST) { ExecutorService asyncExecutor = queryInterceptor.getAsyncExecutor(); return new ClusteredCacheQueryImpl<>(new QueryDefinition(hSearchQuery), asyncExecutor, cache, keyTransformationHandler, null); } else { return new CacheQueryImpl<>(hSearchQuery, cache, keyTransformationHandler); } }
/** * Decide which object loader to use depending on the targeted entities. If there is only a single entity targeted * a <code>QueryLoader</code> can be used which will only execute a single query to load the entities. If more than * one entity is targeted a <code>MultiClassesQueryLoader</code> must be used. We also have to consider whether * projections or <code>Criteria</code> are used. * * @return The loader instance to use to load the results of the query. */ private Loader getLoader() { ObjectLoaderBuilder loaderBuilder = new ObjectLoaderBuilder() .criteria( criteria ) .targetedEntities( hSearchQuery.getTargetedEntities() ) .indexedTargetedEntities( hSearchQuery.getIndexedTargetedEntities().toPojosSet() ) .session( session ) .searchFactory( hSearchQuery.getExtendedSearchIntegrator() ) .timeoutManager( hSearchQuery.getTimeoutManager() ) .lookupMethod( objectLookupMethod ) .retrievalMethod( databaseRetrievalMethod ); if ( hSearchQuery.getProjectedFields() != null ) { return getProjectionLoader( loaderBuilder ); } else { return loaderBuilder.buildLoader(); } }