Search in sources :

Example 1 with QueryRequest

use of org.infinispan.query.remote.client.impl.QueryRequest in project infinispan by infinispan.

the class QueryOperation method executeOperation.

@Override
protected void executeOperation(Channel channel) {
    QueryRequest queryRequest = new QueryRequest();
    queryRequest.setQueryString(remoteQuery.getQueryString());
    if (remoteQuery.getStartOffset() > 0) {
        queryRequest.setStartOffset(remoteQuery.getStartOffset());
    }
    if (remoteQuery.getMaxResults() >= 0) {
        queryRequest.setMaxResults(remoteQuery.getMaxResults());
    }
    queryRequest.setNamedParameters(getNamedParameters());
    queryRequest.setLocal(remoteQuery.isLocal());
    // marshall and write the request
    byte[] requestBytes = querySerializer.serializeQueryRequest(remoteQuery, queryRequest);
    scheduleRead(channel);
    // Here we'll rather just serialize the header + payload length than copying the requestBytes around
    ByteBuf buf = channel.alloc().buffer(codec.estimateHeaderSize(header) + ByteBufUtil.estimateVIntSize(requestBytes.length));
    codec.writeHeader(buf, header);
    ByteBufUtil.writeVInt(buf, requestBytes.length);
    channel.write(buf);
    channel.writeAndFlush(Unpooled.wrappedBuffer(requestBytes));
}
Also used : QueryRequest(org.infinispan.query.remote.client.impl.QueryRequest) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with QueryRequest

use of org.infinispan.query.remote.client.impl.QueryRequest in project infinispan by infinispan.

the class QueryFacadeImpl method query.

@Override
public byte[] query(AdvancedCache<?, ?> cache, byte[] query) {
    AuthorizationManager authorizationManager = SecurityActions.getCacheAuthorizationManager(cache);
    if (authorizationManager != null) {
        authorizationManager.checkPermission(AuthorizationPermission.BULK_READ);
    }
    RemoteQueryManager remoteQueryManager = SecurityActions.getRemoteQueryManager(cache);
    if (remoteQueryManager.getQueryEngine(cache) == null) {
        // todo [anistor] remoteQueryManager should be null if not queryable
        throw log.queryingNotEnabled(cache.getName());
    }
    try {
        MediaType requestMediaType = cache.getValueDataConversion().getRequestMediaType();
        QueryRequest request = remoteQueryManager.decodeQueryRequest(query, requestMediaType);
        int startOffset = request.getStartOffset().intValue();
        int maxResults = request.getMaxResults();
        boolean local = request.isLocal();
        return remoteQueryManager.executeQuery(request.getQueryString(), request.getNamedParametersMap(), startOffset, maxResults, cache, requestMediaType, local);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debugf(e, "Error executing remote query : %s", e.getMessage());
        }
        throw e;
    }
}
Also used : QueryRequest(org.infinispan.query.remote.client.impl.QueryRequest) MediaType(org.infinispan.commons.dataconversion.MediaType) AuthorizationManager(org.infinispan.security.AuthorizationManager)

Aggregations

QueryRequest (org.infinispan.query.remote.client.impl.QueryRequest)2 ByteBuf (io.netty.buffer.ByteBuf)1 MediaType (org.infinispan.commons.dataconversion.MediaType)1 AuthorizationManager (org.infinispan.security.AuthorizationManager)1