Summary: Querying the space using a Prepared Template

Overview

One of the space querying methods is to use an IQuery object. This can be done using the IPreparedTemplate, which implements IQuery. This query can be passed as a template to the Read, Take, ReadMultiple, TakeMultiple, Count and Clear operations, as well as a template when registering for notification.

An IPreparedTemplate is an object that is constructed by the ISpaceProxy.Snapshot method, and can be used to query the space as a template. This template increases the performance of the query, because it reduces serialization overhead and instance introspection. It should be used when doing a repetetive query that uses the same template, otherwise doing a Snapshot for each template, decreases performance.

Usage

To use a prepared template, it must be constructed by the ISpaceProxy.Snapshot method.

Example 1 – Creating a prepared template from an object

Person personTemplate = new Person();
personTemplate.Age = 21;
IPreparedTemplate<Person> preparedTemplate = proxy.Snapshot(personTemplate);

Example 2 – Creating a prepared template from SqlQuery

A prepared template can also be created from any IQuery object, such as SqlQuery.

Person personTemplate = new Person();
personTemplate.Age = 21;
SqlQuery<Person> query = new SqlQuery<Person>(personTemplate, "Age >= ?");
IPreparedTemplate<Person> preparedTemplate = proxy.Snapshot(query);

SqlQuery cannot be used in blocking operations as is. However, if a prepared template is created from it, then it can be used. Only simple sql queries can be used by the ISpaceProxy.Snapshot method

After creating the prepared template, it can be passed as a template to the Read, Take, ReadMultiple, TakeMultiple, Count and Clear operations, as well as a template when registering for notification.

Taking an object from the space using the prepared template

Person person = proxy.Take(preparedTemplate);

Limitations

GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence