}
private QueryResponse executeQuery(AdvancedCache<byte[], byte[]> cache, final SerializationContext serCtx, QueryRequest request) {
SearchManager searchManager = Search.getSearchManager(cache);
CacheQuery cacheQuery;
LuceneQueryParsingResult parsingResult;
QueryParser queryParser = new QueryParser();
SearchFactoryIntegrator searchFactory = (SearchFactoryIntegrator) searchManager.getSearchFactory();
if (cache.getCacheConfiguration().compatibility().enabled()) {
final QueryInterceptor queryInterceptor = ComponentRegistryUtils.getQueryInterceptor(cache);
EntityNamesResolver entityNamesResolver = new EntityNamesResolver() {
@Override
public Class<?> getClassFromName(String entityName) {
MessageMarshaller messageMarshaller = (MessageMarshaller) serCtx.getMarshaller(entityName);
Class clazz = messageMarshaller.getJavaClass();
return queryInterceptor.isIndexed(clazz) ? clazz : null;
}
};
LuceneProcessingChain processingChain = new LuceneProcessingChain.Builder(searchFactory, entityNamesResolver)
.buildProcessingChainForClassBasedEntities();
parsingResult = queryParser.parseQuery(request.getJpqlString(), processingChain);
cacheQuery = searchManager.getQuery(parsingResult.getQuery(), parsingResult.getTargetEntity());
} else {
EntityNamesResolver entityNamesResolver = new EntityNamesResolver() {
@Override
public Class<?> getClassFromName(String entityName) {
return serCtx.canMarshall(entityName) ? ProtobufValueWrapper.class : null;
}
};
FieldBridgeProvider fieldBridgeProvider = new FieldBridgeProvider() {
@Override
public FieldBridge getFieldBridge(String type, String propertyPath) {
Descriptor md = serCtx.getMessageDescriptor(type);
FieldDescriptor fd = getFieldDescriptor(md, propertyPath);
switch (fd.getType()) {
case DOUBLE:
return NumericFieldBridge.DOUBLE_FIELD_BRIDGE;
case FLOAT:
return NumericFieldBridge.FLOAT_FIELD_BRIDGE;
case INT64:
case UINT64:
case FIXED64:
case SFIXED64:
case SINT64:
return NumericFieldBridge.LONG_FIELD_BRIDGE;
case INT32:
case FIXED32:
case UINT32:
case SFIXED32:
case SINT32:
case BOOL:
case ENUM:
return NumericFieldBridge.INT_FIELD_BRIDGE;
case STRING:
case BYTES:
case GROUP:
case MESSAGE:
return new NullEncodingTwoWayFieldBridge(new TwoWayString2FieldBridgeAdaptor(StringBridge.INSTANCE), NULL_TOKEN);
}
return null;
}
};
LuceneProcessingChain processingChain = new LuceneProcessingChain.Builder(searchFactory, entityNamesResolver)
.buildProcessingChainForDynamicEntities(fieldBridgeProvider);
parsingResult = queryParser.parseQuery(request.getJpqlString(), processingChain);
QueryBuilder qb = searchManager.getSearchFactory().buildQueryBuilder().forEntity(parsingResult.getTargetEntity()).get();
Query luceneQuery = qb.bool()
.must(qb.keyword().onField(TYPE_FIELD_NAME).ignoreFieldBridge().ignoreAnalyzer().matching(parsingResult.getTargetEntityName()).createQuery())
.must(parsingResult.getQuery())
.createQuery();
cacheQuery = searchManager.getQuery(luceneQuery, parsingResult.getTargetEntity());
}
if (parsingResult.getSort() != null) {
cacheQuery = cacheQuery.sort(parsingResult.getSort());
}
int projSize = 0;
if (parsingResult.getProjections() != null && !parsingResult.getProjections().isEmpty()) {
projSize = parsingResult.getProjections().size();
cacheQuery = cacheQuery.projection(parsingResult.getProjections().toArray(new String[projSize]));
}
if (request.getStartOffset() > 0) {
cacheQuery = cacheQuery.firstResult((int) request.getStartOffset());
}
if (request.getMaxResults() > 0) {