Chapter 6. Remote Querying
JBoss Data Grid uses its own query language based on an internal DSL. The Infinispan Query DSL provides a simplified way of writing queries, and is agnostic of the underlying query mechanisms. Querying via the Hot Rod client allows remote, language-neutral querying, and is implementable in all languages currently available for the Hot Rod client.
Google's Protocol Buffers is used as an encoding format for both storing and querying data. The Infinispan Query DSL can be used remotely via the Hot Rod client that is configured to use the Protobuf marshaller. Protocol Buffers are used to adopt a common format for storing cache entries and marshalling them.
Warning
6.1. Performing Remote Queries via the Java Hot Rod Client
RemoteCacheManager
has been configured with the Protobuf marshaller.
RemoteCacheManager
must be configured to use the Protobuf Marshaller.
Procedure 6.1. Enabling Remote Querying via Hot Rod
Add All Relevant Dependencies
See theinfinispan-client-hotrod
dependencies in theruntime-classpath.txt
file in the JBoss Data Grid Library distribution for a full list of required dependencies.Enable indexing on the cache configuration.
This is the same as for Library mode. See Section 2.2, “Configure Infinispan Query”Register the Protobuf Binary Descriptor
Register the Protobuf binary descriptor by invoking theregisterProtofile
method of the server'sProtobufMetadataManager
MBean. There is one instance of this perEmbeddedCacheManager
.
All data placed in the cache is now being indexed without the need to annotate entities. These classes are only meaningful to the Java client, and do not exist on the server.
QueryFactory
can be obtained using the following:
import org.infinispan.client.hotrod.Search; import org.infinispan.query.dsl.QueryFactory; import org.infinispan.query.dsl.Query; ... remoteCache.put(2, new User("John", "Doe", 33)); QueryFactory qf = Search.getQueryFactory(remoteCache); Query query = qf.from(User.class) .having("name").eq("John") .toBuilder().build(); List list = query.list(); assertEquals(1, list.size()); assertEquals("John", list.get(0).getName()); assertEquals("Doe", list.get(0).getSurname());