@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); } }
@Override public void registerProtoFiles(FileDescriptorSource source) throws IOException { Map<String, char[]> fileDescriptors = source.getFileDescriptors(); Map<String, String> files = new HashMap<String, String>(fileDescriptors.size()); for (String key : fileDescriptors.keySet()) { files.put(key, new String(fileDescriptors.get(key))); } protobufMetadataManager.getCache().putAll(files); }
@Override public void cacheStarted(ComponentRegistry cr, String cacheName) { InternalCacheRegistry icr = cr.getGlobalComponentRegistry().getComponent(InternalCacheRegistry.class); if (!icr.isInternalCache(cacheName)) { Configuration cfg = cr.getComponent(Configuration.class); boolean isIndexed = cfg.indexing().index().isEnabled(); boolean isCompatMode = cfg.compatibility().enabled(); if (isIndexed && !isCompatMode) { if (!verifyChainContainsRemoteValueWrapperInterceptor(cr)) { throw new IllegalStateException( "It was expected to find the RemoteValueWrapperInterceptor registered in the InterceptorChain but it wasn't found"); } } else if (verifyChainContainsRemoteValueWrapperInterceptor(cr)) { throw new IllegalStateException( "It was NOT expected to find the RemoteValueWrapperInterceptor registered in the InterceptorChain as indexing was disabled, but it was found"); } ProtobufMetadataManagerImpl protobufMetadataManager = (ProtobufMetadataManagerImpl) cr.getGlobalComponentRegistry().getComponent(ProtobufMetadataManager.class); SerializationContext serCtx = protobufMetadataManager.getSerializationContext(); cr.registerComponent(new ProtobufMatcher(serCtx), ProtobufMatcher.class); if (isCompatMode) { SearchIntegrator searchFactory = cr.getComponent(SearchIntegrator.class); CompatibilityReflectionMatcher compatibilityReflectionMatcher; if (searchFactory == null) { compatibilityReflectionMatcher = new CompatibilityReflectionMatcher(serCtx); } else { compatibilityReflectionMatcher = new CompatibilityReflectionMatcher(serCtx, searchFactory); } cr.registerComponent(compatibilityReflectionMatcher, CompatibilityReflectionMatcher.class); } AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache(); RemoteQueryEngine remoteQueryEngine = new RemoteQueryEngine(cache, isIndexed, isCompatMode, serCtx); cr.registerComponent(remoteQueryEngine, RemoteQueryEngine.class); } }
@Override public void unregisterProtoFile(String name) { protobufMetadataManager.getCache().remove(name); }
public DelegatingSerializationContext(ProtobufMetadataManagerImpl protobufMetadataManager) { this.protobufMetadataManager = protobufMetadataManager; this.delegate = protobufMetadataManager.getSerializationContext(); }