Summary: Querying the space using a Prepared Template
OverviewWhen executing a query operation on the space, there's an overhead incurred by translating the query to an internal representation (in object templates the properties values are extracted using reflection, in SqlQuery the expression string is parsed to an expression tree). If the same query is executed over and over again without modification, that overhead can be removed by using prepared templates. The ISpaceProxy interface provides a method called Snapshot which receives a template or query , translates it to an internal XAP query structure and returns a reference to that structure as IPreparedTemplate<T>. That reference can then be used with any of the proxy's query operations to execute queries on the space in a more efficient manner, since there's no need to translate or parse the query.
UsageUse ISpaceProxy.Snapshot to create a prepared template from an object template or a SqlQuery. Creating a prepared template from an objectPerson template= new Person();
template.Age = 21;
IPreparedTemplate<Person> preparedTemplate = proxy.Snapshot(template);
Creating a prepared template from SqlQuerySqlQuery<Person> query = new SqlQuery<Person>(personTemplate, "Age >= ?"); query.SetParameter(1, 21); IPreparedTemplate<Person> preparedTemplate = proxy.Snapshot(query);
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 templatePerson person = proxy.Take(preparedTemplate); |
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |