Summary: Querying the space using SqlQuery
OverviewOne of the space querying methods is to use an IQuery object. This can be done using SqlQuery, 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. UsageAn SqlQuery contains an Sql Syntax query, and an object template that relates to the query. Each query should be instanciated with the query and the template. Example 1Querying the space for all the Person objects whose age is greater than or equal to 21. Person personTemplate = new Person(); personTemplate.Age = 21; SqlQuery<Person> query = new SqlQuery<Person>(personTemplate, "Age >= ?"); Person[] persons = proxy.ReadMultiple<Person>(query); The query only contains the WHERE part of the statement. The FROM part of the statement is determined by the type of template, in this case – Person class. The dynamic arguments are filled from the template, and do not need to be manually typed into the query. personTemplate.Age = 30; Example 2Taking from the space, all the Person objects whose age is greater than or equal to 21, and their first name is John. Person personTemplate = new Person(); personTemplate.Age = 21; personTemplate.FirstName = "John" SqlQuery<Person> query = new SqlQuery<Person>(personTemplate, "Age >= ? AND FirstName = ?"); Person[] persons = proxy.TakeMultiple<Person>(query); Supported Sql OptionsThe following options are supported with SqlQuery:
Simple SqlQueryA simple SqlQuery is a query that can be translated into a single space query, which means that each of its fields appear once, or can be translated into one range. Examples of simple queries: Age = 21 AND Height < 200 AND FirstName = "John"
Age < 5 AND Age <=7
A query which is not simple will be translated into multiple space queries. Example of complex query: Age = 21 OR Age = 22 Limitations
|
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |