Summary: Querying the space using SqlQuery

Overview

One 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.

Usage

An 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 1

Querying 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.
An SqlQuery can be reused with different values in the template i.e. there is no need to create a new SqlQuery for each query. For instance, the previous query could be updated to query for a different age:

personTemplate.Age = 30;

Example 2

Taking 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 Options

The following options are supported with SqlQuery:

  • <
  • >
  • =
  • AND
  • IN
  • LIKE
  • NOT LIKE 1
  • OR 1
  • GROUP BY 1
  • ORDER BY 1
  1. This operation is not supported with Simple queries.

Simple SqlQuery

A 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

  • When using an SqlQuery in clusters, the routing field must be part of the query syntax.
  • An SqlQuery cannot be used in blocking queries as it is. A space query that has a timeout other than 0 does not block when using an SqlQuery. It is necessary to create a Prepared Template from the query.
  • An SqlQuery which is not simple, cannot be used with the ISpaceProxy.SnapShot method, and therefore cannot be used as a Prepared Template.
  • Enum fields or properties cannot contain a static value in the query syntax.
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence