XAP66 == "XAP9NET" || XAP66 == "XAP9" || XAP66 == "XAP9NET")

EDG - Aggregate Queries Tutorial

Search XAP 6.6
Searching XAP 6.6 Documentation
Browse XAP 6.6
Offline Documentation

Download latest offline documentation in HTML format:
xap-6.6.1-documentation.zip (20.6MB)


Summary: Implementing a Validator application that queries the space for account objects showing the different query methods GigaSpaces offers.


In this tutorial you will implement a Validator application that queries the space for account objects showing the different query methods GigaSpaces offers.

Application Components

There are three main components in our workflow:

  • Enterprise Data Grid space instance
  • Feeder
    1. Writes an initial amount of accounts to the space.
    2. Starts cycles of feeding new order objects to the space, each order is labeled Insecure or Normal.
  • Validator
    1. Starts query-based polling of Normal orders from the space, validates according to the relevant account and writes the order back to the space as approved/rejected.
    2. Registers for query-based notifications on Insecure orders, performs read on notify, holds a counter that is increased each time an Insecure order with risk higher then allowed (compared to a relevant account) is read.

Two additional components are:

  • Counter - Counts the number of Insecure orders that are riskier then allowed according to their corresponding account (Demonstrates use of GSIterator).
  • Scripting Counter - Counts number of Insecure orders with risk attribute higher then a fixed risk factor (Demonstrates use of Scripting).
    Scripting Counter is available only from GigaSpaces 6.5 and onwards.

Application Workflow

The application workflow is as follows:

  1. The Feeder PU's Pre-Loader service pre-loads the space with 100 account objects.
  2. After the Pre-Loader finishes, the Feeder Service starts cycles of feeding the space with new order objects with type Normal or Insecure.
  3. The Validator PU polling container continuously tries to take from the space new Normal orders, using a query template.
    The Validator notify container is registered for query-based notification, for every New and Insecure order written to the space.
  4. Once a Normal order is taken by a the polling container, the Normal Validator service validates it by querying the space for the relevant account for the order.
    When a notification is received by the notify container about a written Insecure order to the space, the Risky Counter service examines it by querying the space for the relevant account for the order. its counter is increased if the account allowed risk is sufficient for the order.
    (The Validator Service and Counter Service uses different query and query types (Directly Parameterized Query/Template Based Query)
  5. The order is validated and marked as approved if an account matching the query is found, otherwise it is marked as rejected. After validation is complete, the order is written back to the space.

The Scripting and GSIterator based components are described individually in the following sections:

GigaSpaces Features in this Tutorial

The following SQLQuery methods are used in this tutorial:

  • Plain, non parameterized SQL queries using rlike for regular expression pattern matching.
  • Parameterized querying using a template object for parameter binding.
  • Parameterized querying using JDBC like API for parameter binding.
  • Using queries as templates for notify and polling containers.
  • Queries in scripts.
  • Using GSIterator for iterations based query.
  • Indexing fields to speed up query based operations.

How to Query

Before you begin, you can take a look at this section, which summarizes the different query methods and shows how to index fields to speed up query based operations. If you're already familiar with the SQLQuery API, you can jump ahead to Writing the code. All code is documented inside each example as well.

See use of Query using Scripting and Query using GSIterator inside the tutorial.

For more detailed information, see SQLQuery.

We use the following Person POJO:

public class Person{

   private Integer age;
   private Integer height;
   private String name;

SQLQuery is the primary API when accessing the space.

Writing the Code

The following tabs show the services and configuration for each Processing Unit.

  • Usage of Parameterized query using a template object is demonstrated inside the Normal Validator Service tab.
  • Usage of Parameterized query using JDBC like API is demonstrated inside the Risky Counter Service tab.
  • Usage of Query templates in notify and polling containers is demonstrated inside the Feeder - Config and Validator - Config tabs.

Expected Output

IMPORTANT: This is an old version of GigaSpaces XAP. Click here for the latest version.