6.3.2. Enabling Infinispan Query DSL-based Queries
In library mode, running Infinispan Query DSL-based queries is almost identical to running Lucene-based API queries. Prerequisites are:
- All libraries required for Infinispan Query (see Section 2.1.1, “Infinispan Query Dependencies” for details) and
infinispan-query-dsl.jar
in the classpath. - indexing enabled for caches.
- annotated POJO cache values.
As an alternative to .jar files, the Maven dependency can be used:
<dependency> <groupId>org.infinispan</groupId> <artifactId>infinispan-query-dsl</artifactId> <version>${infinispan.version}</version> </dependency>
The following example shows how to enable indexing:
ConfigurationBuilder cfg = new ConfigurationBuilder(); cfg.indexing().enable(); DefaultCacheManager cacheManager = new DefaultCacheManager(cfg.build()); Cache cache = cacheManager.getCache();
The following is an example of an annotated entity:
@Indexed public class User { @Field(store = Store.YES, analyze = Analyze.NO) private String name; @Field(store = Store.YES, analyze = Analyze.NO, indexNullAs = Field.DEFAULT_NULL_TOKEN) private String surname; @IndexedEmbedded(indexNullAs = Field.DEFAULT_NULL_TOKEN) private List addresses; // .. the rest omitted for brevity }