Exemplo n.º 1
0
  @Override
  public byte[] query(AdvancedCache<byte[], byte[]> cache, byte[] query) {
    try {
      SerializationContext serCtx =
          ProtobufMetadataManagerImpl.getSerializationContextInternal(cache.getCacheManager());
      QueryRequest request =
          ProtobufUtil.fromByteArray(serCtx, query, 0, query.length, QueryRequest.class);

      Configuration cacheConfiguration = SecurityActions.getCacheConfiguration(cache);
      boolean isIndexed = cacheConfiguration.indexing().index().isEnabled();
      boolean isCompatMode = cacheConfiguration.compatibility().enabled();
      SearchManager searchManager =
          isIndexed ? Search.getSearchManager(cache) : null; // this also checks access permissions
      RemoteQueryEngine queryEngine =
          new RemoteQueryEngine(cache, searchManager, isCompatMode, serCtx);

      long startOffset = request.getStartOffset() == null ? -1 : request.getStartOffset();
      int maxResults = request.getMaxResults() == null ? -1 : request.getMaxResults();
      Map<String, Object> namedParameters = getNamedParameters(request);
      Query q =
          queryEngine.buildQuery(
              null, request.getJpqlString(), namedParameters, startOffset, maxResults);

      QueryResponse response = makeResponse(q);
      return ProtobufUtil.toByteArray(serCtx, response);
    } catch (IOException e) {
      throw log.errorExecutingQuery(e);
    }
  }
Exemplo n.º 2
0
  @Override
  public byte[] query(AdvancedCache<byte[], byte[]> cache, byte[] query) {
    try {
      SerializationContext serCtx =
          ProtobufMetadataManager.getSerializationContextInternal(cache.getCacheManager());
      QueryRequest request =
          ProtobufUtil.fromByteArray(serCtx, query, 0, query.length, QueryRequest.class);

      QueryResponse response;
      if (cache.getCacheConfiguration().indexing().index().isEnabled()) {
        response = executeQuery(cache, serCtx, request);
      } else {
        response = executeNonIndexedQuery(cache, serCtx, request);
      }

      return ProtobufUtil.toByteArray(serCtx, response);
    } catch (IOException e) {
      throw new CacheException("An exception has occurred during query execution", e);
    }
  }