Este contenido no está disponible en el idioma seleccionado.

15.8. Querying Example


15.8.1. The Query Module Example

The following provides an example of how to set up and run a query in JBoss Data Grid.
In this example, the "Person" object has been annotated using the following:
@Entity @ProvidedId @Indexed
public class Person
	implements Serializable {
		@Field(store = Store.YES)
		private String name;
		@Field
		private String description;
		@Field(store = Store.YES)
		private int age;
...
}
Copy to Clipboard Toggle word wrap
Assuming several of these "Person" objects have been stored in JBoss Data Grid, they can be searched using querying. The following code creates a SearchManager and QueryBuilder instance:
SearchManager manager=
	Search.getSearchManager(cache);
QueryBuilder builder=
	sm.buildQueryBuilderForClass(Person.class) .get();
Query luceneQuery = builder.keyword()
			.onField("name")
			.matching("FirstName")
		.createQuery();
Copy to Clipboard Toggle word wrap
The SearchManager and QueryBuilder are used to construct a Lucene query. The Lucene query is then passed to the SearchManager to obtain a CacheQuery instance:
CacheQuery query = manager.getQuery(luceneQuery);
for (Object result: query) {
        System.out.println("Found " + result);
}
Copy to Clipboard Toggle word wrap
This CacheQuery instance contains the results of the query, and can be used to produce a list or it can be used for repeat queries.

Important

The Query Module is currently only available as a Technical Preview for JBoss Data Grid 6.1.
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat